コード例 #1
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));
        }
コード例 #2
0
ファイル: ajaxController.cs プロジェクト: shane23675/TGIS
        public ActionResult PasswordChange(string oldpwd, string newpwd, string pwdrepeat, string userId)
        {
            if (newpwd == pwdrepeat)
            {
                if (userId.Substring(0, 1) == "S")
                {
                    Shop shop = db.Shops.Find(userId);
                    if (shop.Password == Hash.PwdHash(oldpwd))
                    {
                        shop.Password = Hash.PwdHash(newpwd);
                        db.SaveChanges();

                        return(Content("2"));
                    }
                    return(Content("1"));
                }
                else if (userId.Substring(0, 1) == "T")
                {
                    Player player = db.Players.Find(userId);
                    if (player.Password == Hash.PwdHash(oldpwd))
                    {
                        player.Password = Hash.PwdHash(newpwd);
                        db.SaveChanges();

                        return(Content("2"));
                    }
                    return(Content("1"));
                }
                return(Content("3"));
            }
            return(Content("0"));
        }
コード例 #3
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));
        }
コード例 #4
0
ファイル: CouponController.cs プロジェクト: shane23675/TGIS
        public ActionResult CouponActivate(string couponID)
        {
            Coupon c = db.Coupons.Find(couponID);

            c.IsAvailable = true;
            db.SaveChanges();
            return(RedirectToAction("CouponIndexForAdmin"));
        }
コード例 #5
0
        public ActionResult CityCreate(string CityName)
        {
            var c = new City();

            c.CityName = CityName;
            db.Cities.Add(c);
            db.SaveChanges();
            return(RedirectToAction("_CityList"));
        }
コード例 #6
0
        public ActionResult DistrictCreate(string DistrictName, int CityID)
        {
            var d = new District();

            d.DistrictName = DistrictName;
            d.CityID       = CityID;
            db.Districts.Add(d);
            db.SaveChanges();
            return(RedirectToAction("_DistrictList", new { CityID = CityID }));
        }
コード例 #7
0
 public ActionResult ContactUs(Feedback feedback)
 {
     //不需要檢舉人和被檢舉人,只確定回報類型
     feedback.Plaintiff    = "";
     feedback.Defendent    = "";
     feedback.ReceivedDate = DateTime.Now;
     feedback.IsRead       = false;
     db.Feedbacks.Add(feedback);
     db.SaveChanges();
     return(View("ThanksForFeedback"));
 }
コード例 #8
0
ファイル: TagController.cs プロジェクト: shane23675/TGIS
        public ActionResult TagCreate(string TagName, string TagID)
        {
            var tag = new Tag
            {
                TagName = TagName,
                ID      = UsefulTools.GetNextID(db.Tags.ToList().Where(t => t.ID[0].ToString() == TagID), 1)
            };

            db.Tags.Add(tag);
            db.SaveChanges();
            return(RedirectToAction("_TagList"));
        }
コード例 #9
0
 public ActionResult CreateAnnoun(Announcement ann)
 {
     if (ModelState.IsValid)
     {
         //填入必要資料
         ann.ID = UsefulTools.GetNextID(db.Announcements, 2);
         ann.AdministratorID = Session["AdminID"].ToString();
         ann.AnnouncedDate   = DateTime.Today;
         db.Announcements.Add(ann);
         db.SaveChanges();
     }
     return(RedirectToAction("AnnouncementIndexForAdmin"));
 }
コード例 #10
0
ファイル: TeamChatController.cs プロジェクト: shane23675/TGIS
            //覆寫OnMessage事件,前端send時觸發,被觸發後會回頭觸發前端的onmessage事件
            public override void OnMessage(string message)
            {
                //將訊息的相關資訊製成Json檔後傳出
                _chatRooms[_roomKey].Broadcast(
                    JsonConvert.SerializeObject(new {
                    Message  = message,
                    Time     = DateTime.Now.ToString("MM/dd hh:mm"),
                    UserID   = _userID,
                    UserName = _userName
                })
                    );

                //將此訊息儲存至訊息列表
                Message m = new Message
                {
                    TeamID      = _teamID,
                    MessageDate = DateTime.Now,
                    Speaker     = _userID,
                    IsPrivate   = _isPrivate,
                    Content     = message.Length > 300 ? message.Substring(0, 300) : message
                };
                var db = new TGISDBEntities();

                db.Messages.Add(m);
                db.SaveChanges();
            }
