예제 #1
0
        public ActionResult Create(CartCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service        = CreateCartService();
            var productService = CreateProductService();

            productService.GetProductById(model.ProductId);



            if (service.CreateCart(model))
            {
                TempData["SaveResult"] = "Your cart is up to date!";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Cart could not be updated.");

            return(View(model));
        }
예제 #2
0
        public bool AddToCart(BookDetail book)
        {
            CartCreate cartCreate = new CartCreate()
            {
                BookId    = book.BookId,
                Title     = book.Title,
                Price     = book.Price,
                Quantity  = 1,
                ItemTotal = 1,
                OwnerId   = _userId
            };

            return(CreateCart(cartCreate));
        }
예제 #3
0
        //Not Real World Usage
        //[Route("api/cart/purchase")]
        //public IHttpActionResult GetCartByPurchaseDate([FromBody]  DateTime date)
        //{
        //    CartService cartService = CreateCartService();
        //    var cart = cartService.GetCartByPurchaseDate(date);
        //    return Ok(cart);
        //}
        public IHttpActionResult Post(CartCreate cart)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            CartService cartService = CreateCartService();

            if (!cartService.CreateCart(cart))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
예제 #4
0
        public bool CreateCart(CartCreate model)
        {
            var entity =
                new Cart()
            {
                PlantId = model.PlantId,
                OwnerId = _userId,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Carts.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #5
0
        public bool CreateCart(CartCreate model)
        {
            var entity = new Cart()
            {
                CartUser     = _cartId,
                GiftBoxId    = model.GiftBoxId,
                ItemCount    = model.ItemCount,
                PurchaseDate = DateTime.Now,
                CustomerId   = model.CustomerId,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Carts.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #6
0
 public bool CreateCart(CartCreate model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var cart = new Cart()
         {
             OwnerId   = _userId,
             CartId    = model.CartId,
             BookId    = model.BookId,
             Quantity  = model.Quantity,
             Price     = model.Price,
             ItemTotal = model.ItemTotal
         };
         cart.ItemTotal = cart.Price * Convert.ToDecimal(model.Quantity);
         ctx.Cart.Add(cart);
         return(ctx.SaveChanges() == 1);
     }
 }
예제 #7
0
        public ActionResult Create(CartCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            CartService service = CreateCartService();

            if (service.CreateCart(model))
            {
                TempData["SaveResult"] = "Your cart has been successully updated.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "An error was encountered. Your cart was not updated.");
            return(View(model));
        }
예제 #8
0
        public ActionResult Create(CartCreate model)
        {
            if (ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateCartService();

            if (service.CreateCart(model))
            {
                TempData["SaveResult"] = "Your cart was created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Cart could not be created.");

            return(View(model));
        }