From 78f2162efe30d241482287a41c79e75ea5fc33f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sun, 2 Apr 2023 15:07:36 +0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8=20Hea?= =?UTF-8?q?dwaiter=20=D0=B2=20DataBaseImplement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Headwaiter.cs | 84 +++++++++++++++++-- 1 file changed, 77 insertions(+), 7 deletions(-) diff --git a/Hotel/HotelDataBaseImplement/Models/Headwaiter.cs b/Hotel/HotelDataBaseImplement/Models/Headwaiter.cs index 0e6f1a0..202843c 100644 --- a/Hotel/HotelDataBaseImplement/Models/Headwaiter.cs +++ b/Hotel/HotelDataBaseImplement/Models/Headwaiter.cs @@ -1,6 +1,10 @@ -using HotelDataModels.Models; +using HotelContracts.BindingModels; +using HotelContracts.ViewModels; +using HotelDataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,16 +13,82 @@ namespace HotelDataBaseImplement.Models { public class Headwaiter : IHeadwaiterModel { - public string HeadwaiterFIO => throw new NotImplementedException(); + public int Id { get; private set; } + + [Required] + public string HeadwaiterFIO { get; set; } = string.Empty; - public string HeadwaiterPassword => throw new NotImplementedException(); + [Required] + public string HeadwaiterEmail { get; set; } = string.Empty; - public string HeadwaiterLogin => throw new NotImplementedException(); + [Required] + public string HeadwaiterPassword { get; set; } = string.Empty; - public string HeadwaiterEmail => throw new NotImplementedException(); + [Required] + public string HeadwaiterLogin { get; set; } = string.Empty; - public string HeadwaiterNumber => throw new NotImplementedException(); + [Required] + public string HeadwaiterNumber { get; set; } = string.Empty; + + + [ForeignKey("HeadwaiterId")] + public virtual List Rooms { get; set; } = new(); + + [ForeignKey("HeadwaiterId")] + public virtual List Dinners { get; set; } = new(); + + [ForeignKey("HeadwaiterId")] + public virtual List ConferenceBookings { get; set; } = new(); + public static Headwaiter? Create(HeadwaiterBindingModel model) + { + if (model == null) + { + return null; + } + return new Headwaiter() + { + Id = model.Id, + HeadwaiterFIO = model.HeadwaiterFIO, + HeadwaiterEmail = model.HeadwaiterEmail, + HeadwaiterPassword = model.HeadwaiterPassword, + HeadwaiterLogin = model.HeadwaiterLogin, + HeadwaiterNumber = model.HeadwaiterNumber + }; + } + public static Headwaiter Create(HeadwaiterViewModel model) + { + return new Headwaiter + { + Id = model.Id, + HeadwaiterFIO = model.HeadwaiterFIO, + HeadwaiterEmail = model.HeadwaiterEmail, + HeadwaiterPassword = model.HeadwaiterPassword, + HeadwaiterLogin = model.HeadwaiterLogin, + HeadwaiterNumber = model.HeadwaiterNumber + }; + } + public void Update(HeadwaiterBindingModel model) + { + if (model == null) + { + return; + } + Id = model.Id; + HeadwaiterFIO = model.HeadwaiterFIO; + HeadwaiterEmail = model.HeadwaiterEmail; + HeadwaiterPassword = model.HeadwaiterPassword; + HeadwaiterLogin = model.HeadwaiterLogin; + HeadwaiterNumber = model.HeadwaiterNumber; + } + public HeadwaiterViewModel GetViewModel => new() + { + Id = Id, + HeadwaiterFIO = HeadwaiterFIO, + HeadwaiterEmail = HeadwaiterEmail, + HeadwaiterPassword = HeadwaiterPassword, + HeadwaiterLogin = HeadwaiterLogin, + HeadwaiterNumber = HeadwaiterNumber + }; - public int Id => throw new NotImplementedException(); } }