Пример #1
0
        public ViewResult Checkout(Cart cart, DeliveryDTO deliveryDto)
        {
            if (cart.Lines.Count() == 0)
            {
                ModelState.AddModelError("", "Извините, ваша корзина пуста!");
            }

            if (ModelState.IsValid)
            {
                //todo: refactor
                var userId = User.Identity.GetUserId();
                var client = _clientLogic.Get(userId);

                foreach (var item in cart.Lines)
                {
                    var good = _goodLogic.Get(item.Good.Id);
                    if (good.Count >= item.Number)
                    {
                        good.Count     -= item.Number;
                        good.OrderItems = null;
                        _goodLogic.Edit(good);
                    }
                    else
                    {
                        return(View("GoodIsOver"));
                    }
                }

                _orderLogic.ProcessOrder(cart, deliveryDto, client);
                cart.Clear();

                return(View("Completed"));
            }
            return(View(deliveryDto));
        }
Пример #2
0
        public ActionResult Edit(GoodEditModel goodEditModel, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                goodEditModel.Date = DateTime.Now;

                Mapper.CreateMap <GoodEditModel, GoodDTO>()
                .ForMember("Category",
                           opt => opt.MapFrom(v => _categoryLogic.Get(v.CategoryId)))
                .ForMember("Color",
                           opt => opt.MapFrom(v => _colorLogic.Get(v.ColorId)));

                var good = Mapper.Map <GoodEditModel, GoodDTO>(goodEditModel);
                good.OrderItems = _goodLogic.Get(goodEditModel.Id).OrderItems;
                if (upload != null && upload.ContentLength > 0)
                {
                    good.ImageType = upload.ContentType;

                    using (var reader = new BinaryReader(upload.InputStream))
                    {
                        good.Image = reader.ReadBytes(upload.ContentLength);
                    }
                }

                _goodLogic.Edit(good);

                return(RedirectToAction("Index"));
            }
            return(View(goodEditModel));
        }