Exemple #1
0
        public ActionResult PlayerCreate(Player player, string passwordConfirm, int CityID, HttpPostedFileBase photo)
        {
            //檢查確認密碼是否輸入正確
            if (passwordConfirm != player.Password)
            {
                ModelState["Password"].Errors.Add("輸入的密碼和確認密碼不相符");
            }
            //檢查帳號是否重複
            if (db.Players.Any(m => m.Account == player.Account))
            {
                ModelState["Account"].Errors.Add("此帳號已經有人使用");
            }
            //檢查帳號及密碼是否符合規則
            UsefulTools.RegisterValidate(player.Account, ModelState["Account"].Errors.Add, false, false);
            UsefulTools.RegisterValidate(player.Password, ModelState["Password"].Errors.Add, true, false);
            //填入預設值
            player.ID           = UsefulTools.GetNextID(db.Players, 2);
            player.Points       = 0;
            player.IsBanned     = false;
            player.IsEmailValid = false;

            if (ModelState.IsValid)
            {
                player.Password = Hash.PwdHash(player.Password);
                db.Players.Add(player);
                db.SaveChanges();
                //儲存圖片(先將photo變為陣列再傳入)
                PhotoManager.Create(player.ID, new HttpPostedFileBase[] { photo });

                return(RedirectToAction("EmailValidate", "EmailValidate", new { Email = player.Email, id = player.ID }));
            }
            ViewBag.CityID     = new SelectList(db.Cities, "ID", "CityName", CityID);
            ViewBag.DistrictID = new SelectList(db.Districts, "ID", "DistrictName", player.DistrictID);
            return(View(player));
        }
Exemple #2
0
        public ActionResult MgShopCreate(Shop shop, HttpPostedFileBase[] photos)
        {
            //檢查帳號是否重複
            if (db.Shops.Any(m => m.Account == shop.Account))
            {
                ModelState["Account"].Errors.Add("此帳號已經有人使用");
            }
            //驗證帳號密碼是否符合規則
            UsefulTools.RegisterValidate(shop.Account, ModelState["Account"].Errors.Add, false, false);
            UsefulTools.RegisterValidate(shop.Password, ModelState["Password"].Errors.Add, true, true);

            if (ModelState.IsValid)
            {
                //填入必要資料
                shop.ID               = UsefulTools.GetNextID(db.Shops, 1);
                shop.Password         = Hash.PwdHash(shop.Password);
                shop.AccumulatedHours = 0;
                db.Shops.Add(shop);
                db.SaveChanges();

                //添加圖片
                PhotoManager.Create(shop.ID, photos);

                return(RedirectToAction("ShopIndex"));
            }
            ViewBag.DistrictID = new SelectList(db.Districts, "ID", "DistrictName");
            ViewBag.CityID     = new SelectList(db.Cities, "ID", "CityName", db.Districts.Find(shop.DistrictID).CityID);
            ViewBag.AreaScale  = new SelectList(new[]
            {
                new { Option = "大" },
                new { Option = "中" },
                new { Option = "小" }
            }, "Option", "Option");
            return(View(shop));
        }
Exemple #3
0
        public ActionResult ShopEditForStore(Shop shop, int[] deletedPhotoID, HttpPostedFileBase[] newPhoto)
        {
            Shop s = db.Shops.Find((string)TempData["Shop_ID"]);

            //清除ModelState中的錯誤以免無法通過
            List <string> exceptions = new List <string> {
                "Account", "Password"
            };

            exceptions.ForEach(m => ModelState[m].Errors.Clear());

            if (ModelState.IsValid)
            {
                //取得原始檔案並將必要資料存入
                shop.ID               = s.ID;
                shop.Account          = s.Account;
                shop.Password         = s.Password;
                shop.IsVIP            = s.IsVIP;
                shop.ExpireDate       = s.ExpireDate;
                shop.AccumulatedHours = s.AccumulatedHours;

                //取消追蹤變量s,以免儲存時發生錯誤
                db.Entry(s).State    = EntityState.Detached;
                db.Entry(shop).State = EntityState.Modified;
                db.SaveChanges();

                //刪除被勾選的圖片
                if (deletedPhotoID != null)
                {
                    foreach (int id in deletedPhotoID)
                    {
                        PhotoManager.Delete(id);
                    }
                }
                //加入新圖片
                PhotoManager.Create(shop.ID, newPhoto);

                return(RedirectToAction("ShopDetailForStore"));
            }
            ViewBag.CityID      = new SelectList(db.Cities, "ID", "CityName", s.District.CityID);
            ViewBag.DistrictID  = new SelectList(db.Districts, "ID", "DistrictName", s.DistrictID);
            ViewBag.photoIDList = PhotoManager.GetPhotoIDList(s.ID);
            TempData.Keep("Shop_ID");
            ViewBag.AreaScale = new SelectList(new List <SelectListItem> {
                new SelectListItem {
                    Text = "大", Value = "大"
                },
                new SelectListItem {
                    Text = "中", Value = "中"
                },
                new SelectListItem {
                    Text = "小", Value = "小"
                }
            }, "Value", "Text", shop.AreaScale);
            return(View(shop));
        }
