Exemplo n.º 1
0
        public void AddOrder(CheckoutBm bm)
        {
            Order order = new Order
            {
                DataAdded   = DateTime.Now,
                Adress      = bm.Adress,
                Email       = bm.Email,
                Name        = bm.Name,
                PhoneNumber = bm.PhoneNumber,
                SumTotal    = bm.SumTotal
            };

            foreach (var productId in bm.ProductId)
            {
                Product prod = this.Context.Products.Find(productId);
                order.Products.Add(prod);
            }
            this.Context.Orders.Add(order);
            this.Context.SaveChanges();
        }
Exemplo n.º 2
0
        public ActionResult SimpleCheckout(CheckoutBm bm)
        {
            var  strCurrentUserId = User.Identity.GetUserId();
            Cart currnetCart      = this.service.GetCart(strCurrentUserId);

            if (this.ModelState.IsValid)
            {
                try
                {
                    this.service.AddOrder(bm);
                    this.service.ClearCart(currnetCart);
                    return(RedirectToAction("Success"));
                }
                catch (DbEntityValidationException ex)
                {
                    var error = ex.EntityValidationErrors.First().ValidationErrors.First();
                    this.ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                }
            }
            return(this.View(currnetCart));
        }