Beispiel #1
0
 private Payment CreateModel(Payment payment, PaymentBindingModel model)
 {
     payment.Sum       = model.Sum.Value;
     payment.ReserveId = model.ReserveId;
     payment.UserId    = model.UserId;
     return(payment);
 }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Sum,LessonId")] PaymentBindingModel payment)
        {
            if (id != payment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    payment.ClientId = Program.Client.Id;
                    _paymentLogic.CreateOrUpdate(payment);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PaymentExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LessonId"] = new SelectList(_lessonLogic.Read(null), "Id", "LessonName", payment.LessonId);
            return(View(payment));
        }
Beispiel #3
0
 public void CreateOrUpdate(PaymentBindingModel model)
 {
     using (var context = new Database())
     {
         Payment element = model.Id.HasValue ? null : new Payment();
         if (model.Id.HasValue)
         {
             element = context.Payments.FirstOrDefault(rec => rec.Id ==
                                                       model.Id);
             if (element == null)
             {
                 throw new Exception("Элемент не найден");
             }
         }
         else
         {
             element = new Payment();
             context.Payments.Add(element);
         }
         element.EducationId = model.EducationId;
         element.ClientId    = model.ClientId;
         element.Sum         = model.Sum;
         element.DatePayment = model.DatePayment;
         context.SaveChanges();
     }
 }
        public void Update(PaymentBindingModel model)
        {
            using (var context = new SchoolDataBase())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var payment = context.Payments.FirstOrDefault(rec => rec.Id == model.Id);

                        if (payment == null)
                        {
                            throw new Exception("Кружок не найден");
                        }

                        CreateModel(model, payment);
                        context.SaveChanges();

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
        public void CreateOrUpdate(PaymentBindingModel model)
        {
            using (var context = new ElectronicsShopDatabase())
            {
                Payment tempPayment = model.Id.HasValue ? null : new Payment();

                if (model.Id.HasValue)
                {
                    tempPayment = context.Payments.FirstOrDefault(rec => rec.Id == model.Id);
                }

                if (model.Id.HasValue)
                {
                    if (tempPayment == null)
                    {
                        throw new Exception("Элемент не найден");
                    }

                    CreateModel(model, tempPayment);
                }
                else
                {
                    context.Payments.Add(CreateModel(model, tempPayment));
                }

                context.SaveChanges();
            }
        }
 public void CreateOrUpdate(PaymentBindingModel model)
 {
     using (var context = new TravelAgencyDatabase())
     {
         Payment element = context.Payments.FirstOrDefault(rec => rec.Id != model.Id);
         if (element != null)
         {
             throw new Exception("Уже есть платеж  с таким названием");
         }
         if (model.Id.HasValue)
         {
             element = context.Payments.FirstOrDefault(rec => rec.Id ==
                                                       model.Id);
             if (element == null)
             {
                 throw new Exception("Элемент не найден");
             }
         }
         else
         {
             element = new Payment();
             context.Payments.Add(element);
         }
         element.TravelId    = model.TravelId;
         element.ClientId    = model.ClientId;
         element.Sum         = model.Sum;
         element.DatePayment = model.DatePayment;
         context.SaveChanges();
     }
 }
 public void CreateOrUpdate(PaymentBindingModel model)
 {
     using (var context = new FurnitureFactoryDatabase())
     {
         Payment element = model.Id.HasValue ? null : new Payment();
         if (model.Id.HasValue)
         {
             element = context.Payments.FirstOrDefault(rec => rec.Id == model.Id);
             if (element == null)
             {
                 throw new Exception("Элемент не найден");
             }
         }
         else
         {
             element = new Payment();
             context.Payments.Add(element);
         }
         element.OrderId       = model.OrderId;
         element.ClientId      = model.ClientId;
         element.PaymentAmount = model.PaymentAmount;
         element.PaymentDate   = model.PaymentDate;
         context.SaveChanges();
     }
 }
 private Payment CreateModel(PaymentBindingModel model, Payment payment)
 {
     payment.LessonId    = model.LessonId;
     payment.Sum         = model.Sum;
     payment.PaymentDate = model.PaymentDate;
     payment.ClientId    = model.ClientId;
     return(payment);
 }
Beispiel #9
0
 private Payment CreateModel(PaymentBindingModel model, Payment payment)
 {
     payment.ClientId      = model.ClientId;
     payment.WorkId        = (int)model.WorkId;
     payment.Sum           = model.Sum;
     payment.DateOfPayment = model.DateOfPayment;
     return(payment);
 }
Beispiel #10
0
 public void Insert(PaymentBindingModel model)
 {
     using (var context = new UrskiyPeriodDatabase())
     {
         context.Payment.Add(CreateModel(new Payment(), model));
         context.SaveChanges();
     }
 }
Beispiel #11
0
 public void Insert(PaymentBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         context.Payments.Add(CreateModel(model, new Payment()));
         context.SaveChanges();
     }
 }
        public IHttpActionResult CreatePayment(PaymentBindingModel formData)
        {
            if (formData == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var Ccb = DbContext
                      .CreditCardBrands
                      .FirstOrDefault(p => p.Id == formData.CreditCardBrandId);

            if (Ccb == null)
            {
                ModelState.AddModelError("CreditCardBrandId",
                                         "This is not valid. No record in the system.");
                return(BadRequest(ModelState));
            }

            if (formData.Amount <= 0)
            {
                ModelState.AddModelError("Amount",
                                         "It must be greater than 0.");
                return(BadRequest(ModelState));
            }

            if (!formData.SecurityCode.All(char.IsDigit))
            {
                ModelState.AddModelError("SecurityCode",
                                         "It must be a number");
                return(BadRequest(ModelState));
            }


            var payment = Mapper.Map <Payment>(formData);

            RejectPaymentLottery(payment);

            DbContext.Payments.Add(payment);
            DbContext.SaveChanges();

            if (payment.IsRejected)
            {
                ModelState.AddModelError("Status",
                                         "Sorry. Payment is rejected.");
                return(BadRequest(ModelState));
            }

            var viewModel = Mapper.Map <PaymentViewModel>(payment);

            return(Ok(viewModel));
        }
Beispiel #13
0
 public IActionResult Index([Bind("ReserveId", "Sum")] PaymentBindingModel model, decimal reserveSum)
 {
     if (reserveSum < model.Sum)
     {
         throw new Exception("Внесённая сумма не должна быть больше, чем сумма к оплате");
     }
     model.UserId = Program.User.Id;
     APIUser.PostRequest("api/payment/Pay", model);
     return(Redirect("~/Home/Index"));
 }
Beispiel #14
0
 public List <PaymentViewModel> Read(PaymentBindingModel model)
 {
     if (model.Id.HasValue)
     {
         return(new List <PaymentViewModel> {
             _paymentStorage.GetElement(model)
         });
     }
     return(_paymentStorage.GetFullList());
 }
Beispiel #15
0
 public void CreateOrUpdate(PaymentBindingModel model)
 {
     if (model.Id.HasValue)
     {
         _paymentStorage.Update(model);
     }
     else
     {
         _paymentStorage.Insert(model);
     }
 }
Beispiel #16
0
 public List <PaymentViewModel> GetFilteredList(PaymentBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new UrskiyPeriodDatabase())
     {
         return(context.Payment.Where(rec => rec.Sum == model.Sum).Select(CreateModel).ToList());
     }
 }
Beispiel #17
0
 public async Task <IActionResult> Create([Bind("Sum,LessonId")] PaymentBindingModel payment)
 {
     if (ModelState.IsValid)
     {
         payment.ClientId = Program.Client.Id;
         _paymentLogic.CreateOrUpdate(payment);
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["LessonId"] = new SelectList(_lessonLogic.Read(null), "Id", "LessonName", payment.LessonId);
     return(View(payment));
 }
Beispiel #18
0
 public PaymentViewModel GetElement(PaymentBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new UrskiyPeriodDatabase())
     {
         var route = context.Payment.FirstOrDefault(rec => rec.Id == model.Id);
         return(route != null?CreateModel(route) : null);
     }
 }
Beispiel #19
0
 public void Delete(PaymentBindingModel model)
 {
     using (var context = new UrskiyPeriodDatabase())
     {
         var user = context.Payment.FirstOrDefault(rec => rec.Id == model.Id);
         if (user == null)
         {
             throw new Exception("Не найдено");
         }
         context.Payment.Remove(user);
         context.SaveChanges();
     }
 }
Beispiel #20
0
 public void Update(PaymentBindingModel model)
 {
     using (var context = new UrskiyPeriodDatabase())
     {
         var payment = context.Payment.FirstOrDefault(rec => rec.Id == model.Id);
         if (payment == null)
         {
             throw new Exception("Не найдено");
         }
         CreateModel(payment, model);
         context.SaveChanges();
     }
 }
Beispiel #21
0
 public void Update(PaymentBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         var element = context.Payments.FirstOrDefault(rec => rec.Id == model.Id);
         if (element == null)
         {
             throw new Exception("Оплата не найдена");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
        private Payment CreateModel(PaymentBindingModel model, Payment payment)
        {
            using (var context = new ElectronicsShopDatabase())
            {
                payment.OrderId  = model.OrderId;
                payment.ClientId = model.ClientId;
                payment.Account  = model.Account;
                payment.Date     = model.Date;
                payment.Sum      = model.Sum;

                return(payment);
            }
        }
Beispiel #23
0
        public void Delete(PaymentBindingModel model)
        {
            var element = _paymentStorage.GetElement(new PaymentBindingModel
            {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Не найдено");
            }
            _paymentStorage.Delete(model);
        }
Beispiel #24
0
 public List <PaymentViewModel> Read(PaymentBindingModel model)
 {
     if (model == null || model.ClientId != null)
     {
         return(_paymentStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <PaymentViewModel> {
             _paymentStorage.GetElement(model)
         });
     }
     return(_paymentStorage.GetFilteredList(model));
 }
Beispiel #25
0
 public List <PaymentViewModel> GetFilteredList(PaymentBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new CTODatabase())
     {
         return(context.Payments.Where(rec => rec.Id == model.Id).Include(rec => rec.Client)
                .Include(rec => rec.Work)
                .Select(CreateViewModel)
                .ToList());
     }
 }
        //public void CreateOrUpdate(CreatePaymentBindingModel model)
        //{
        //    var payment = new PaymentBindingModel
        //    {
        //        Id = model.Id,
        //        Prepayment = model.Prepayment,
        //        ClientId = model.ClientId,
        //        DishId = model.DishId,
        //        DateCreate = model.DateCreate
        //    };

        //    if (model.Id.HasValue)
        //    {
        //        paymentStorage.Update(payment);
        //    }
        //    else
        //    {
        //        paymentStorage.Insert(payment);
        //    }
        //}

        public void Delete(PaymentBindingModel model)
        {
            var payment = paymentStorage.GetElement(
                new PaymentBindingModel
            {
                Id = model.Id
            });

            if (payment == null)
            {
                throw new Exception("Оплата не внесена");
            }

            paymentStorage.Delete(model);
        }
        public void Delete(PaymentBindingModel model)
        {
            using (var context = new SchoolDataBase())
            {
                var payment = context.Payments.FirstOrDefault(rec => rec.Id == model.Id);

                if (payment == null)
                {
                    throw new Exception("Кружок не найден");
                }

                context.Payments.Remove(payment);
                context.SaveChanges();
            }
        }
Beispiel #28
0
 public void Delete(PaymentBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         Payment element = context.Payments.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Payments.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Оплата не найдена");
         }
     }
 }
Beispiel #29
0
 public void Delete(PaymentBindingModel model)
 {
     using (var context = new ComputerRepairDatabase())
     {
         var element = context.Payment.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Payment.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Элемент не найден");
         }
     }
 }
Beispiel #30
0
 public List <PaymentViewModel> Read(PaymentBindingModel model)
 {
     using (var context = new Database())
     {
         return(context.Payments
                .Where(rec => model == null || rec.Id == model.Id || rec.EducationId.Equals(model.EducationId))
                .Select(rec => new PaymentViewModel
         {
             Id = rec.Id,
             ClientId = rec.ClientId,
             DatePayment = rec.DatePayment,
             EducationId = rec.EducationId,
             Sum = rec.Sum
         })
                .ToList());
     }
 }