コード例 #1
0
 public void Insert(AccountingBindingModel model)
 {
     using (var context = new HotelContext())
     {
         context.Accounting.Add(CreateModel(model, new Accounting(), context));
         context.SaveChanges();
     }
 }
コード例 #2
0
 private Accounting CreateModel(AccountingBindingModel model, Accounting accounting, HotelContext database)
 {
     accounting.Clientid  = model.Clientid;
     accounting.Startdate = model.Startdate;
     accounting.Cost      = model.Cost;
     accounting.Enddate   = model.Enddate;
     accounting.Roomid    = model.Roomid;
     return(accounting);
 }
コード例 #3
0
 public void CreateOrUpdate(AccountingBindingModel model)
 {
     if (model.Id.HasValue)
     {
         _accountingStorage.Update(model);
     }
     else
     {
         _accountingStorage.Insert(model);
     }
 }
コード例 #4
0
 public void Update(AccountingBindingModel model)
 {
     using (var context = new HotelContext())
     {
         var element = context.Accounting.FirstOrDefault(rec => rec.Id == model.Id);
         if (element == null)
         {
             throw new Exception("Клиент не найден");
         }
         CreateModel(model, element, context);
         context.SaveChanges();
     }
 }
コード例 #5
0
        public void Delete(AccountingBindingModel model)
        {
            var element = _accountingStorage.GetElement(new AccountingBindingModel
            {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Элемент не найден");
            }
            _accountingStorage.Delete(model);
        }
コード例 #6
0
 public List <AccountingViewModel> Read(AccountingBindingModel model)
 {
     if (model == null)
     {
         return(_accountingStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <AccountingViewModel> {
             _accountingStorage.GetElement(model)
         });
     }
     return(_accountingStorage.GetFilteredList(model));
 }
コード例 #7
0
 public void Delete(AccountingBindingModel model)
 {
     using (var context = new HotelContext())
     {
         Accounting element = context.Accounting.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Accounting.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Клиент не найден");
         }
     }
 }
コード例 #8
0
 public List <AccountingViewModel> GetFilteredList(AccountingBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new HotelContext())
     {
         return(context.Accounting
                .Where(rec => rec.Enddate == model.Enddate)
                .Select(rec => new AccountingViewModel
         {
             Id = rec.Id,
             Clientid = rec.Clientid,
             Startdate = rec.Startdate,
             Cost = rec.Cost,
             Enddate = rec.Enddate,
             Roomid = rec.Roomid
         })
                .ToList());
     }
 }
コード例 #9
0
 public AccountingViewModel GetElement(AccountingBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new HotelContext())
     {
         var accounting = context.Accounting
                          .FirstOrDefault(rec => rec.Id == model.Id);
         return(accounting != null ?
                new AccountingViewModel
         {
             Id = accounting.Id,
             Clientid = accounting.Clientid,
             Startdate = accounting.Startdate,
             Cost = accounting.Cost,
             Enddate = accounting.Enddate,
             Roomid = accounting.Roomid
         } :
                null);
     }
 }