Ejemplo n.º 1
0
        public ActionResult Index(Models.OrderModel.Ship postback)
        {
            if (this.ModelState.IsValid)
            {
                var currentcart = Models.Cart.Operation.GetCurrentCart();

                var userId = HttpContext.User.Identity.GetUserId();

                using (Models.ShoppingCartEntities db = new Models.ShoppingCartEntities())
                {
                    var order = new Models.Order()
                    {
                        UserId          = userId,
                        RecieverName    = postback.RecieverName,
                        RecieverAddress = postback.RecieverAddress,
                        RecieverPhone   = postback.RecieverPhone
                    };

                    db.Orders.Add(order);
                    db.SaveChanges();

                    var orderDetails = currentcart.ToOrderDetailList(order.Id);

                    db.OrderDetails.AddRange(orderDetails);
                    db.SaveChanges();
                }
                return(Content("訂購成功"));
            }
            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult Edit(Models.Product postback)
        {
            if (this.ModelState.IsValid)
            {
                using (Models.ShoppingCartEntities db = new Models.ShoppingCartEntities())
                {
                    var result = (from product in db.Products where product.Id == postback.Id select product).FirstOrDefault();

                    result.Name           = postback.Name;
                    result.Price          = postback.Price;
                    result.PublishDate    = postback.PublishDate;
                    result.PriceDiscount  = postback.PriceDiscount;
                    result.Quantity       = postback.Quantity;
                    result.StatusSale     = postback.StatusSale;
                    result.StatusShow     = postback.StatusShow;
                    result.CategoryId     = postback.CategoryId;
                    result.DefaultImageId = postback.DefaultImageId;
                    result.Description    = postback.Description;
                    result.ImageUrl       = postback.ImageUrl;

                    db.SaveChanges();

                    TempData["ResultMessage"] = String.Format("商品[{0}]成功編輯", postback.Name);
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                return(View(postback));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(Models.Product postback)
        {
            if (this.ModelState.IsValid)
            {
                using (Models.ShoppingCartEntities db = new Models.ShoppingCartEntities())
                {
                    db.Products.Add(postback);

                    db.SaveChanges();

                    TempData["ResultMessage"] = String.Format("商品[{0}]成功建立 ", postback.Name);

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

            return(View());
        }
Ejemplo n.º 4
0
        public ActionResult Delete(int id)
        {
            using (Models.ShoppingCartEntities db = new Models.ShoppingCartEntities())
            {
                var result = (from product in db.Products where product.Id == id select product).FirstOrDefault();
                if (result != default(Models.Product))
                {
                    db.Products.Remove(result);

                    db.SaveChanges();

                    TempData["ResultMessage"] = String.Format("商品[{0}]成功刪除", result.Name);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    TempData["ResultMessage"] = "指定資料不存在,無法刪除,請重新操作";
                    return(RedirectToAction("Index"));
                }
            }
        }