This commit is contained in:
Кашин Максим 2023-04-02 16:41:29 +04:00
commit 0b29e90218
3 changed files with 42 additions and 4 deletions

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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> 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
};
}
}