Exemplo 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.mainEntities db = new Models.mainEntities())
                {
                    //Order object
                    var order = new Models.Order()
                    {
                        UserId          = UserId,
                        RecieverName    = postback.ReceiverName,
                        RecieverPhone   = postback.ReceiverPhone,
                        RecieverAddress = postback.ReceiverAddress
                    };
                    //Add data table
                    db.OrderSet.Add(order);
                    db.SaveChanges();

                    //Get OrderDetail Object
                    var orderDetails = currentcart.ToOrderDetailList(order.Id);
                    // insert to order datatable
                    db.OrderDetailSet.AddRange(orderDetails);
                    db.SaveChanges();
                }
                return(Content("訂購成功!"));
            }
            return(View());
        }
Exemplo n.º 2
0
        public ActionResult Edit(Models.Product postback)
        {
            if (this.ModelState.IsValid)
            {
                using (main.Models.mainEntities db = new Models.mainEntities())
                {
                    var result = (from s in db.Products where s.Id == postback.Id select s).FirstOrDefault();
                    //Revise Data
                    result.Name           = postback.Name;
                    result.Price          = postback.Price;
                    result.PublishDate    = postback.PublishDate;
                    result.Quantity       = postback.Quantity;
                    result.Status         = postback.Status;
                    result.CategoryId     = postback.CategoryId;
                    result.DefaultImageId = postback.DefaultImageId;
                    result.Description    = postback.Description;

                    //save data which changed
                    db.SaveChanges();

                    //retuen message
                    TempData["ResultMessage"] = String.Format("成功編輯");
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                return(View(postback));
            }
        }
Exemplo n.º 3
0
 public ActionResult Create(Models.Product postback)
 {
     if (this.ModelState.IsValid)
     {
         using (Models.mainEntities db = new Models.mainEntities())
         {
             db.Products.Add(postback);
             db.SaveChanges();
             //Success Message
             TempData["ResultMessage"] = String.Format("商品[{0}]建立成功", postback.Name);
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         ViewBag.ResultMessage = "資料有誤";
         return(View());
     }
 }
 public ActionResult Delete(int id)
 {
     using (Models.mainEntities db = new Models.mainEntities())
     {
         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["resultMessage"] = String.Format("商品[{0}]已刪除", result.Name);
             return(RedirectToAction("Index"));
         }
         else
         {
             TempData["resultMessage"] = String.Format("沒有找到指定商品,無法刪除");
             return(RedirectToAction("Index"));
         }
     }
 }