Client logic + client storages were implemented.
This commit is contained in:
parent
e41fcdad52
commit
6d252ad2d7
126
DressAtelierBusinessLogic/BusinessLogic/ClientLogic.cs
Normal file
126
DressAtelierBusinessLogic/BusinessLogic/ClientLogic.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.BusinessLogicContracts;
|
||||
using DressAtelierContracts.SearchModels;
|
||||
using DressAtelierContracts.StorageContracts;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ClientLogic : IClientLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientStorage _clientStorage;
|
||||
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_clientStorage = clientStorage;
|
||||
}
|
||||
public bool Create(ClientBindingModel model)
|
||||
{
|
||||
CheckUser(model);
|
||||
if(_clientStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ClientBindingModel model)
|
||||
{
|
||||
CheckUser(model);
|
||||
if (_clientStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ClientBindingModel model)
|
||||
{
|
||||
CheckUser(model,false);
|
||||
_logger.LogInformation("Delete. ID:{ID}", model.ID);
|
||||
if (_clientStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ClientViewModel? ReadElement(ClientSearchModel model)
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. UserName:{UserName}.ID:{ ID}", model.Email, model.ID);
|
||||
var element = _clientStorage.GetElement(model);
|
||||
if(element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. ID:{ID}", element.ID);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. UserName:{UserName}. ID:{ ID}", model?.Email, model?.ID);
|
||||
|
||||
var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public void CheckUser(ClientBindingModel model,bool withParams = true)
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if(!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(string.IsNullOrEmpty(model.FullName))
|
||||
{
|
||||
throw new ArgumentNullException("Invalid fullname of user", nameof(model.FullName));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
throw new ArgumentNullException("Invalid email of user", nameof(model.Email));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Invalid password of user", nameof(model.Password));
|
||||
}
|
||||
_logger.LogInformation("Client. ClientName:{ FullName}. Email:{ Email}. ID: { ID} ", model.FullName, model.Email, model.ID);
|
||||
|
||||
var element = _clientStorage.GetElement(new ClientSearchModel
|
||||
{
|
||||
Email = model.Email
|
||||
});
|
||||
|
||||
if(element != null && element.ID != model.ID)
|
||||
{
|
||||
throw new InvalidOperationException("User with such email already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
17
DressAtelierContracts/BindingModels/ClientBindingModel.cs
Normal file
17
DressAtelierContracts/BindingModels/ClientBindingModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using DressAtelierDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierContracts.BindingModels
|
||||
{
|
||||
public class ClientBindingModel : IClientModel
|
||||
{
|
||||
public int ID { get; set;}
|
||||
public string FullName { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -13,6 +13,8 @@ namespace DressAtelierContracts.BindingModels
|
||||
public int ID { get; set; }
|
||||
|
||||
public int DressID { get; set; }
|
||||
public int ClientID { get; set; }
|
||||
public string ClientFullName { get; set; } = string.Empty;
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
|
20
DressAtelierContracts/BusinessLogicContracts/IClientLogic.cs
Normal file
20
DressAtelierContracts/BusinessLogicContracts/IClientLogic.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.SearchModels;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IClientLogic
|
||||
{
|
||||
List<ClientViewModel>? ReadList(ClientSearchModel? model);
|
||||
ClientViewModel? ReadElement(ClientSearchModel model);
|
||||
bool Create(ClientBindingModel model);
|
||||
bool Update(ClientBindingModel model);
|
||||
bool Delete(ClientBindingModel model);
|
||||
}
|
||||
}
|
14
DressAtelierContracts/SearchModels/ClientSearchModel.cs
Normal file
14
DressAtelierContracts/SearchModels/ClientSearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierContracts.SearchModels
|
||||
{
|
||||
public class ClientSearchModel
|
||||
{
|
||||
public int? ID { get; set; }
|
||||
public string? Email { get; set; }
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ namespace DressAtelierContracts.SearchModels
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? ID { get; set; }
|
||||
public int? ClientID { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
|
21
DressAtelierContracts/StorageContracts/IClientStorage.cs
Normal file
21
DressAtelierContracts/StorageContracts/IClientStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.SearchModels;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierContracts.StorageContracts
|
||||
{
|
||||
public interface IClientStorage
|
||||
{
|
||||
List<ClientViewModel> GetFullList();
|
||||
List<ClientViewModel> GetFilteredList(ClientSearchModel model);
|
||||
ClientViewModel? GetElement(ClientSearchModel model);
|
||||
ClientViewModel? Insert(ClientBindingModel model);
|
||||
ClientViewModel? Update(ClientBindingModel model);
|
||||
ClientViewModel? Delete(ClientBindingModel model);
|
||||
}
|
||||
}
|
24
DressAtelierContracts/ViewModels/ClientViewModel.cs
Normal file
24
DressAtelierContracts/ViewModels/ClientViewModel.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using DressAtelierDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierContracts.ViewModels
|
||||
{
|
||||
public class ClientViewModel : IClientModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
[DisplayName("Client's full name")]
|
||||
public string FullName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Login")]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Password")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
}
|
@ -14,9 +14,12 @@ namespace DressAtelierContracts.ViewModels
|
||||
[DisplayName("ID")]
|
||||
public int ID { get; set; }
|
||||
public int DressID { get; set; }
|
||||
public int ClientID { get; set; }
|
||||
[DisplayName("Client's name")]
|
||||
public string ClientFullName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("DressName")]
|
||||
public string DressName { get; set; }
|
||||
public string DressName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Quantity")]
|
||||
public int Count { get; set; }
|
||||
|
15
DressAtelierDataModels/Models/IClientModel.cs
Normal file
15
DressAtelierDataModels/Models/IClientModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierDataModels.Models
|
||||
{
|
||||
public interface IClientModel : IID
|
||||
{
|
||||
string FullName { get; }
|
||||
string Email { get; }
|
||||
string Password { get; }
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using DressAtelierDatabaseImplementation.Models;
|
||||
using DressAtelierDatabaseImplement.Models;
|
||||
using DressAtelierDatabaseImplementation.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -23,5 +24,6 @@ namespace DressAtelierDatabaseImplementation
|
||||
public virtual DbSet<Dress> Dresses { set; get; }
|
||||
public virtual DbSet<DressMaterial> DressMaterials { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
}
|
||||
}
|
||||
|
68
DressAtelierDatabaseImplement/Implements/ClientStorage.cs
Normal file
68
DressAtelierDatabaseImplement/Implements/ClientStorage.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.SearchModels;
|
||||
using DressAtelierContracts.StorageContracts;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using DressAtelierDatabaseImplement.Models;
|
||||
using DressAtelierDatabaseImplementation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierDatabaseImplement.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
using var context = new DressAtelierDatabase();
|
||||
var newClient = Client.Create(model);
|
||||
if(newClient == null) { return null; }
|
||||
context.Clients.Add(newClient);
|
||||
context.SaveChanges();
|
||||
return newClient.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
using var context = new DressAtelierDatabase();
|
||||
var client = context.Clients.FirstOrDefault(x => x.ID == model.ID);
|
||||
if(client == null) { return null; };
|
||||
client.Update(model);
|
||||
context.SaveChanges();
|
||||
return client.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
using var context = new DressAtelierDatabase();
|
||||
var client = context.Clients.FirstOrDefault(x => x.ID == model.ID);
|
||||
if(client == null) { return null;}
|
||||
context.Clients.Remove(client);
|
||||
context.SaveChanges();
|
||||
return client.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Email) && !model.ID.HasValue) { return null; }
|
||||
using var context = new DressAtelierDatabase();
|
||||
return context.Clients.FirstOrDefault(x => (!(string.IsNullOrEmpty(model.Email)) && model.Email == x.Email) || (model.ID.HasValue && model.ID == x.ID))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Email)) { return new(); }
|
||||
using var context = new DressAtelierDatabase();
|
||||
return context.Clients.Where(x => x.Email.Equals(model.Email)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
using var context = new DressAtelierDatabase();
|
||||
return context.Clients.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -18,15 +18,19 @@ namespace DressAtelierDatabaseImplementation.Implements
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new DressAtelierDatabase();
|
||||
return context.Orders.Include(x => x.Dress).Select(x => x.GetViewModel).ToList();
|
||||
return context.Orders.Include(x => x.Client).Include(x => x.Dress).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.ID.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue)
|
||||
if (!model.ID.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientID.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new DressAtelierDatabase();
|
||||
if(model.ClientID.HasValue)
|
||||
{
|
||||
return context.Orders.Include(x => x.Client).Where(x => x.ClientID == model.ClientID).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
return context.Orders.Include(x => x.Dress).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).ToList().Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
|
61
DressAtelierDatabaseImplement/Models/Client.cs
Normal file
61
DressAtelierDatabaseImplement/Models/Client.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using DressAtelierDatabaseImplementation.Models;
|
||||
using DressAtelierDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace DressAtelierDatabaseImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
[Required]
|
||||
public string FullName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
[ForeignKey("ClientID")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
public static Client? Create(ClientBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Client()
|
||||
{
|
||||
ID = model.ID,
|
||||
FullName = model.FullName,
|
||||
Email = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ClientBindingModel? model)
|
||||
{
|
||||
if (model == null) { return; }
|
||||
FullName = model.FullName;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
ID = ID,
|
||||
FullName = FullName,
|
||||
Email = Email,
|
||||
Password = Password
|
||||
};
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using DressAtelierDatabaseImplement.Models;
|
||||
using DressAtelierDataModels.Enums;
|
||||
using DressAtelierDataModels.Models;
|
||||
using System;
|
||||
@ -16,8 +17,11 @@ namespace DressAtelierDatabaseImplementation.Models
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
[Required]
|
||||
public int DressID { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int ClientID { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
@ -33,6 +37,7 @@ namespace DressAtelierDatabaseImplementation.Models
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public virtual Dress Dress { get; set; }
|
||||
public virtual Client Client { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
@ -44,6 +49,7 @@ namespace DressAtelierDatabaseImplementation.Models
|
||||
{
|
||||
ID = model.ID,
|
||||
DressID = model.DressID,
|
||||
ClientID = model.ClientID,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -68,13 +74,14 @@ namespace DressAtelierDatabaseImplementation.Models
|
||||
{
|
||||
ID = ID,
|
||||
DressID = DressID,
|
||||
ClientID = ClientID,
|
||||
ClientFullName = Client.FullName,
|
||||
DressName = Dress.DressName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -15,9 +15,11 @@ namespace DressAtelierFileImplement
|
||||
private readonly string MaterialFileName = "Material.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string DressFileName = "Dress.xml";
|
||||
private readonly string ClientFileName = "Client.xml";
|
||||
public List<Material> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Dress> Dresses { get; private set; }
|
||||
public List<Client> Clients { get; private set; }
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
@ -29,11 +31,13 @@ namespace DressAtelierFileImplement
|
||||
public void SaveComponents() => SaveData(Components, MaterialFileName,"Components", x => x.GetXElement);
|
||||
public void SaveDresses() => SaveData(Dresses, DressFileName,"Dresses", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName,"Orders", x => x.GetXElement);
|
||||
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(MaterialFileName, "Component", x => Material.Create(x)!)!;
|
||||
Dresses = LoadData(DressFileName, "Dress", x => Dress.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||
}
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
|
||||
Func<XElement, T> selectFunction)
|
||||
|
68
DressAtelierFileImplement/Implements/ClientStorage.cs
Normal file
68
DressAtelierFileImplement/Implements/ClientStorage.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.SearchModels;
|
||||
using DressAtelierContracts.StorageContracts;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using DressAtelierFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierFileImplement.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
public ClientStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
model.ID = _source.Clients.Count > 0 ? _source.Clients.Max(client => client.ID) + 1 : 1;
|
||||
var newClient = Client.Create(model);
|
||||
if(newClient == null) { return null; }
|
||||
_source.Clients.Add(newClient);
|
||||
_source.SaveClients();
|
||||
return newClient.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
var client = _source.Clients.FirstOrDefault(x => x.ID == model.ID);
|
||||
if(client == null) { return null; };
|
||||
client.Update(model);
|
||||
_source.SaveClients();
|
||||
return client.GetViewModel;
|
||||
}
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
var client = _source.Clients.FirstOrDefault(client => client.ID == model.ID);
|
||||
if(client == null) { return null; }
|
||||
_source.Clients.Remove(client);
|
||||
_source.SaveClients();
|
||||
return client.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
if(string.IsNullOrEmpty(model.Email) && !model.ID.HasValue) { return null; }
|
||||
|
||||
return _source.Clients.FirstOrDefault(x => (!(string.IsNullOrEmpty(model.Email)) && model.Email == x.Email) || (model.ID.HasValue && model.ID == x.ID))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Email)) { return new(); }
|
||||
return _source.Clients.Where(x => x.Email.Equals(model.Email)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
return _source.Clients.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
73
DressAtelierFileImplement/Models/Client.cs
Normal file
73
DressAtelierFileImplement/Models/Client.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using DressAtelierDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace DressAtelierFileImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string FullName { get; set; } = string.Empty;
|
||||
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
public static Client? Create(ClientBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Client()
|
||||
{
|
||||
ID = model.ID,
|
||||
FullName = model.FullName,
|
||||
Email = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
|
||||
public static Client? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Client()
|
||||
{
|
||||
ID = Convert.ToInt32(element.Attribute("ID")!.Value),
|
||||
FullName = element.Element("FullName")!.Value,
|
||||
Email = element.Element("Email")!.Value,
|
||||
Password = element.Element("Password")!.Value
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ClientBindingModel? model)
|
||||
{
|
||||
if (model == null) { return; }
|
||||
FullName = model.FullName;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
ID = ID,
|
||||
FullName = FullName,
|
||||
Email = Email,
|
||||
Password = Password
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("Client", new XAttribute("ID", ID),
|
||||
new XElement("FullName", FullName),
|
||||
new XElement("Email", Email),
|
||||
new XElement("Password", Password));
|
||||
}
|
||||
}
|
@ -13,11 +13,13 @@ namespace DressAtelierListImplement
|
||||
public List<Material> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Dress> Dresses { get; set; }
|
||||
public List<Client> Clients { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Material>();
|
||||
Orders = new List<Order>();
|
||||
Dresses = new List<Dress>();
|
||||
Clients = new List<Client>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
113
DressAtelierListImplement/Implements/ClientStorage.cs
Normal file
113
DressAtelierListImplement/Implements/ClientStorage.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.SearchModels;
|
||||
using DressAtelierContracts.StorageContracts;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using DressAtelierListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierListImplement.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public ClientStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
model.ID = 1;
|
||||
foreach(var client in _source.Clients)
|
||||
{
|
||||
if(model.ID <= client.ID)
|
||||
{
|
||||
model.ID = client.ID + 1;
|
||||
}
|
||||
}
|
||||
var newClient = Client.Create(model);
|
||||
if(newClient == null) { return null; }
|
||||
_source.Clients.Add(newClient);
|
||||
return newClient.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
foreach(var client in _source.Clients)
|
||||
{
|
||||
if(client.ID == model.ID)
|
||||
{
|
||||
client.Update(model);
|
||||
return client.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
for(int i = 0 ; i< _source.Clients.Count;i++)
|
||||
{
|
||||
if(model.ID == _source.Clients[i].ID)
|
||||
{
|
||||
var element = _source.Clients[i];
|
||||
_source.Clients.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
if(string.IsNullOrEmpty(model.Email) && !model.ID.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach(var client in _source.Clients)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.Email) && model.Email == client.Email) || (model.ID.HasValue && model.ID.Value == client.ID))
|
||||
{
|
||||
return client.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
var result = new List<ClientViewModel>();
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
if (client.Email.Contains(model.Email))
|
||||
{
|
||||
result.Add(client.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ClientViewModel>();
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
result.Add(client.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
52
DressAtelierListImplement/Models/Client.cs
Normal file
52
DressAtelierListImplement/Models/Client.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using DressAtelierDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierListImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string FullName { get; set; } = string.Empty;
|
||||
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
public static Client? Create(ClientBindingModel? model)
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Client()
|
||||
{
|
||||
ID = model.ID,
|
||||
FullName = model.FullName,
|
||||
Email = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ClientBindingModel? model)
|
||||
{
|
||||
if(model == null) { return; }
|
||||
FullName = model.FullName;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
ID = ID,
|
||||
FullName = FullName,
|
||||
Email = Email,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
}
|
@ -45,6 +45,7 @@ namespace SewingDresses
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["DressID"].Visible = false;
|
||||
dataGridView.Columns["ClientID"].Visible = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -94,12 +95,7 @@ namespace SewingDresses
|
||||
{
|
||||
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||
{
|
||||
ID = id,
|
||||
DressID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value),
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
|
||||
ID = id,
|
||||
});
|
||||
|
||||
if (!operationResult)
|
||||
@ -128,12 +124,7 @@ namespace SewingDresses
|
||||
{
|
||||
var operationResult = _orderLogic.ReadyOrder(new OrderBindingModel
|
||||
{
|
||||
ID = id,
|
||||
DressID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value),
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
|
||||
ID = id,
|
||||
});
|
||||
|
||||
if (!operationResult)
|
||||
@ -162,12 +153,7 @@ namespace SewingDresses
|
||||
{
|
||||
var operationResult = _orderLogic.GivenOrder(new OrderBindingModel
|
||||
{
|
||||
ID = id,
|
||||
DressID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value),
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
|
||||
ID = id,
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
|
180
SewingDresses/FormOrderCreation.Designer.cs
generated
180
SewingDresses/FormOrderCreation.Designer.cs
generated
@ -28,111 +28,133 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.dressLabel = new System.Windows.Forms.Label();
|
||||
this.quantityLabel = new System.Windows.Forms.Label();
|
||||
this.priceLabel = new System.Windows.Forms.Label();
|
||||
this.dressComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.quantityTextBox = new System.Windows.Forms.TextBox();
|
||||
this.priceTextBox = new System.Windows.Forms.TextBox();
|
||||
this.ButtonSave = new System.Windows.Forms.Button();
|
||||
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
dressLabel = new Label();
|
||||
quantityLabel = new Label();
|
||||
priceLabel = new Label();
|
||||
dressComboBox = new ComboBox();
|
||||
quantityTextBox = new TextBox();
|
||||
priceTextBox = new TextBox();
|
||||
ButtonSave = new Button();
|
||||
ButtonCancel = new Button();
|
||||
labelClient = new Label();
|
||||
comboBoxClients = new ComboBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dressLabel
|
||||
//
|
||||
this.dressLabel.AutoSize = true;
|
||||
this.dressLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.dressLabel.Location = new System.Drawing.Point(12, 9);
|
||||
this.dressLabel.Name = "dressLabel";
|
||||
this.dressLabel.Size = new System.Drawing.Size(82, 25);
|
||||
this.dressLabel.TabIndex = 0;
|
||||
this.dressLabel.Text = "Product:";
|
||||
dressLabel.AutoSize = true;
|
||||
dressLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
dressLabel.Location = new Point(12, 9);
|
||||
dressLabel.Name = "dressLabel";
|
||||
dressLabel.Size = new Size(82, 25);
|
||||
dressLabel.TabIndex = 0;
|
||||
dressLabel.Text = "Product:";
|
||||
//
|
||||
// quantityLabel
|
||||
//
|
||||
this.quantityLabel.AutoSize = true;
|
||||
this.quantityLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.quantityLabel.Location = new System.Drawing.Point(12, 50);
|
||||
this.quantityLabel.Name = "quantityLabel";
|
||||
this.quantityLabel.Size = new System.Drawing.Size(88, 25);
|
||||
this.quantityLabel.TabIndex = 1;
|
||||
this.quantityLabel.Text = "Quantity:";
|
||||
quantityLabel.AutoSize = true;
|
||||
quantityLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
quantityLabel.Location = new Point(12, 78);
|
||||
quantityLabel.Name = "quantityLabel";
|
||||
quantityLabel.Size = new Size(88, 25);
|
||||
quantityLabel.TabIndex = 1;
|
||||
quantityLabel.Text = "Quantity:";
|
||||
//
|
||||
// priceLabel
|
||||
//
|
||||
this.priceLabel.AutoSize = true;
|
||||
this.priceLabel.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.priceLabel.Location = new System.Drawing.Point(12, 90);
|
||||
this.priceLabel.Name = "priceLabel";
|
||||
this.priceLabel.Size = new System.Drawing.Size(56, 25);
|
||||
this.priceLabel.TabIndex = 2;
|
||||
this.priceLabel.Text = "Total:";
|
||||
priceLabel.AutoSize = true;
|
||||
priceLabel.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
priceLabel.Location = new Point(12, 118);
|
||||
priceLabel.Name = "priceLabel";
|
||||
priceLabel.Size = new Size(56, 25);
|
||||
priceLabel.TabIndex = 2;
|
||||
priceLabel.Text = "Total:";
|
||||
//
|
||||
// dressComboBox
|
||||
//
|
||||
this.dressComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.dressComboBox.FormattingEnabled = true;
|
||||
this.dressComboBox.Location = new System.Drawing.Point(114, 12);
|
||||
this.dressComboBox.Name = "dressComboBox";
|
||||
this.dressComboBox.Size = new System.Drawing.Size(320, 23);
|
||||
this.dressComboBox.TabIndex = 3;
|
||||
this.dressComboBox.SelectedIndexChanged += new System.EventHandler(this.DressComboBox_SelectedIndexChanged);
|
||||
dressComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
dressComboBox.FormattingEnabled = true;
|
||||
dressComboBox.Location = new Point(114, 12);
|
||||
dressComboBox.Name = "dressComboBox";
|
||||
dressComboBox.Size = new Size(320, 23);
|
||||
dressComboBox.TabIndex = 3;
|
||||
dressComboBox.SelectedIndexChanged += DressComboBox_SelectedIndexChanged;
|
||||
//
|
||||
// quantityTextBox
|
||||
//
|
||||
this.quantityTextBox.Location = new System.Drawing.Point(114, 52);
|
||||
this.quantityTextBox.Name = "quantityTextBox";
|
||||
this.quantityTextBox.Size = new System.Drawing.Size(320, 23);
|
||||
this.quantityTextBox.TabIndex = 4;
|
||||
this.quantityTextBox.TextChanged += new System.EventHandler(this.QuantityTextBox_TextChanged);
|
||||
quantityTextBox.Location = new Point(114, 80);
|
||||
quantityTextBox.Name = "quantityTextBox";
|
||||
quantityTextBox.Size = new Size(320, 23);
|
||||
quantityTextBox.TabIndex = 4;
|
||||
quantityTextBox.TextChanged += QuantityTextBox_TextChanged;
|
||||
//
|
||||
// priceTextBox
|
||||
//
|
||||
this.priceTextBox.Location = new System.Drawing.Point(114, 90);
|
||||
this.priceTextBox.Name = "priceTextBox";
|
||||
this.priceTextBox.ReadOnly = true;
|
||||
this.priceTextBox.Size = new System.Drawing.Size(320, 23);
|
||||
this.priceTextBox.TabIndex = 5;
|
||||
priceTextBox.Location = new Point(114, 118);
|
||||
priceTextBox.Name = "priceTextBox";
|
||||
priceTextBox.ReadOnly = true;
|
||||
priceTextBox.Size = new Size(320, 23);
|
||||
priceTextBox.TabIndex = 5;
|
||||
//
|
||||
// ButtonSave
|
||||
//
|
||||
this.ButtonSave.Location = new System.Drawing.Point(220, 138);
|
||||
this.ButtonSave.Name = "ButtonSave";
|
||||
this.ButtonSave.Size = new System.Drawing.Size(100, 32);
|
||||
this.ButtonSave.TabIndex = 6;
|
||||
this.ButtonSave.Text = "Save";
|
||||
this.ButtonSave.UseVisualStyleBackColor = true;
|
||||
this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
ButtonSave.Location = new Point(220, 166);
|
||||
ButtonSave.Name = "ButtonSave";
|
||||
ButtonSave.Size = new Size(100, 32);
|
||||
ButtonSave.TabIndex = 6;
|
||||
ButtonSave.Text = "Save";
|
||||
ButtonSave.UseVisualStyleBackColor = true;
|
||||
ButtonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// ButtonCancel
|
||||
//
|
||||
this.ButtonCancel.Location = new System.Drawing.Point(334, 138);
|
||||
this.ButtonCancel.Name = "ButtonCancel";
|
||||
this.ButtonCancel.Size = new System.Drawing.Size(100, 32);
|
||||
this.ButtonCancel.TabIndex = 7;
|
||||
this.ButtonCancel.Text = "Cancel";
|
||||
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
ButtonCancel.Location = new Point(334, 166);
|
||||
ButtonCancel.Name = "ButtonCancel";
|
||||
ButtonCancel.Size = new Size(100, 32);
|
||||
ButtonCancel.TabIndex = 7;
|
||||
ButtonCancel.Text = "Cancel";
|
||||
ButtonCancel.UseVisualStyleBackColor = true;
|
||||
ButtonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// labelClient
|
||||
//
|
||||
labelClient.AutoSize = true;
|
||||
labelClient.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
labelClient.Location = new Point(12, 43);
|
||||
labelClient.Name = "labelClient";
|
||||
labelClient.Size = new Size(65, 25);
|
||||
labelClient.TabIndex = 8;
|
||||
labelClient.Text = "Client:";
|
||||
//
|
||||
// comboBoxClients
|
||||
//
|
||||
comboBoxClients.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxClients.FormattingEnabled = true;
|
||||
comboBoxClients.Location = new Point(114, 43);
|
||||
comboBoxClients.Name = "comboBoxClients";
|
||||
comboBoxClients.Size = new Size(320, 23);
|
||||
comboBoxClients.TabIndex = 9;
|
||||
//
|
||||
// FormOrderCreation
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(446, 181);
|
||||
this.Controls.Add(this.ButtonCancel);
|
||||
this.Controls.Add(this.ButtonSave);
|
||||
this.Controls.Add(this.priceTextBox);
|
||||
this.Controls.Add(this.quantityTextBox);
|
||||
this.Controls.Add(this.dressComboBox);
|
||||
this.Controls.Add(this.priceLabel);
|
||||
this.Controls.Add(this.quantityLabel);
|
||||
this.Controls.Add(this.dressLabel);
|
||||
this.Name = "FormOrderCreation";
|
||||
this.Text = "FormOrderCreation";
|
||||
this.Load += new System.EventHandler(this.FormOrderCreation_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(446, 224);
|
||||
Controls.Add(comboBoxClients);
|
||||
Controls.Add(labelClient);
|
||||
Controls.Add(ButtonCancel);
|
||||
Controls.Add(ButtonSave);
|
||||
Controls.Add(priceTextBox);
|
||||
Controls.Add(quantityTextBox);
|
||||
Controls.Add(dressComboBox);
|
||||
Controls.Add(priceLabel);
|
||||
Controls.Add(quantityLabel);
|
||||
Controls.Add(dressLabel);
|
||||
Name = "FormOrderCreation";
|
||||
Text = "FormOrderCreation";
|
||||
Load += FormOrderCreation_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -145,5 +167,7 @@
|
||||
private TextBox priceTextBox;
|
||||
private Button ButtonSave;
|
||||
private Button ButtonCancel;
|
||||
private Label labelClient;
|
||||
private ComboBox comboBoxClients;
|
||||
}
|
||||
}
|
@ -19,14 +19,16 @@ namespace SewingDresses
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IDressLogic _logicDress;
|
||||
private readonly IClientLogic _logicClient;
|
||||
|
||||
private readonly IOrderLogic _logicOrder;
|
||||
public FormOrderCreation(ILogger<FormOrderCreation> logger, IDressLogic logicP, IOrderLogic logicO)
|
||||
public FormOrderCreation(ILogger<FormOrderCreation> logger, IDressLogic logicP, IOrderLogic logicO, IClientLogic logicC)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicDress = logicP;
|
||||
_logicOrder = logicO;
|
||||
_logicClient = logicC;
|
||||
}
|
||||
|
||||
private void FormOrderCreation_Load(object sender, EventArgs e)
|
||||
@ -48,6 +50,24 @@ namespace SewingDresses
|
||||
_logger.LogError(ex, "Downloading dresses for order error");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Downloading clients for order");
|
||||
try
|
||||
{
|
||||
var _list = _logicClient.ReadList(null);
|
||||
if (_list != null)
|
||||
{
|
||||
comboBoxClients.DisplayMember = "FullName";
|
||||
comboBoxClients.ValueMember = "ID";
|
||||
comboBoxClients.DataSource = _list;
|
||||
comboBoxClients.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Downloading clients for order error");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void CalcSum()
|
||||
@ -69,7 +89,7 @@ namespace SewingDresses
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Calculation total of order error");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -86,7 +106,7 @@ namespace SewingDresses
|
||||
{
|
||||
if (string.IsNullOrEmpty(quantityTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Fill quantity field", "Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show("Fill quantity field", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (dressComboBox.SelectedValue == null)
|
||||
@ -95,12 +115,20 @@ namespace SewingDresses
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxClients.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Choose client", "Error",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Creation of order");
|
||||
try
|
||||
{
|
||||
var operationResult = _logicOrder.CreateOrder(new OrderBindingModel
|
||||
{
|
||||
DressID = Convert.ToInt32(dressComboBox.SelectedValue),
|
||||
ClientID = Convert.ToInt32(comboBoxClients.SelectedValue),
|
||||
Count = Convert.ToInt32(quantityTextBox.Text),
|
||||
Sum = Convert.ToDouble(priceTextBox.Text)
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user