diff --git a/Hotel/HotelDataBaseImplement/Models/Conference.cs b/Hotel/HotelDataBaseImplement/Models/Conference.cs index b61cd1b..371c717 100644 --- a/Hotel/HotelDataBaseImplement/Models/Conference.cs +++ b/Hotel/HotelDataBaseImplement/Models/Conference.cs @@ -68,7 +68,7 @@ namespace HotelDataBaseImplement.Models var conferenceMembers = context.ConferenceMembers.Where(rec => rec.ConferenceId == model.Id).ToList(); if (conferenceMembers != null) - { // удалили те, которых нет в модели + { context.ConferenceMembers.RemoveRange(conferenceMembers.Where(rec => !model.ConferenceMembers.ContainsKey(rec.MemberId))); context.SaveChanges(); } diff --git a/Hotel/HotelDataBaseImplement/Models/MealPlan.cs b/Hotel/HotelDataBaseImplement/Models/MealPlan.cs index 1517c3e..693ec00 100644 --- a/Hotel/HotelDataBaseImplement/Models/MealPlan.cs +++ b/Hotel/HotelDataBaseImplement/Models/MealPlan.cs @@ -69,7 +69,7 @@ namespace HotelDataBaseImplement.Models var mealPlanMembers = context.MealPlanMembers.Where(rec => rec.MealPlanId == model.Id).ToList(); if (mealPlanMembers != null) - { // удалили те, которых нет в модели + { context.MealPlanMembers.RemoveRange(mealPlanMembers.Where(rec => !model.MealPlanMembers.ContainsKey(rec.MemberId))); context.SaveChanges(); } diff --git a/Hotel/HotelDataBaseImplement/Models/Member.cs b/Hotel/HotelDataBaseImplement/Models/Member.cs index d55e872..5d8c292 100644 --- a/Hotel/HotelDataBaseImplement/Models/Member.cs +++ b/Hotel/HotelDataBaseImplement/Models/Member.cs @@ -1,4 +1,6 @@ -using HotelDataModels.Models; +using HotelContracts.BindingModels; +using HotelContracts.ViewModels; +using HotelDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -23,7 +25,43 @@ namespace HotelDataBaseImplement.Models [ForeignKey("MemberId")] public virtual List ConferenceMember { get; set; } + public static Member? Create(MemberBindingModel model) + { + if (model == null) + { + return null; + } + return new Member() + { + Id = model.Id, + MemberFIO = model.MemberFIO, + Citizenship = model.Citizenship + }; + } + public static Member Create(MemberViewModel model) + { + return new Member + { + Id = model.Id, + MemberFIO = model.MemberFIO, + Citizenship = model.Citizenship + }; + } + public void Update(MemberBindingModel model) + { + if (model == null) + { + return; + } + MemberFIO = model.MemberFIO; + Citizenship = model.Citizenship; + } + public MemberViewModel GetViewModel => new() + { + Id = Id, + MemberFIO = MemberFIO, + Citizenship = Citizenship + }; - } }