Exemplo n.º 1
0
        public ActionResult EditDrinkDetail(BuyDMDrinkView Buy, string DetailID)
        {
            int ordid   = Int32.Parse(DetailID);
            var OrderID = db.CreateBuyOrder_Details.Find(ordid);

            //加入超過三樣配料,返回視圖
            int addTot = Models.AnyDMorBuy.GetAddItemInt(Buy).Count;

            if (!ModelState.IsValid || addTot > 3)
            {
                Buy.SizeType = Models.AnyDMorBuy.DrinkSize(OrderID.MenuID, OrderID.DrinkID);
                //到時要寫配料的選擇超過三樣時的返回視圖

                if (addTot > 3)
                {
                    ViewBag.ErrorMessage = "配料最多只能選三樣喔!";
                }
                ViewBag.DetailID = ordid;
                return(View(Buy));
            }

            //更新訂單用明細
            int SizePID = Int32.Parse(Buy.SizeTypeM);
            int SweetID = Models.AnyDMorBuy.GetSweetIceInt(Buy, "sweet");
            int IceID   = Models.AnyDMorBuy.GetSweetIceInt(Buy, "ice");
            int Add01   = Models.AnyDMorBuy.GetOnlyAdditemInt(Buy, 1);
            int Add02   = Models.AnyDMorBuy.GetOnlyAdditemInt(Buy, 2);
            int Add03   = Models.AnyDMorBuy.GetOnlyAdditemInt(Buy, 3);
            int SCount  = Models.AnyDMorBuy.GetSCount(Buy);

            var result = db.Database.ExecuteSqlCommand(@"UPDATE createbuyorder_detail SET SizePID = '" + SizePID + "', SweetID = '" + SweetID + "', IceID = '" + IceID +
                                                       "', Additem01PID = '" + Add01 + "', Additem02PID = '" + Add02 + "', Additem03PID = '" + Add03 + "', Quantity = '" + Buy.Quantity +
                                                       "', SCount = '" + SCount + "' Where DetailID = '" + ordid + "';");

            //釋放資料(若不釋放則有資料會取未更新時的那筆)
            db.Dispose();

            //更新總價格
            NewDrinkDB db2          = new NewDrinkDB();
            var        OrderID2     = db2.CreateBuyOrder_Details.Find(ordid);
            var        TotCount     = db2.CreateBuyOrder_LeaderOrders.Find(OrderID.OrderID);
            var        AllTotCount2 = db2.CreateBuyOrder_Details.Where(m => m.OrderID == TotCount.OrderID);
            int        tot          = 0;

            foreach (var item in AllTotCount2)
            {
                tot = tot + item.SCount;
            }
            TotCount.TotalCount = tot;

            db2.SaveChanges();
            db2.Dispose();
            //返回訂單檢視界面
            return(RedirectToAction("OrderingDetail", "AnyDMorBuy", new { OrderID = OrderID.OrderID.ToString() }));
        }
Exemplo n.º 2
0
        public ActionResult ChangePsd(ChangePsdView chang)
        {
            if (!ModelState.IsValid)
            {
                return(View(chang));
            }
            string UserMail = Helper.GetUserMail();
            int    UserID   = Models.AccountModels.UserID(UserMail);

            //先確認舊密碼是否正確
            AesCryptoServiceProvider aes = new AesCryptoServiceProvider();

            NewDrinkDB db = new NewDrinkDB();

            User   query = db.Users.Find(UserID);
            string Psd   = PasswordUtility.AESDecryptor(query.Password, aes.Key, aes.IV);

            if (Psd != chang.OldPassword)
            {
                ViewBag.Error = "密碼輸入錯誤";
                return(View(chang));
            }

            string NewPsd = PasswordUtility.AESEncryptor(chang.Password, aes.Key, aes.IV);
            var    result = db.Database.ExecuteSqlCommand(@"UPDATE users SET Password = '******', ConfirmPsd = '" + NewPsd + "' Where ID = '" + UserID + "';");

            //關閉連線
            db.Dispose();

            string BuyDrink   = Helper.GetUserBuyDrink();
            string OrderSet   = Helper.GetUserOrderSet();
            string Message    = Helper.GetUserMessage();
            string Callnotice = Helper.GetUserCallnotice();
            string ChangePsd  = Helper.GetUserChangePsd();

            string[] UserLimit = { BuyDrink, OrderSet, Message, Callnotice, ChangePsd };
            ViewBag.UserLimit   = UserLimit;
            TempData["message"] = "success";

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 3
0
 //關閉連線
 protected override void Dispose(bool disposing)
 {
     db.Dispose();
     base.Dispose(disposing);
 }