Ejemplo n.º 1
0
 public void Insert(BalanceBindingModel model)
 {
     using (var context = new AdBoardDatabase())
     {
         context.Balance.Add(CreateModel(model, new Balance()));
         context.SaveChanges();
     }
 }
Ejemplo n.º 2
0
 private Balance CreateModel(BalanceBindingModel model, Balance balance)
 {
     model.Id       = balance.Id;
     model.CardFIO  = balance.CardFIO;
     model.Username = balance.User.Username;
     model.CardNumb = balance.CardFIO;
     model.CardDate = balance.CardFIO;
     return(balance);
 }
Ejemplo n.º 3
0
 public void CreateOrUpdate(BalanceBindingModel model)
 {
     if (model.Id.HasValue)
     {
         _balanceStorage.Update(model);
     }
     else
     {
         _balanceStorage.Insert(model);
     }
 }
Ejemplo n.º 4
0
        public void Delete(BalanceBindingModel model)
        {
            var element = _balanceStorage.GetElement(new BalanceBindingModel
            {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Баланс не найден");
            }
            _balanceStorage.Delete(model);
        }
Ejemplo n.º 5
0
 public void Update(BalanceBindingModel model)
 {
     using (var context = new AdBoardDatabase())
     {
         var element = context.Balance.FirstOrDefault(rec => rec.Id ==
                                                      model.Id);
         if (element == null)
         {
             throw new Exception("Баланс не найден");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 public List <BalanceViewModel> Read(BalanceBindingModel model)
 {
     if (model == null)
     {
         return(_balanceStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <BalanceViewModel> {
             _balanceStorage.GetElement(model)
         });
     }
     return(_balanceStorage.GetFilteredList(model));
 }
Ejemplo n.º 7
0
 public void Delete(BalanceBindingModel model)
 {
     using (var context = new AdBoardDatabase())
     {
         Balance element = context.Balance.FirstOrDefault(rec => rec.Id ==
                                                          model.Id);
         if (element != null)
         {
             context.Balance.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Клиент не найден");
         }
     }
 }
Ejemplo n.º 8
0
 public List <BalanceViewModel> GetFilteredList(BalanceBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AdBoardDatabase())
     {
         return(context.Balance
                .Select(rec => new BalanceViewModel
         {
             Id = rec.Id,
             CardFIO = rec.CardFIO,
             Username = rec.User.Username,
             CardNumb = rec.CardFIO,
             CardDate = rec.CardFIO,
         })
                .ToList());
     }
 }
Ejemplo n.º 9
0
 public BalanceViewModel GetElement(BalanceBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AdBoardDatabase())
     {
         var user = context.Balance
                    .FirstOrDefault(rec => rec.Id == model.Id);
         return(user != null ?
                new BalanceViewModel
         {
             Id = rec.Id,
             CardFIO = rec.CardFIO,
             Username = rec.User.Username,
             CardNumb = rec.CardFIO,
             CardDate = rec.CardFIO,
         } :
                null);
     }
 }