From 3ebe39ff938b39acd0f2820a93400ec30ce37c1d Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Sun, 2 Apr 2023 16:32:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20Models?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Conference.cs | 2 +- .../HotelDataBaseImplement/Models/MealPlan.cs | 2 +- Hotel/HotelDataBaseImplement/Models/Member.cs | 42 ++++++++++++++++++- 3 files changed, 42 insertions(+), 4 deletions(-) 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 + }; - } }