コード例 #11
0
ファイル: TeamController.cs プロジェクト: shane23675/TGIS
        public ActionResult TeamDetailForPlayer(string teamID, string action, bool fromMyTeam = false)
        {
            //先找到對應的team、player
            Player player = db.Players.Find(Session["PlayerID"].ToString());
            Team   team   = db.Teams.Find(teamID);

            //通過action判斷要參加、退出、取消出團或提前截止
            switch (action)
            {
            //送出訂位請求(若無法在該玩家為隊長的團中找到指定ID的團則返回錯誤頁面
            case "sendRequest":
                if (!player.TeamsForLeader.Any(t => t.ID == teamID))
                {
                    return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest));
                }
                team.IsRequestSent = true;
                break;

            //退出
            case "exit":
                team.OtherPlayers.Remove(player);
                break;

            //參加
            case "join":
                team.OtherPlayers.Add(player);
                break;

            //取消
            case "cancel":
                team.IsCanceled = true;
                break;

            //提前截止報名
            case "close":
                team.IsClosed = true;
                break;
            }
            db.SaveChanges();

            //若此請求來自「我的揪桌」則導回
            if (fromMyTeam)
            {
                return(RedirectToAction("MyTeam"));
            }
            return(View(team));
        }
コード例 #12
0
        public ActionResult EmailRepeat(string id)
        {
            Player player = db.Players.Find(id);

            player.IsEmailValid = true;
            db.SaveChanges();
            return(View());
        }
コード例 #13
0
        public ActionResult UpdateTableGameInShopDetail(string[] tableGameIDs, bool[] isContainedFlags, bool[] isSaleFlags, int[] Price)
        {
            string                shopID = Session["ShopID"].ToString();
            TableGame             tg;
            TableGameInShopDetail detail;
            //CheckBox陣列整理(o:舊陣列)
            Func <bool[], List <bool> > arrange = (o) =>
            {
                List <bool> n = new List <bool>();
                for (int i = 0; i < o.Length; i++)
                {
                    if (o[i] == true)
                    {
                        n.Add(true);
                        i++;
                    }
                    else
                    {
                        n.Add(false);
                    }
                }
                return(n);
            };

            for (int i = 0; i < tableGameIDs.Length; i++)
            {
                //查找此店家是否有此桌遊
                tg     = db.TableGames.Find(tableGameIDs[i]);
                detail = tg.TableGameInShopDetails.Where(m => m.ShopID == shopID).FirstOrDefault();
                //有此桌遊,進一步判斷此桌遊是否有被刪除
                if (detail != null)
                {
                    if (arrange(isContainedFlags)[i])
                    {
                        detail.IsSale = arrange(isSaleFlags)[i];
                        detail.Price  = Price[i];
                    }
                    else
                    {
                        db.TableGameInShopDetails.Remove(detail);
                    }
                }
                //無此桌遊,若後來有被新增則新增至TableGameInShopDetails
                else if (arrange(isContainedFlags)[i])
                {
                    TableGameInShopDetail d = new TableGameInShopDetail
                    {
                        ShopID      = shopID,
                        TableGameID = tableGameIDs[i],
                        IsSale      = arrange(isSaleFlags)[i],
                        Price       = Price[i]
                    };
                    db.TableGameInShopDetails.Add(d);
                }
                db.SaveChanges();
            }
            return(RedirectToAction("UpdateTableGameInShopDetail"));
        }