Exemple #4
0
        public ActionResult ChangePlayerPhoto(HttpPostedFileBase[] photo)
        {
            string playerID = (string)Session["PlayerID"];

            //若登入時間已過則跳轉至登入頁
            if (playerID == null)
            {
                return(RedirectToAction("LoginForPlayer", "Login"));
            }
            if (photo.Length != 0)
            {
                //先刪除原先圖片再新增圖片
                PhotoManager.Delete(playerID);
                PhotoManager.Create(playerID, photo);
            }
            return(RedirectToAction("PlayerDetail"));
        }
        public ActionResult OfferCreate(NormalOffer normalOffer, HttpPostedFileBase[] photos)
        {
            OfferTimeCheck(normalOffer);
            if (ModelState.IsValid)
            {
                //填入預設值
                normalOffer.ID     = UsefulTools.GetNextID(db.NormalOffers, 1);
                normalOffer.ShopID = Session["ShopID"].ToString();
                normalOffer.Clicks = 0;

                db.NormalOffers.Add(normalOffer);
                db.SaveChanges();
                //存入圖片
                PhotoManager.Create(normalOffer.ID, photos);
                return(RedirectToAction("OfferListForShop"));
            }
            return(View());
        }
Exemple #6
0
        public ActionResult CouponCreate(Coupon coupon, HttpPostedFileBase[] photos)
        {
            //填入預設值
            coupon.ID          = UsefulTools.GetNextID(db.Coupons, 1);
            coupon.ShopID      = (string)Session["ShopID"];
            coupon.IsAvailable = false;

            CouponCheck(coupon);
            if (ModelState.IsValid)
            {
                db.Coupons.Add(coupon);
                db.SaveChanges();

                //加入照片
                PhotoManager.Create(coupon.ID, photos);
                return(RedirectToAction("CouponIndexForShop"));
            }
            return(View());
        }
        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());
        }
Exemple #8
0
        public ActionResult CreateTableGame(TableGame newTableGame, string[] selectedCategories, HttpPostedFileBase[] photos, string[] links)
        {
            //無法通過驗證則顯示錯誤訊息
            if (!ModelState.IsValid)
            {
                UpdateTableGamePreparaion();
                return(View());
            }
            //儲存newTableGame
            newTableGame.ID = UsefulTools.GetNextID(db.TableGames, 1);
            db.TableGames.Add(newTableGame);
            db.SaveChanges();
            foreach (string sc in selectedCategories)
            {
                newTableGame.GameCategoryTags.Add(db.Tags.Find(sc));
                db.SaveChanges();
            }
            //調用PhotoManager中的方法來儲存傳入的圖片
            PhotoManager.Create(newTableGame.ID, photos);
            //儲存相關教學連結
            RelevantLinkManager.Create(newTableGame.ID, links);

            return(RedirectToAction("ShowTableGameListForAdmin"));
        }
Exemple #9
0
        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));
        }
Exemple #10
0
        public ActionResult EditTableGame(TableGame tableGame, string[] selectedCategories,
                                          int[] deletedPhotoID, HttpPostedFileBase[] newPhoto, int[] deletedLinkIDs, string[] links)
        {
            //無法通過驗證則顯示錯誤訊息
            if (!ModelState.IsValid)
            {
                UpdateTableGamePreparaion();
                //將圖片的ID的List傳入ViewBag
                ViewBag.photoIDList = PhotoManager.GetPhotoIDList(tableGame.ID);
                return(View(db.TableGames.Find(tableGame.ID)));
            }
            tableGame.ID = (string)TempData["TableGame_ID"];
            //通過ID找到舊的tableGame資料
            TableGame oldTableGame = db.TableGames.Find(tableGame.ID);

            //使用自訂方法更新
            UsefulTools.Update(oldTableGame, tableGame);
            db.SaveChanges();

            //通過selectedCategories解析出對應的Tags並加入newTagList
            List <Tag> newTagList = new List <Tag>();

            foreach (string sc in selectedCategories)
            {
                Tag t = db.Tags.Find(sc);
                newTagList.Add(t);
            }
            //全部的GameCategoryTag
            List <Tag> allTagList = db.Tags.Where(t => t.ID.Substring(0, 1) == "C").ToList();

            //遍歷所有GameCategoryTag
            foreach (Tag t in allTagList)
            {
                if (oldTableGame.GameCategoryTags.Contains(t))
                {
                    //這個GameCategoryTag有在這個桌遊的GameCategoryTags之中
                    //進一步判斷是否有在newTagList中,如果沒有就從這個桌遊的GameCategoryTags刪除
                    if (!newTagList.Contains(t))
                    {
                        oldTableGame.GameCategoryTags.Remove(t);
                        db.SaveChanges();
                    }
                }
                else
                {
                    //這個GameCategoryTag不在這個桌遊的GameCategoryTags之中
                    //進一步判斷是否有在newTagList中,如果有就加入這個桌遊的GameCategoryTags
                    if (newTagList.Contains(t))
                    {
                        oldTableGame.GameCategoryTags.Add(t);
                        db.SaveChanges();
                    }
                }
            }

            //刪除被勾選的圖片
            if (deletedPhotoID != null)
            {
                foreach (int id in deletedPhotoID)
                {
                    PhotoManager.Delete(id);
                }
            }
            //加入新圖片
            PhotoManager.Create(tableGame.ID, newPhoto);
            //刪除連結
            if (deletedLinkIDs != null)
            {
                RelevantLinkManager.Delete(deletedLinkIDs);
            }
            //加入新連結
            RelevantLinkManager.Create(tableGame.ID, links);

            return(RedirectToAction("ShowTableGameListForAdmin"));
        }
Exemple #11
0
 public ActionResult CreateDefaultPhoto(string sourceID, HttpPostedFileBase[] photos)
 {
     PhotoManager.Create(sourceID, photos);
     return(Content("success"));
 }