Beispiel #1
0
        public IHttpActionResult Delete(int id)
        {
            var userId = Request.GetUserId();

            if (userId < 0)
            {
                return(Unauthorized());
            }

            var photo = _photoManager.GetById(id);

            if (photo == null)
            {
                return(NotFound());
            }

            if (_authManager.HasAccess(userId, photo, Operation.Delete))
            {
                return(Unauthorized());
            }

            _photoManager.Delete(photo.Id);

            return(Ok());
        }
Beispiel #2
0
        public ActionResult ShopDelete(string id)
        {
            Shop s = db.Shops.Find(id);

            //刪除該店家的圖片
            PhotoManager.Delete(id);
            //刪除店內桌遊明細
            db.TableGameInShopDetails.RemoveRange(s.TableGameInShopDetails);
            //刪除一般優惠(活動)
            db.NormalOffers.RemoveRange(s.NormalOffers);
            //刪除優惠券主檔及其明細
            s.Coupons.ToList().ForEach(m => db.PlayerCouponDetails.RemoveRange(m.PlayerCouponDetails));
            db.Coupons.RemoveRange(s.Coupons);
            //刪除揪桌主檔及其相關資料
            foreach (Team t in s.Teams)
            {
                t.OtherPlayers.Clear();
                db.Messages.RemoveRange(t.Messages);
            }
            db.Teams.RemoveRange(s.Teams);
            //最後再刪除店家本身
            db.Shops.Remove(s);
            db.SaveChanges();

            return(RedirectToAction("ShopIndex"));
        }
        public ResponseModel <Product> Delete([FromForm] Product product)
        {
            ResponseModel <Product> productResult = new ResponseModel <Product>();

            try
            {
                productResult = _productManager.Delete(product);
                var photo         = photoManager.GetByProductId(productResult.result.ProductID);
                var photoResult   = FileStorageHelper.DeleteFile(Path.Combine(Environment.CurrentDirectory, "wwwroot", photo.result.PhotoUrl));
                var photoDBResult = photoManager.Delete(new Photo
                {
                    PhotoID   = photo.result.PhotoID,
                    PhotoUrl  = photo.result.PhotoUrl,
                    ProductID = photo.result.ProductID,
                    isMain    = photo.result.isMain
                });
                return(productResult);
            }
            catch (Exception ex)
            {
                productResult.Success = false;
                productResult.Message = ex.Message;
            }
            return(productResult);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Photo photos = photomanager.Find(x => x.Id == id);

            photomanager.Delete(photos);
            return(RedirectToAction("Index"));
        }
Beispiel #5
0
        public ActionResult PlayerDelete(string playerID)
        {
            Player p = db.Players.Find(playerID);

            //刪除桌遊評論
            p.TableGameComments.ToList().ForEach(m => db.TableGameComments.Remove(m));
            //刪除相關圖片
            PhotoManager.Delete(playerID);
            //刪除優惠券明細
            p.PlayerCouponDetails.ToList().ForEach(m => db.PlayerCouponDetails.Remove(m));
            //刪除點數明細
            p.PlayerPointDetails.ToList().ForEach(m => db.PlayerPointDetails.Remove(m));
            //刪除揪桌人員明細
            p.TeamsForOtherPlayer.ToList().ForEach(m => m.OtherPlayers.Remove(p));
            //刪除揪桌主檔
            p.TeamsForLeader.ToList().ForEach(m =>
            {
                //先刪除該桌的訊息
                m.Messages.ToList().ForEach(n => db.Messages.Remove(n));
                db.Teams.Remove(m);
            });
            //刪除玩家本身
            db.Players.Remove(p);
            db.SaveChanges();
            return(RedirectToAction("PlayerIndex"));
        }
Beispiel #6
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));
        }
        public ActionResult OfferDel(string normalOfferID)
        {
            var offer = db.NormalOffers.Find(normalOfferID);
            //檢查店家ID是否為活動所屬店家
            string shopID = (string)Session["ShopID"];

            if (shopID != offer.ShopID)
            {
                return(HttpNotFound());
            }

            //先刪除圖片
            PhotoManager.Delete(normalOfferID);
            db.NormalOffers.Remove(offer);
            db.SaveChanges();
            return(RedirectToAction("OfferList"));
        }
Beispiel #8
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"));
        }
Beispiel #9
0
        public ActionResult DeleteTableGame(string tableGameID)
        {
            TableGame tg = db.TableGames.Find(tableGameID);

            //刪除對應的GameCategoryTags
            tg.GameCategoryTags.Clear();
            //刪除對應的圖片
            PhotoManager.Delete(tableGameID);
            //刪除相關教學連結
            db.RelevantLinks.Where(m => m.TableGameID == tableGameID).ToList().ForEach(m => db.RelevantLinks.Remove(m));
            //刪除店內桌遊明細
            List <TableGameInShopDetail> details = db.TableGameInShopDetails.Where(m => m.TableGameID == tableGameID).ToList();

            details.ForEach(m => db.TableGameInShopDetails.Remove(m));
            //刪除桌遊評論
            db.TableGameComments.RemoveRange(tg.TableGameComments);
            //刪除桌遊閱覽紀錄
            db.TableGameVisitedStatistics.RemoveRange(tg.TableGameVisitedStatistics);
            //最後再刪除桌遊本身
            db.TableGames.Remove(tg);
            db.SaveChanges();
            return(RedirectToAction("ShowTableGameListForAdmin"));
        }
        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());
        }
Beispiel #11
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));
        }
Beispiel #12
0
        public JsonResult DeletePhoto(int id)
        {
            bool isdelete = PhotoManager.Delete(id);

            return(Json(isdelete));
        }
Beispiel #13
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"));
        }