Этап с модернизацией писем.

This commit is contained in:
Programmist73 2023-04-30 18:16:40 +04:00
parent 4e78fd4c3e
commit 6ca35bcd5d
12 changed files with 169 additions and 36 deletions

View File

@ -53,5 +53,17 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
return true;
}
}
public bool Update(MessageInfoBindingModel model)
{
if (_messageInfoStorage.Update(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
}
}

View File

@ -20,5 +20,9 @@ namespace BlacksmithWorkshopContracts.BindingModels
public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
}
public bool IsRead { get; set; } = false;
public string? Answer { get; set; } = string.Empty;
}
}

View File

@ -14,5 +14,7 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
bool Create(MessageInfoBindingModel model);
}
bool Update(MessageInfoBindingModel model);
}
}

View File

@ -18,5 +18,7 @@ namespace BlacksmithWorkshopContracts.StoragesContracts
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
}
MessageInfoViewModel? Update(MessageInfoBindingModel model);
}
}

View File

@ -14,7 +14,9 @@ namespace BlacksmithWorkshopContracts.ViewModels
public int? ClientId { get; set; }
[DisplayName("Отправитель")]
public bool IsRead { get; set; } = false;
[DisplayName("Отправитель")]
public string SenderName { get; set; } = string.Empty;
[DisplayName("Дата отправки")]
@ -25,5 +27,11 @@ namespace BlacksmithWorkshopContracts.ViewModels
[DisplayName("Текст")]
public string Body { get; set; } = string.Empty;
}
[DisplayName("Прочитано")]
public string statusChecking { get; set; } = string.Empty;
[DisplayName("Ответ")]
public string? Answer { get; set; } = string.Empty;
}
}

View File

@ -19,5 +19,9 @@ namespace BlacksmithWorkshopDataModels.Models
string Subject { get; }
string Body { get; }
bool IsRead { get; }
string Answer { get; }
}
}

View File

@ -63,5 +63,24 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
return newMessage.GetViewModel;
}
}
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
{
using var context = new BlacksmithWorkshopDatabase();
var message = context.Messages
.FirstOrDefault(x => x.MessageId.Equals(model.MessageId));
if (message == null)
{
return null;
}
message.Update(model);
context.SaveChanges();
return context.Messages
.FirstOrDefault(x => x.MessageId.Equals(model.MessageId))
?.GetViewModel;
}
}
}

View File

@ -17,7 +17,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
public int? ClientId { get; set; }
[Required]
public bool IsRead { get; set; } = false;
[Required]
public string SenderName { get; set; } = string.Empty;
[Required]
@ -29,7 +31,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
[Required]
public string Body { get; set; } = string.Empty;
public virtual Client? Client { get; set; }
public string? Answer { get; set; } = string.Empty;
public virtual Client? Client { get; set; }
public static MessageInfo? Create(MessageInfoBindingModel model)
{
@ -45,18 +49,39 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
SenderName = model.SenderName,
Body = model.Body,
DateDelivery = model.DateDelivery,
Subject = model.Subject
Subject = model.Subject,
IsRead = model.IsRead,
Answer = model.Answer
};
}
public MessageInfoViewModel GetViewModel => new()
public void Update(MessageInfoBindingModel model)
{
if (model == null)
{
return;
}
MessageId = model.MessageId;
ClientId = model.ClientId;
SenderName = model.SenderName;
Body = model.Body;
DateDelivery = model.DateDelivery;
Subject = model.Subject;
IsRead = model.IsRead;
Answer = model.Answer;
}
public MessageInfoViewModel GetViewModel => new()
{
MessageId = MessageId,
ClientId = ClientId,
SenderName = SenderName,
Body = Body,
DateDelivery = DateDelivery,
Subject = Subject
};
}
Subject = Subject,
IsRead = IsRead,
Answer = Answer
};
}
}

View File

@ -67,10 +67,26 @@ namespace BlacksmithWorkshopFileImplement.Implements
return GetViewModel(newMessage);
}
//для загрузки названий и имён в заказ
private MessageInfoViewModel GetViewModel(MessageInfo message)
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
{
var message = source.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId));
if (message == null)
{
return null;
}
message.Update(model);
source.SaveClients();
return message.GetViewModel;
}
//для загрузки названий и имён в заказ
private MessageInfoViewModel GetViewModel(MessageInfo message)
{
return message.GetViewModel;
}
}
}
}

View File

