Добавлена логика изменения сообщения

This commit is contained in:
Данияр Аглиуллов 2023-03-18 01:57:49 +04:00
parent 9f71199535
commit be8b7adbf8
6 changed files with 53 additions and 4 deletions

View File

@ -33,7 +33,17 @@ namespace ConfectioneryBusinessLogic
return true;
}
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
public bool Update(MessageInfoBindingModel model)
{
if (_messageInfoStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
{
_logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId} ", model?.MessageId, model?.ClientId);
var list = (model == null) ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model);

View File

@ -55,5 +55,16 @@ namespace ConfectioneryFileImplement
_source.SaveMessages();
return newMessage.GetViewModel;
}
}
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
{
var res = _source.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId));
if (res != null)
{
res.Update(model);
_source.SaveMessages();
}
return res?.GetViewModel;
}
}
}

View File

@ -72,5 +72,18 @@ namespace ConfectioneryListImplement
_source.Messages.Add(newMessage);
return newMessage.GetViewModel;
}
}
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
{
foreach (var message in _source.Messages)
{
if (message.MessageId.Equals(model.MessageId))
{
message.Update(model);
return message.GetViewModel;
}
}
return null;
}
}
}

View File

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

View File

@ -18,5 +18,6 @@ namespace ConfectioneryContracts.StoragesContract
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
MessageInfoViewModel? Update(MessageInfoBindingModel model);
}
}

View File

@ -52,5 +52,17 @@ namespace ConfectioneryDatabaseImplement
context.SaveChanges();
return newMessage.GetViewModel;
}
}
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
{
using var context = new ConfectioneryDatabase();
var res = context.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId));
if (res != null)
{
res.Update(model);
context.SaveChanges();
}
return res?.GetViewModel;
}
}
}