Exemplo n.º 1
0
 public void CreateOrUpdate(ReserveBindingModel model)
 {
     if (model.Id.HasValue)
     {
         _reserveStorage.Update(model);
     }
     else
     {
         _reserveStorage.Insert(model);
     }
 }
 public void Insert(ReserveBindingModel model)
 {
     using (var context = new UrskiyPeriodDatabase())
     {
         if (context.Reserves.FirstOrDefault(rec => rec.Name == model.Name) != null)
         {
             return;
         }
         context.Reserves.Add(CreateModel(new Reserve(), model));
         context.SaveChanges();
     }
 }
 public List <ReserveViewModel> GetFilteredList(ReserveBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new UrskiyPeriodDatabase())
     {
         return(context.Reserves.Include(x => x.Payment)
                .Where(rec => rec.RouteReserve.Select(x => x.RouteId).Contains(model.RouteId)).Select(CreateModel).ToList());
     }
 }
Exemplo n.º 4
0
 public void Delete(ReserveBindingModel model)
 {
     var element = _reserveStorage.GetElement(new ReserveBindingModel
     {
         Id = model.Id
     });
     if (element == null)
     {
         throw new Exception("Заповедник найден");
     }
     _reserveStorage.Delete(model);
 }
Exemplo n.º 5
0
 public List<ReserveViewModel> Read(ReserveBindingModel model)
 {
     if (model == null)
     {
         return _reserveStorage.GetFullList();
     }
     if (model.Id.HasValue || model.Name != null)
     {
         return new List<ReserveViewModel> { _reserveStorage.GetElement(model) };
     }
     return _reserveStorage.GetFilteredList(model);
 }
 public void Delete(ReserveBindingModel model)
 {
     using (var context = new UrskiyPeriodDatabase())
     {
         var user = context.Reserves.FirstOrDefault(rec => rec.Id == model.Id);
         if (user == null)
         {
             throw new Exception("Заповедник не найден");
         }
         context.Reserves.Remove(user);
         context.SaveChanges();
     }
 }
 public ReserveViewModel GetElement(ReserveBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new UrskiyPeriodDatabase())
     {
         var route = context.Reserves.Include(x => x.Payment)
                     .FirstOrDefault(rec => rec.Id == model.Id || rec.Name == model.Name);
         return(route != null?CreateModel(route) : null);
     }
 }
 private Reserve CreateModel(Reserve reserve, ReserveBindingModel model)
 {
     reserve.Name  = model.Name;
     reserve.Price = model.Price;
     return(reserve);
 }