コード例 #14
0
        //顯示單個桌遊詳細內容
        public ActionResult ShowTableGameDetail(string tableGameID)
        {
            //將此桌遊的相關連結傳入ViewBag
            ViewBag.relevantLinks = db.RelevantLinks.Where(m => m.TableGameID == tableGameID).ToList();
            //將此桌遊的圖片數量傳入ViewBag
            ViewBag.photoIDList = PhotoManager.GetPhotoIDList(tableGameID);
            //新增一筆桌遊閱覽紀錄(每月至多紀錄一筆)
            var statistic = db.TableGameVisitedStatistics.ToList().Where(s => s.VisitedDate.ToString("yyyy/MM") == DateTime.Today.ToString("yyyy/MM")).FirstOrDefault();

            if (statistic == null)
            {
                db.TableGameVisitedStatistics.Add(new TableGameVisitedStatistic
                {
                    VisitedDate = DateTime.Today,
                    Clicks      = 1,
                    TableGameID = tableGameID
                });
            }
            else
            {
                statistic.Clicks++;
            }
            db.SaveChanges();
            return(View(db.TableGames.Find(tableGameID)));
        }
コード例 #15
0
        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());
        }
コード例 #16
0
 public ActionResult AdminCreate(Administrator administrator, string pwdConfirm)
 {
     //驗證帳號密碼格式
     UsefulTools.RegisterValidate(administrator.Account, msg => ModelState["Account"].Errors.Add(msg), false, false);
     UsefulTools.RegisterValidate(administrator.Password, msg => ModelState["Password"].Errors.Add(msg), true, false);
     if (administrator.Password != pwdConfirm)
     {
         ModelState.AddModelError("Password", "密碼確認和密碼欄位不相符");
     }
     if (ModelState.IsValid)
     {
         administrator.ID = UsefulTools.GetNextID(db.Administrators, 1);
         db.Administrators.Add(administrator);
         db.SaveChanges();
         return(RedirectToAction("AdminIndex"));
     }
     return(View(administrator));
 }
コード例 #17
0
ファイル: ToolController.cs プロジェクト: shane23675/TGIS
        //修正RelevantLinks網址
        public ActionResult RelevantLinksReplace()
        {
            var links = db.RelevantLinks.ToList();

            foreach (var link in links)
            {
                link.Url = link.Url.Replace("watch?v=", "embed/");
            }
            db.SaveChanges();
            return(RedirectToAction("Test"));
        }
コード例 #18
0
        public ActionResult ForgetPwd(string account, string Email)
        {
            Player user = db.Players.Where(m => m.Account == account).SingleOrDefault();

            if (user != null)
            {
                if (Email == user.Email)
                {
                    string newPwd = UsefulTools.CreateNewPwd();
                    var    id     = Hash.PwdHash(user.ID);
                    user.Password = Hash.PwdHash(newPwd);
                    db.SaveChanges();
                    var content = $"您好,已為您重設密碼,您的新密碼如下:\n密碼:{newPwd}\n請以此密碼重新登入,並建議再次變更密碼確保資訊安全,謝謝您\n有桌方遊資訊網";
                    AutoEmail.AutoEmailSend(Email, "有桌方遊:密碼重設", content);
                    return(RedirectToAction("Index", "Home"));
                }
                ViewBag.Error = "信箱錯誤";
                return(View());
            }
            ViewBag.Error = "查無此帳號";
            return(View());
        }
コード例 #19
0
 // 玩家新增評論
 public ActionResult CreateTGComment(string tId, string comment)
 {
     if (Session["PlayerID"] != null)
     {
         if (ModelState.IsValid && comment.Trim() != "")
         {
             var pId = Session["PlayerID"].ToString();
             TableGameComment tgc = new TableGameComment();
             tgc.PlayerID    = pId;
             tgc.TableGameID = tId;
             tgc.CommentDate = DateTime.Today;
             tgc.Content     = comment;
             tgc.IsHidden    = false;
             db.TableGameComments.Add(tgc);
             UsefulTools.PointRecord((string)Session["PlayerID"], "評論桌遊", 1);
             Player player = db.Players.Find(pId);
             player.Points += 1;
             db.SaveChanges();
         }
         return(RedirectToAction("ShowTableGameDetail", "TableGame", new { tableGameID = tId }));
     }
     return(RedirectToAction("LoginForPlayer", "Login"));
 }