diff --git a/BeautySalonView/BeautySalonBusinesLogic/BusinessLogic/MessageInfoLogic.cs b/BeautySalonView/BeautySalonBusinesLogic/BusinessLogic/MessageInfoLogic.cs index e3180fd..929cdab 100644 --- a/BeautySalonView/BeautySalonBusinesLogic/BusinessLogic/MessageInfoLogic.cs +++ b/BeautySalonView/BeautySalonBusinesLogic/BusinessLogic/MessageInfoLogic.cs @@ -17,15 +17,17 @@ namespace BeautySalonBusinesLogic.BusinessLogic private readonly ILogger _logger; private readonly IMessageInfoStorage _messageInfoStorage; private readonly IClientStorage _clientStorage; - public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageInfoStorage, IClientStorage clientStorage) + private readonly IStaffMemberStorage _staffmemberStorage; + public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageInfoStorage, IClientStorage clientStorage, IStaffMemberStorage staffmemberStorage) { _logger = logger; _messageInfoStorage = messageInfoStorage; _clientStorage = clientStorage; + _staffmemberStorage = staffmemberStorage; } public List? ReadList(MessageInfoSearchModel? model) { - _logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId}", model?.MessageId, model?.ClientId); + _logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId}.StaffMemberId:{StaffMemberId}", model?.MessageId, model?.ClientId, model?.StaffMemberId); var list = model == null ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model); if (list == null) { diff --git a/BeautySalonView/BeautySalonBusinesLogic/BusinessLogic/StaffMemberLogic.cs b/BeautySalonView/BeautySalonBusinesLogic/BusinessLogic/StaffMemberLogic.cs index 31166ec..77dabb1 100644 --- a/BeautySalonView/BeautySalonBusinesLogic/BusinessLogic/StaffMemberLogic.cs +++ b/BeautySalonView/BeautySalonBusinesLogic/BusinessLogic/StaffMemberLogic.cs @@ -4,6 +4,7 @@ using BeautySalonContracts.SearchModels; using BeautySalonContracts.StoragesContracts; using BeautySalonContracts.ViewModels; using Microsoft.Extensions.Logging; +using System.Text.RegularExpressions; namespace BeautySalonBusinesLogic.BusinessLogic { @@ -124,9 +125,9 @@ namespace BeautySalonBusinesLogic.BusinessLogic { throw new ArgumentNullException("Нет логина сотрудника", nameof(model.StaffMemberLogin)); } - if (string.IsNullOrEmpty(model.StaffMemberEmail)) + if (!Regex.IsMatch(model.StaffMemberEmail, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$")) { - throw new ArgumentNullException("Нет почты сотрудника", nameof(model.StaffMemberEmail)); + throw new ArgumentException("Некорретно введенный email", nameof(model.StaffMemberEmail)); } if (string.IsNullOrEmpty(model.StaffMemberPassword)) { @@ -134,7 +135,7 @@ namespace BeautySalonBusinesLogic.BusinessLogic } if (string.IsNullOrEmpty(model.StaffMemberPhone)) { - throw new ArgumentNullException("Нет телефона сотрудника", nameof(model.StaffMemberEmail)); + throw new ArgumentNullException("Нет телефона сотрудника", nameof(model.StaffMemberPhone)); } if (model.StaffMemberPassword.Length < _passwordMinLength) diff --git a/BeautySalonView/BeautySalonContracts/BindingModels/MessageInfoBindingModel.cs b/BeautySalonView/BeautySalonContracts/BindingModels/MessageInfoBindingModel.cs index 8d3579c..5fc36a2 100644 --- a/BeautySalonView/BeautySalonContracts/BindingModels/MessageInfoBindingModel.cs +++ b/BeautySalonView/BeautySalonContracts/BindingModels/MessageInfoBindingModel.cs @@ -11,7 +11,8 @@ namespace BeautySalonContracts.BindingModels { public string MessageId { get; set; } = string.Empty; public int? ClientId { get; set; } - public string SenderName { get; set; } = string.Empty; + public int? StaffMemberId { get; set; } + public string SenderName { get; set; } = string.Empty; public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } diff --git a/BeautySalonView/BeautySalonContracts/SearchModels/MessageInfoSearchModel.cs b/BeautySalonView/BeautySalonContracts/SearchModels/MessageInfoSearchModel.cs index ed0b8fc..9dbcf2b 100644 --- a/BeautySalonView/BeautySalonContracts/SearchModels/MessageInfoSearchModel.cs +++ b/BeautySalonView/BeautySalonContracts/SearchModels/MessageInfoSearchModel.cs @@ -9,6 +9,7 @@ namespace BeautySalonContracts.SearchModels public class MessageInfoSearchModel { public int? ClientId { get; set; } - public string? MessageId { get; set; } + public int? StaffMemberId { get; set; } + public string? MessageId { get; set; } } } diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/MessageInfoViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/MessageInfoViewModel.cs index b234f17..762844f 100644 --- a/BeautySalonView/BeautySalonContracts/ViewModels/MessageInfoViewModel.cs +++ b/BeautySalonView/BeautySalonContracts/ViewModels/MessageInfoViewModel.cs @@ -15,7 +15,11 @@ namespace BeautySalonContracts.ViewModels public int? ClientId { get; set; } [DisplayName("Отправитель")] - public string SenderName { get; set; } = string.Empty; + + public int? StaffMemberId { get; set; } + + [DisplayName("Получатель")] + public string SenderName { get; set; } = string.Empty; [DisplayName("Дата письма")] public DateTime DateDelivery { get; set; } diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Implements/MessageInfoStorage.cs b/BeautySalonView/BeautySalonDatabaseImplement/Implements/MessageInfoStorage.cs index 9859309..a9f971b 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Implements/MessageInfoStorage.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Implements/MessageInfoStorage.cs @@ -11,42 +11,48 @@ using System.Threading.Tasks; namespace BeautySalonDatabaseImplement.Implements { - public class MessageInfoStorage : IMessageInfoStorage - { - public List GetFullList() - { - using var context = new BeautySalonDatabase(); - return context.MessageInfos.Select(x => x.GetViewModel).ToList(); - } - public List GetFilteredList(MessageInfoSearchModel model) - { - if (!model.ClientId.HasValue) - { - return new(); - } - using var context = new BeautySalonDatabase(); - return context.MessageInfos.Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); - } - public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) - { - if (string.IsNullOrEmpty(model.MessageId)) - { - return new(); - } - using var context = new BeautySalonDatabase(); - return context.MessageInfos.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; - } - public MessageInfoViewModel? Insert(MessageInfoBindingModel model) - { - var newMessage = MessageInfo.Create(model); - if (newMessage == null) - { - return null; - } - using var context = new BeautySalonDatabase(); - context.MessageInfos.Add(newMessage); - context.SaveChanges(); - return newMessage.GetViewModel; - } - } -} + public class MessageInfoStorage : IMessageInfoStorage + { + public List GetFullList() + { + using var context = new BeautySalonDatabase(); + return context.MessageInfos.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(MessageInfoSearchModel model) + { + if (!model.ClientId.HasValue) + { + return new List(); + } + + using var context = new BeautySalonDatabase(); + + return context.MessageInfos + .Where(x => x.ClientId == model.ClientId && x.StaffMemberId == model.StaffMemberId) + .Select(x => x.GetViewModel) + .ToList(); + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (string.IsNullOrEmpty(model.MessageId)) + { + return new(); + } + using var context = new BeautySalonDatabase(); + return context.MessageInfos.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; + } + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = MessageInfo.Create(model); + if (newMessage == null) + { + return null; + } + using var context = new BeautySalonDatabase(); + context.MessageInfos.Add(newMessage); + context.SaveChanges(); + return newMessage.GetViewModel; + } + } +} \ No newline at end of file diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/MessageInfo.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/MessageInfo.cs index d788110..caca52b 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Models/MessageInfo.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/MessageInfo.cs @@ -21,7 +21,11 @@ namespace BeautySalonDatabaseImplement.Models public virtual Client? Client { get; set; } - [Required] + public int? StaffMemberId { get; set; } + + public virtual StaffMember? StaffMember { get; set; } + + [Required] public string SenderName { get; set; } = string.Empty; [Required] @@ -43,7 +47,8 @@ namespace BeautySalonDatabaseImplement.Models { MessageId = model.MessageId, ClientId = model.ClientId, - SenderName = model.SenderName, + StaffMemberId = model.StaffMemberId, + SenderName = model.SenderName, DateDelivery = model.DateDelivery, Subject = model.Subject, Body = model.Body, @@ -51,11 +56,13 @@ namespace BeautySalonDatabaseImplement.Models }; } - public MessageInfoViewModel GetViewModel => new() + + public MessageInfoViewModel GetViewModel => new() { MessageId = MessageId, ClientId = ClientId, - SenderName = SenderName, + StaffMemberId = StaffMemberId, + SenderName = SenderName, DateDelivery = DateDelivery, Subject = Subject, Body = Body diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/StaffMember.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/StaffMember.cs index 2c81f17..d8bf371 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Models/StaffMember.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/StaffMember.cs @@ -34,6 +34,8 @@ namespace BeautySalonDatabaseImplement.Models //[ForeignKey("StaffMemberId")] //public virtual List Services { get; set; } = new(); + public virtual List Messages { get; set; } = new(); + public static StaffMember? Create(StaffMemberBindingModel model) {