public ActionResult MgShopEdit(Shop shop) { //移除不能修改部分的ModelState錯誤 List <string> exceptions = new List <string> { "ID", "Account", "Password", "ShopName", "OpeningHours", "Address", "AreaScale", "Tel" }; exceptions.ForEach(m => ModelState[m].Errors.Clear()); if (ModelState.IsValid) { //找到原始店家資料並修改變動項目 Shop s = db.Shops.Find((string)TempData["Shop_ID"]); s.IsVIP = shop.IsVIP; s.ExpireDate = shop.ExpireDate; s.AccumulatedHours = shop.AccumulatedHours; s.IsAccountEnabled = shop.IsAccountEnabled; db.Entry(s).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("ShopIndex")); } return(View(shop)); }
public ActionResult PlayerEdit(Player player, int CityID, int DistrictID) { //從TempData中取出原始資料並存入 Player p = (Player)TempData["Player"]; player.ID = p.ID; player.Account = p.Account; player.Password = p.Password; player.NickName = p.NickName; //將帳號相關檢查移除以免觸發錯誤 List <string> exceptions = new List <string> { "Account", "Password", "NickName" }; exceptions.ForEach(m => ModelState[m].Errors.Clear()); if (ModelState.IsValid) { db.Entry(player).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("PlayerIndex")); } ViewBag.CityID = new SelectList(db.Cities, "ID", "CityName", CityID); ViewBag.DistrictID = new SelectList(db.Districts, "ID", "DistrictName", DistrictID); ViewBag.Gender = new SelectList(new SelectListItem[] { new SelectListItem { Text = "男", Value = "true" }, new SelectListItem { Text = "女", Value = "false" } }, "Value", "Text"); TempData.Keep("Player_ID"); return(View(player)); }
public ActionResult OfferEdit(NormalOffer normalOffer, HttpPostedFileBase[] photos, int[] deletedPhotoID) { OfferTimeCheck(normalOffer); NormalOffer offer = (NormalOffer)TempData["Offer"]; if (ModelState.IsValid) { //取出原始資料並灌入必要資料 normalOffer.ID = offer.ID; normalOffer.ShopID = offer.ShopID; normalOffer.Clicks = offer.Clicks; db.Entry(normalOffer).State = EntityState.Modified; db.SaveChanges(); //存入圖片 PhotoManager.Create(normalOffer.ID, photos); //刪除圖片 PhotoManager.Delete(deletedPhotoID); return(RedirectToAction("OfferListForShop")); } ViewBag.photoIDList = PhotoManager.GetPhotoIDList(offer.ID); TempData.Keep("Offer"); return(View()); }
public ActionResult CouponEdit(Coupon coupon, HttpPostedFileBase[] photos, int[] deletedPhotoID) { //從TempData取出原始資料並存入必要欄位 Coupon c = (Coupon)TempData["Coupon"]; coupon.ID = c.ID; coupon.ShopID = c.ShopID; //優惠券只要有修改過就必須再經審核 coupon.IsAvailable = false; CouponCheck(coupon); if (ModelState.IsValid) { db.Entry(coupon).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); //加入及刪除照片 PhotoManager.Create(coupon.ID, photos); PhotoManager.Delete(deletedPhotoID); return(RedirectToAction("CouponIndexForShop")); } ViewBag.photoIDList = PhotoManager.GetPhotoIDList(coupon.ID); TempData.Keep(); return(View(coupon)); }