Personmodel handled as dbtabel and as file
This commit is contained in:
@ -8,5 +8,6 @@ namespace TrackerLibrary.DataAccess
|
||||
public interface IDataConnection
|
||||
{
|
||||
PrizeModel CreatePrize(PrizeModel model);
|
||||
PersonModel CreatePerson(PersonModel model);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using TrackerLibrary.Models;
|
||||
|
||||
|
||||
//@PlaceNumber int,
|
||||
@ -15,6 +16,24 @@ namespace TrackerLibrary.DataAccess
|
||||
{
|
||||
public class SqlConnector : IDataConnection
|
||||
{
|
||||
public PersonModel CreatePerson(PersonModel model)
|
||||
{
|
||||
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("Tournaments"))) {
|
||||
var p = new DynamicParameters();
|
||||
p.Add("@FirstName", model.FirstName);
|
||||
p.Add("@LastName", model.LastName);
|
||||
p.Add("@EmailAddress", model.EmailAddress);
|
||||
p.Add("@CellPhoneNumber", model.CellPhoneNumber);
|
||||
p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
|
||||
|
||||
connection.Execute("dbo.spPeople_Insert", p, commandType: CommandType.StoredProcedure);
|
||||
|
||||
model.Id = p.Get<int>("@Id");
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO - Make the CreatePrize method actually save to the database
|
||||
/// <summary>
|
||||
/// Saves a prize to the database
|
||||
|
||||
@ -10,6 +10,26 @@ namespace TrackerLibrary.DataAccess
|
||||
public class TextConnector : IDataConnection
|
||||
{
|
||||
private const string PrizesFile = "PrizeModels.csv";
|
||||
private const string PeopleFile = "PersonModels.csv";
|
||||
|
||||
public PersonModel CreatePerson(PersonModel model)
|
||||
{
|
||||
List<PersonModel> people = PeopleFile.FullFilePath().LoadFile().ConvertToPersonModels();
|
||||
|
||||
int currentId = 1;
|
||||
if (people.Count > 0)
|
||||
{
|
||||
currentId = people.OrderByDescending(x => x.Id).First().Id + 1;
|
||||
}
|
||||
|
||||
model.Id = currentId;
|
||||
|
||||
people.Add(model);
|
||||
|
||||
people.SaveToPeopleFile(PeopleFile);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
// TODO - Wire up the createPrize for textFiles
|
||||
public PrizeModel CreatePrize(PrizeModel model)
|
||||
|
||||
@ -44,6 +44,23 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
return output;
|
||||
}
|
||||
|
||||
public static List<PersonModel> ConvertToPersonModels(this List<string> lines)
|
||||
{
|
||||
List<PersonModel> output = new List<PersonModel>();
|
||||
foreach(string line in lines)
|
||||
{
|
||||
string[] cols = line.Split(',');
|
||||
PersonModel p = new PersonModel();
|
||||
p.Id = int.Parse(cols[0]);
|
||||
p.FirstName = cols[1];
|
||||
p.LastName = cols[2];
|
||||
p.EmailAddress = cols[3];
|
||||
p.CellPhoneNumber = cols[4];
|
||||
output.Add(p);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static void SaveToPrizeFile(this List<PrizeModel> models, string fileName)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
@ -54,5 +71,17 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
}
|
||||
File.WriteAllLines(fileName.FullFilePath(), lines);
|
||||
}
|
||||
|
||||
public static void SaveToPeopleFile(this List<PersonModel> models, string fileName)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
foreach(PersonModel p in models)
|
||||
{
|
||||
lines.Add($"{p.Id},{p.FirstName},{p.LastName},{p.EmailAddress},{p.CellPhoneNumber}");
|
||||
}
|
||||
|
||||
File.WriteAllLines(fileName.FullFilePath(), lines);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,10 @@ namespace TrackerLibrary.Models
|
||||
{
|
||||
public class PersonModel
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the prize
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string EmailAddress { get; set; }
|
||||
|
||||
19
TrackerUI/CreateTeamForm.Designer.cs
generated
19
TrackerUI/CreateTeamForm.Designer.cs
generated
@ -37,7 +37,7 @@
|
||||
this.selectTeamMemberLabel = new System.Windows.Forms.Label();
|
||||
this.addNewMemberGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.createMemberButton = new System.Windows.Forms.Button();
|
||||
this.cellPhoneNumber = new System.Windows.Forms.TextBox();
|
||||
this.cellphoneValue = new System.Windows.Forms.TextBox();
|
||||
this.cellPhoneLabel = new System.Windows.Forms.Label();
|
||||
this.emailValue = new System.Windows.Forms.TextBox();
|
||||
this.emailLabel = new System.Windows.Forms.Label();
|
||||
@ -116,7 +116,7 @@
|
||||
// addNewMemberGroupBox
|
||||
//
|
||||
this.addNewMemberGroupBox.Controls.Add(this.createMemberButton);
|
||||
this.addNewMemberGroupBox.Controls.Add(this.cellPhoneNumber);
|
||||
this.addNewMemberGroupBox.Controls.Add(this.cellphoneValue);
|
||||
this.addNewMemberGroupBox.Controls.Add(this.cellPhoneLabel);
|
||||
this.addNewMemberGroupBox.Controls.Add(this.emailValue);
|
||||
this.addNewMemberGroupBox.Controls.Add(this.emailLabel);
|
||||
@ -147,14 +147,15 @@
|
||||
this.createMemberButton.TabIndex = 20;
|
||||
this.createMemberButton.Text = "Create Member";
|
||||
this.createMemberButton.UseVisualStyleBackColor = true;
|
||||
this.createMemberButton.Click += new System.EventHandler(this.createMemberButton_Click);
|
||||
//
|
||||
// cellPhoneNumber
|
||||
// cellphoneValue
|
||||
//
|
||||
this.cellPhoneNumber.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.cellPhoneNumber.Location = new System.Drawing.Point(183, 169);
|
||||
this.cellPhoneNumber.Name = "cellPhoneNumber";
|
||||
this.cellPhoneNumber.Size = new System.Drawing.Size(185, 35);
|
||||
this.cellPhoneNumber.TabIndex = 16;
|
||||
this.cellphoneValue.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.cellphoneValue.Location = new System.Drawing.Point(183, 169);
|
||||
this.cellphoneValue.Name = "cellphoneValue";
|
||||
this.cellphoneValue.Size = new System.Drawing.Size(185, 35);
|
||||
this.cellphoneValue.TabIndex = 16;
|
||||
//
|
||||
// cellPhoneLabel
|
||||
//
|
||||
@ -301,7 +302,7 @@
|
||||
private System.Windows.Forms.Label selectTeamMemberLabel;
|
||||
private System.Windows.Forms.GroupBox addNewMemberGroupBox;
|
||||
private System.Windows.Forms.Button createMemberButton;
|
||||
private System.Windows.Forms.TextBox cellPhoneNumber;
|
||||
private System.Windows.Forms.TextBox cellphoneValue;
|
||||
private System.Windows.Forms.Label cellPhoneLabel;
|
||||
private System.Windows.Forms.TextBox emailValue;
|
||||
private System.Windows.Forms.Label emailLabel;
|
||||
|
||||
@ -7,6 +7,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TrackerLibrary;
|
||||
using TrackerLibrary.Models;
|
||||
|
||||
namespace TrackerUI
|
||||
{
|
||||
@ -16,5 +18,54 @@ namespace TrackerUI
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void createMemberButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ValidateForm())
|
||||
{
|
||||
PersonModel p = new PersonModel();
|
||||
|
||||
p.FirstName = firstNameValue.Text;
|
||||
p.LastName = lastNameValue.Text;
|
||||
p.EmailAddress = emailValue.Text;
|
||||
p.CellPhoneNumber = cellphoneValue.Text;
|
||||
|
||||
GlobalConfig.Connection.CreatePerson(p);
|
||||
|
||||
firstNameValue.Text = string.Empty;
|
||||
lastNameValue.Text = string.Empty;
|
||||
emailValue.Text = string.Empty;
|
||||
cellphoneValue.Text = string.Empty;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("You need to fill in all of the fiealds.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private bool ValidateForm()
|
||||
{
|
||||
// TODO - add validation to the form
|
||||
if(firstNameValue.Text.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (lastNameValue.Text.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (emailValue.Text.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (cellphoneValue.Text.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ namespace TrackerUI
|
||||
|
||||
// Initialize the database connections
|
||||
GlobalConfig.InitializeConnections(DatabaseType.TextFile);
|
||||
Application.Run(new CreatePrizeForm());
|
||||
Application.Run(new CreateTeamForm());
|
||||
|
||||
//Application.Run(new TournamentDashboardForm());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user