Ejemplo n.º 1
0
 public void CreateOrUpdate(DepositBindingModel model)
 {
     using (var context = new BankDatabase())
     {
         Deposit element = context.Deposits.FirstOrDefault(rec =>
                                                           rec.ClientFIO == model.ClientFIO && rec.Id != model.Id);
         if (element != null)
         {
             throw new Exception("Уже есть вклад с таким именем");
         }
         if (model.Id.HasValue)
         {
             element = context.Deposits.FirstOrDefault(rec => rec.Id ==
                                                       model.Id);
             if (element == null)
             {
                 throw new Exception("Элемент не найден");
             }
         }
         else
         {
             element = new Deposit();
             context.Deposits.Add(element);
         }
         element.ClientFIO   = model.ClientFIO;
         element.SizeDeposit = model.SizeDeposit;
         element.Email       = model.Email;
         element.DateOpened  = model.DateOpened;
         element.TypeValue   = model.TypeValue;
         context.SaveChanges();
     }
 }
Ejemplo n.º 2
0
 public void Delete(DepositBindingModel model)
 {
     using (var context = new BankDatabase())
     {
         Deposit element = context.Deposits.FirstOrDefault(rec => rec.Id ==
                                                           model.Id);
         if (element != null)
         {
             context.Deposits.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Элемент не найден");
         }
     }
 }
Ejemplo n.º 3
0
 // POST api/deposit
 public IHttpActionResult Post([FromBody] DepositBindingModel depositModel)
 {
     try
     {
         var deposit = Mapper.Map <DomainDeposit>(depositModel);
         _depositService.Add(deposit);
         return(Ok());
     }
     catch (BankClientException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Ejemplo n.º 4
0
 public List <DepositViewModel> Read(DepositBindingModel model)
 {
     using (var context = new BankDatabase())
     {
         return(context.Deposits
                .Where(rec => model == null || rec.Id == model.Id || (model.DateFrom.HasValue && model.DateTo.HasValue && rec.Bank.DateCreate >= model.DateFrom && rec.Bank.DateCreate <= model.DateTo))
                .Select(rec => new DepositViewModel
         {
             Id = rec.Id,
             ClientFIO = rec.ClientFIO,
             Email = rec.Email,
             BankId = rec.BankId,
             TypeValue = rec.TypeValue,
             DateOpened = rec.Bank.DateCreate,
             Name = rec.Bank.Name,
         })
                .ToList());
     }
 }