почта для сотрудника...
This commit is contained in:
parent
0bbc4a53ef
commit
246341e9ad
@ -17,15 +17,17 @@ namespace BeautySalonBusinesLogic.BusinessLogic
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMessageInfoStorage _messageInfoStorage;
|
||||
private readonly IClientStorage _clientStorage;
|
||||
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageInfoStorage, IClientStorage clientStorage)
|
||||
private readonly IStaffMemberStorage _staffmemberStorage;
|
||||
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageInfoStorage, IClientStorage clientStorage, IStaffMemberStorage staffmemberStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_messageInfoStorage = messageInfoStorage;
|
||||
_clientStorage = clientStorage;
|
||||
_staffmemberStorage = staffmemberStorage;
|
||||
}
|
||||
public List<MessageInfoViewModel>? 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)
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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; }
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
|
@ -11,42 +11,48 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BeautySalonDatabaseImplement.Implements
|
||||
{
|
||||
public class MessageInfoStorage : IMessageInfoStorage
|
||||
{
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
return context.MessageInfos.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<MessageInfoViewModel> 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<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
return context.MessageInfos.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
if (!model.ClientId.HasValue)
|
||||
{
|
||||
return new List<MessageInfoViewModel>();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -34,6 +34,8 @@ namespace BeautySalonDatabaseImplement.Models
|
||||
//[ForeignKey("StaffMemberId")]
|
||||
//public virtual List<Service> Services { get; set; } = new();
|
||||
|
||||
public virtual List<MessageInfo> Messages { get; set; } = new();
|
||||
|
||||
public static StaffMember? Create(StaffMemberBindingModel model)
|
||||
{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user