Ejemplo n.º 1
0
        public ActionResult Payment(PaymentModel model)
        {
            ReceptionViewModel reception = _reception.Read(new ReceptionBindingModel
            {
                Id = model.ReceptionId
            }).FirstOrDefault();
            int leftSum = CalculateLeftSum(reception);

            if (!ModelState.IsValid)
            {
                ViewBag.Reception = reception;
                ViewBag.LeftSum   = leftSum;
                return(View(model));
            }
            if (leftSum < model.Sum)
            {
                ViewBag.Reception = reception;
                ViewBag.LeftSum   = leftSum;
                return(View(model));
            }
            _payment.CreateOrUpdate(new PaymentBindingModel
            {
                ReceptionId = reception.Id,
                ClientId    = Program.Client.Id,
                DatePayment = DateTime.Now,
                Sum         = model.Sum
            });
            leftSum -= model.Sum;
            _reception.CreateOrUpdate(new ReceptionBindingModel
            {
                Id                = reception.Id,
                ClientId          = reception.ClientId,
                DateCreate        = reception.DateCreate,
                ReceptionStatus   = leftSum > 0 ? ReceptionStatus.ОплаченЧастично : ReceptionStatus.Оплачен,
                TotalSum          = reception.TotalSum,
                ReceptionServices = reception.ReceptionServices.Select(rec => new ReceptionServiceBindingModel
                {
                    Id          = rec.Id,
                    ReceptionId = rec.ReceptionId,
                    ServiceId   = rec.ServiceId,
                    Count       = rec.Count
                }).ToList()
            });
            return(RedirectToAction("Reception"));
        }