Exemplo n.º 1
0
        public ActionResult Edit(Models.Product postinfo)
        {
            if (this.ModelState.IsValid)
            {
                using (Models.ItemEntities db = new Models.ItemEntities())
                {
                    var result = (from s in db.Products where s.Id == postinfo.Id select s).FirstOrDefault();
                    result.Name             = postinfo.Name;
                    result.PublishDate      = postinfo.PublishDate;
                    result.Status           = postinfo.Status;
                    result.Price            = postinfo.Price;
                    result.Quantity         = postinfo.Quantity;
                    result.CategoryID       = postinfo.CategoryID;
                    result.Description      = postinfo.Description;
                    result.DefaultImageId   = postinfo.DefaultImageId;
                    result.DefaultImageName = postinfo.DefaultImageName;

                    db.SaveChanges();
                    TempData["ResultMsg"] = string.Format("商品[{0}]成功修改", postinfo.Name);
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                return(View(postinfo));
            }
        }
Exemplo n.º 2
0
        [Authorize] // 登入會員才可留言
        public ActionResult AddComment(int id, string Content)
        {
            var userId = HttpContext.User.Identity.GetUserId();     //取得目前登入使用者Id



            var currentDateTime = DateTime.Now;

            var comment = new Models.ProductCommet()
            {
                ProductId  = id,
                Content    = Content,
                UserId     = userId,
                CreateDate = currentDateTime,
                UserName   = User.Identity.GetUserName()
            };

            using (Models.ItemEntities db = new Models.ItemEntities())
            {
                db.ProductCommets.Add(comment);
                db.SaveChanges();
            }

            return(RedirectToAction("Details", new { id = id }));
        }
Exemplo n.º 3
0
        public ActionResult Index(Models.OrderModel.Ship postback)
        {
            if (this.ModelState.IsValid)
            {
                var currentcart = Models.Cart.Operation.GetCurrentCart();//取得目前購物車


                var userId = HttpContext.User.Identity.GetUserId();//取得登入使用者Id

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

                    db.Orders.Add(order);   //加其入Orders資料表後,儲存變更
                    db.SaveChanges();


                    var orderDetails = currentcart.ToOrderDetailList(order.Id);//取得購物車中OrderDetai物件


                    db.OrderDetails.AddRange(orderDetails);//將其加入OrderDetails資料表後,儲存變更
                    db.SaveChanges();
                }

                var currentCart = Models.Cart.Operation.GetCurrentCart();
                currentCart.ClearCart();
                return(Redirect("/Order/MyOrder"));
            }
            return(View());
        }
Exemplo n.º 4
0
        public ActionResult Creat(Models.Product postinfo)
        {
            if (this.ModelState.IsValid)
            {
                using (Models.ItemEntities db = new Models.ItemEntities())
                {
                    postinfo.DefaultImageName = postinfo.DefaultImageName + ".png";
                    db.Products.Add(postinfo);
                    db.SaveChanges();

                    TempData["ResultMsg"] = string.Format("商品[{0}]成功建立", postinfo.Name);
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.ResultMessage = "資料有誤";

            return(View(postinfo));
        }
Exemplo n.º 5
0
 public ActionResult Delete(int id)
 {
     using (Models.ItemEntities db = new Models.ItemEntities())
     {
         var result = (from s in db.Products where s.Id == id select s).FirstOrDefault();
         if (result != default(Models.Product))  //資料判斷有無
         {
             db.Products.Remove(result);
             db.SaveChanges();
             TempData["ResultMsg"] = string.Format("商品[{0}]成功刪除", result.Name);
             return(RedirectToAction("Index"));
         }
         else
         {
             TempData["ResultMsg"] = "指定資料不存在";
             return(RedirectToAction("Index"));
         }
     }
 }