diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/MessageInfoStorage.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/MessageInfoStorage.cs index 5e9f730..826716b 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/MessageInfoStorage.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/MessageInfoStorage.cs @@ -53,5 +53,17 @@ namespace FurnitureAssemFileImplement.Implements _source.SaveMessages(); return newClient.GetViewModel; } + + 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.SaveMessages(); + return message.GetViewModel; + } } } diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/MessageInfo.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/MessageInfo.cs index f051bf3..bbeccdc 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/MessageInfo.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/MessageInfo.cs @@ -19,6 +19,10 @@ namespace FurnitureAssemFileImplement.Models public string Body { get; private set; } = string.Empty; + public string? Reply { get; private set; } + + public bool IsRead { get; private set; } + public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) @@ -33,6 +37,8 @@ namespace FurnitureAssemFileImplement.Models Subject = model.Subject, SenderName = model.SenderName, DateDelivery = model.DateDelivery, + IsRead = model.IsRead, + Reply = model.Reply }; } @@ -49,10 +55,22 @@ namespace FurnitureAssemFileImplement.Models Body = element.Element("Body")!.Value, Subject = element.Element("Subject")!.Value, SenderName = element.Element("SenderName")!.Value, - DateDelivery = DateTime.ParseExact(element.Element("DateDelivery")!.Value, "G", null) + DateDelivery = DateTime.ParseExact(element.Element("DateDelivery")!.Value, "G", null), + IsRead = Convert.ToBoolean(element.Element("IsRead")!.Value), + Reply = element.Element("Reply")!.Value, }; } + public void Update(MessageInfoBindingModel model) + { + if (model == null) + { + return; + } + IsRead = model.IsRead; + Reply = model.Reply; + } + public MessageInfoViewModel GetViewModel => new() { Body = Body, @@ -61,6 +79,8 @@ namespace FurnitureAssemFileImplement.Models MessageId = MessageId, SenderName = SenderName, DateDelivery = DateDelivery, + IsRead = IsRead, + Reply = Reply }; public XElement GetXElement => new("MessageInfo", @@ -69,7 +89,9 @@ namespace FurnitureAssemFileImplement.Models new XElement("DateDelivery", DateDelivery), new XAttribute("MessageId", MessageId), new XElement("Body", Body), - new XElement("Subject", Subject) + new XElement("Subject", Subject), + new XElement("IsRead", IsRead), + new XElement("Reply", Reply) ); } } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/MessageInfoLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/MessageInfoLogic.cs index 1425e6c..6e798b3 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/MessageInfoLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/MessageInfoLogic.cs @@ -28,6 +28,23 @@ namespace FurnitureAssemblyBusinessLogic return true; } + public MessageInfoViewModel? ReadElement(MessageInfoSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. MessageId:{MessageId}", model.MessageId); + var element = _messageInfoStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.MessageId); + return element; + } + public List? ReadList(MessageInfoSearchModel? model) { _logger.LogInformation("ReadList. ClientId:{ClientId}. MessageId:{ MessageId}", model?.ClientId, model?.MessageId); @@ -40,5 +57,15 @@ namespace FurnitureAssemblyBusinessLogic _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } + + public bool Update(MessageInfoBindingModel model) + { + if (_messageInfoStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs index 10e611a..b6c365a 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,8 @@ namespace FurnitureAssemblyContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; + + public string? Reply { get; set; } + public bool IsRead { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IMessageInfoLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IMessageInfoLogic.cs index 2b7e15d..e20e1de 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IMessageInfoLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IMessageInfoLogic.cs @@ -6,7 +6,9 @@ namespace FurnitureAssemblyContracts.BusinessLogicsContarcts { public interface IMessageInfoLogic { + MessageInfoViewModel? ReadElement(MessageInfoSearchModel model); List? ReadList(MessageInfoSearchModel? model); bool Create(MessageInfoBindingModel model); + bool Update(MessageInfoBindingModel model); } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IMessageInfoStorage.cs b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IMessageInfoStorage.cs index 10663b3..9011dd6 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IMessageInfoStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IMessageInfoStorage.cs @@ -10,5 +10,6 @@ namespace FurnitureAssemblyContracts.StoragesContracts List GetFilteredList(MessageInfoSearchModel model); MessageInfoViewModel? GetElement(MessageInfoSearchModel model); MessageInfoViewModel? Insert(MessageInfoBindingModel model); + MessageInfoViewModel? Update(MessageInfoBindingModel model); } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs index 98b85aa..61cceed 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/MessageInfoViewModel.cs @@ -16,5 +16,9 @@ namespace FurnitureAssemblyContracts.ViewModels public string Subject { get; set; } = string.Empty; [DisplayName("Текст")] public string Body { get; set; } = string.Empty; + [DisplayName("Прочитано")] + public bool IsRead { get; set; } + [DisplayName("Ответ")] + public string? Reply { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs index 6139889..fe65a0e 100644 --- a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IMessageInfoModel.cs @@ -8,5 +8,7 @@ DateTime DateDelivery { get; } string Subject { get; } string Body { get; } + bool IsRead { get; } + string? Reply { get; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/MessageInfoStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/MessageInfoStorage.cs index 50468d4..d66d4e7 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/MessageInfoStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/MessageInfoStorage.cs @@ -55,5 +55,18 @@ namespace FurnitureAssemblyDatabaseImplement.Implements context.SaveChanges(); return newMessage.GetViewModel; } + + public MessageInfoViewModel? Update(MessageInfoBindingModel model) + { + using var context = new FurnitureAssemblyDatabase(); + var element = context.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId)); + if (element == null) + { + return null; + } + element.Update(model); + context.SaveChanges(); + return context.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId))?.GetViewModel; + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230422115706_Message2.Designer.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230422115706_Message2.Designer.cs new file mode 100644 index 0000000..f184cfc --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230422115706_Message2.Designer.cs @@ -0,0 +1,379 @@ +// +using System; +using FurnitureAssemblyDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FurnitureAssemblyDatabaseImplement.Migrations +{ + [DbContext(typeof(FurnitureAssemblyDatabase))] + [Migration("20230422115706_Message2")] + partial class Message2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FurnitureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Furnitures"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("FurnitureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("FurnitureId"); + + b.ToTable("FurnitureComponents"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("IsRead") + .HasColumnType("bit"); + + b.Property("Reply") + .HasColumnType("nvarchar(max)"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("FurnitureId") + .HasColumnType("int"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("FurnitureId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpening") + .HasColumnType("datetime2"); + + b.Property("MaxCount") + .HasColumnType("int"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.ShopFurniture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("FurnitureId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("FurnitureId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopFurniture"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureComponent", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Component", "Component") + .WithMany("FurnitureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Components") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Furniture"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Orders") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.Navigation("Client"); + + b.Navigation("Furniture"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.ShopFurniture", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany() + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Shop", "Shop") + .WithMany("ShopFurnitures") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Furniture"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b => + { + b.Navigation("Messages"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b => + { + b.Navigation("FurnitureComponents"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Shop", b => + { + b.Navigation("ShopFurnitures"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230422115706_Message2.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230422115706_Message2.cs new file mode 100644 index 0000000..dbf522a --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230422115706_Message2.cs @@ -0,0 +1,39 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FurnitureAssemblyDatabaseImplement.Migrations +{ + /// + public partial class Message2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "IsRead", + table: "Messages", + type: "bit", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "Reply", + table: "Messages", + type: "nvarchar(max)", + nullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "IsRead", + table: "Messages"); + + migrationBuilder.DropColumn( + name: "Reply", + table: "Messages"); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs index 1e256ea..661a587 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs @@ -155,6 +155,12 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.Property("DateDelivery") .HasColumnType("datetime2"); + b.Property("IsRead") + .HasColumnType("bit"); + + b.Property("Reply") + .HasColumnType("nvarchar(max)"); + b.Property("SenderName") .IsRequired() .HasColumnType("nvarchar(max)"); @@ -319,11 +325,6 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.Navigation("Implementer"); }); - modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b => - { - b.Navigation("Messages"); - }); - modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.ShopFurniture", b => { b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") @@ -343,6 +344,11 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.Navigation("Shop"); }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b => + { + b.Navigation("Messages"); + }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b => { b.Navigation("FurnitureComponents"); diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs index 291789b..f2d74d2 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/MessageInfo.cs @@ -20,6 +20,10 @@ namespace FurnitureAssemblyDatabaseImplement.Models public string Body { get; private set; } = string.Empty; + public string? Reply { get; private set; } + + public bool IsRead { get; private set; } + public virtual Client? Client { get; private set; } public static MessageInfo? Create(MessageInfoBindingModel model) @@ -36,9 +40,21 @@ namespace FurnitureAssemblyDatabaseImplement.Models MessageId = model.MessageId, SenderName = model.SenderName, DateDelivery = model.DateDelivery, + IsRead = model.IsRead, + Reply = model.Reply }; } + public void Update(MessageInfoBindingModel model) + { + if (model == null) + { + return; + } + IsRead = model.IsRead; + Reply = model.Reply; + } + public MessageInfoViewModel GetViewModel => new() { Body = Body, @@ -47,6 +63,8 @@ namespace FurnitureAssemblyDatabaseImplement.Models MessageId = MessageId, SenderName = SenderName, DateDelivery = DateDelivery, + IsRead = IsRead, + Reply = Reply }; } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/MessageInfoStorage.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/MessageInfoStorage.cs index d2db11d..11626e5 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/MessageInfoStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/MessageInfoStorage.cs @@ -64,5 +64,18 @@ namespace FurnitureAssemblyListImplement.Implements _source.Messages.Add(newMessage); return newMessage.GetViewModel; } + + public MessageInfoViewModel? Update(MessageInfoBindingModel model) + { + foreach (var m in _source.Messages) + { + if (m.MessageId.Equals(model.MessageId)) + { + m.Update(model); + return m.GetViewModel; + } + } + return null; + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs index 332bb9f..d1c8659 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/MessageInfo.cs @@ -18,6 +18,10 @@ namespace FurnitureAssemblyListImplement.Models public string Body { get; private set; } = string.Empty; + public string? Reply { get; private set; } + + public bool IsRead { get; private set; } + public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) @@ -32,9 +36,21 @@ namespace FurnitureAssemblyListImplement.Models Subject = model.Subject, SenderName = model.SenderName, DateDelivery = model.DateDelivery, + IsRead = model.IsRead, + Reply = model.Reply }; } + public void Update(MessageInfoBindingModel model) + { + if (model == null) + { + return; + } + IsRead = model.IsRead; + Reply = model.Reply; + } + public MessageInfoViewModel GetViewModel => new() { Body = Body, @@ -43,6 +59,8 @@ namespace FurnitureAssemblyListImplement.Models MessageId = MessageId, SenderName = SenderName, DateDelivery = DateDelivery, + IsRead = IsRead, + Reply = Reply }; } }