@ -18,7 +18,9 @@ namespace BlacksmithWorkshopFileImplement.Models
public int? ClientId { get; private set; }
public string SenderName { get; private set; } = string.Empty;
public bool IsRead { get; private set; } = false;
public string SenderName { get; private set; } = string.Empty;
public DateTime DateDelivery { get; private set; } = DateTime.Now;
@ -26,7 +28,9 @@ namespace BlacksmithWorkshopFileImplement.Models
public string Body { get; private set; } = string.Empty;
public static MessageInfo? Create(MessageInfoBindingModel model)
public string? Answer { get; private set; } = string.Empty;
public static MessageInfo? Create(MessageInfoBindingModel model)
{
if (model == null)
{
@ -40,7 +44,9 @@ namespace BlacksmithWorkshopFileImplement.Models
SenderName = model.SenderName,
Body = model.Body,
Subject = model.Subject,
DateDelivery = model.DateDelivery
DateDelivery = model.DateDelivery,
IsRead = model.IsRead,
Answer = model.Answer
};
}
@ -58,8 +64,10 @@ namespace BlacksmithWorkshopFileImplement.Models
SenderName = element.Element("SenderName")!.Value,
Body = element.Element("Body")!.Value,
Subject = element.Element("Subject")!.Value,
DateDelivery = Convert.ToDateTime(element.Element("DateDelivery")!.Value)
};
DateDelivery = Convert.ToDateTime(element.Element("DateDelivery")!.Value),
IsRead = Convert.ToBoolean(element.Element("IsRead")!.Value),
Answer = element.Element("Answer")!.Value
};
}
public void Update(MessageInfoBindingModel model)
@ -75,7 +83,10 @@ namespace BlacksmithWorkshopFileImplement.Models
Body = model.Body;
Subject = model.Subject;
DateDelivery = model.DateDelivery;
}
IsRead = model.IsRead;
Answer = model.Answer;
}
public MessageInfoViewModel GetViewModel => new()
{
@ -84,8 +95,10 @@ namespace BlacksmithWorkshopFileImplement.Models
SenderName = SenderName,
Body = Body,
Subject = Subject,
DateDelivery = DateDelivery
};
DateDelivery = DateDelivery,
IsRead = IsRead,
Answer = Answer
};
public XElement GetXElement => new("MessageInfo",
new XAttribute("MessageId", MessageId),
@ -93,6 +106,8 @@ namespace BlacksmithWorkshopFileImplement.Models
new XElement("SenderName", SenderName),
new XElement("Body", Body),
new XElement("Subject", Subject),
new XElement("DateDelivery", DateDelivery.ToString()));
}
new XElement("DateDelivery", DateDelivery.ToString()),
new XElement("IsRead", IsRead),
new XElement("Answer", Answer));
}
}

View File

@ -84,5 +84,20 @@ namespace BlacksmithWorkshopListImplement.Implements
return newMessage.GetViewModel;
}
}
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
{
foreach (var message in _source.MessageInfos)
{
if (message.MessageId.Equals(model.MessageId))
{
message.Update(model);
return message.GetViewModel;
}
}
return null;
}
}
}

View File

@ -16,7 +16,9 @@ namespace BlacksmithWorkshopListImplement.Models
public int? ClientId { get; private set; }
public string SenderName { get; private set; } = string.Empty;
public bool IsRead { get; private set; }
public string SenderName { get; private set; } = string.Empty;
public DateTime DateDelivery { get; private set; } = DateTime.Now;
@ -24,8 +26,10 @@ namespace BlacksmithWorkshopListImplement.Models
public string Body { get; private set; } = string.Empty;
//метод для создания объекта от класса-компонента на основе класса-BindingModel
public static MessageInfo? Create(MessageInfoBindingModel? model)
public string? Answer { get; private set; } = string.Empty;
//метод для создания объекта от класса-компонента на основе класса-BindingModel
public static MessageInfo? Create(MessageInfoBindingModel? model)
{
if (model == null)
{
@ -39,7 +43,9 @@ namespace BlacksmithWorkshopListImplement.Models
SenderName = model.SenderName,
DateDelivery = model.DateDelivery,
Subject = model.Subject,
Body = model.Body
Body = model.Body,
IsRead = model.IsRead,
Answer = model.Answer
};
}
@ -57,7 +63,10 @@ namespace BlacksmithWorkshopListImplement.Models
DateDelivery = model.DateDelivery;
Subject = model.Subject;
Body = model.Body;
}
IsRead = model.IsRead;
Answer = model.Answer;
}
//метод для создания объекта класса ViewModel на основе данных объекта класса-компонента
public MessageInfoViewModel GetViewModel => new()
@ -67,7 +76,9 @@ namespace BlacksmithWorkshopListImplement.Models
SenderName = SenderName,
DateDelivery = DateDelivery,
Subject = Subject,
Body = Body
};
}
Body = Body,
IsRead = IsRead,
Answer = Answer
};
}
}