コード例 #1
0
        public ActionResult Chat(string id)
        {
            try
            {
                LoginHelper.CheckAccess(Session);
            }
            catch (Exception)
            {
                return(RedirectToAction("Login", "Login"));
            }

            var matchHandler  = new MatchHandler();
            var userProfileId = (int)Session["userProfileId"];
            var userId        = (int)Session["userId"];

            var userProfileToMatch = new UserProfileHandler().GetByUsername(id);

            if (!userProfileToMatch.CompletedRequest)
            {
                return(RedirectToAction("Index", "Error", new { errorMessage = userProfileToMatch.ErrorMessage.Replace(' ', '-') }));
            }

            if (!matchHandler.Matched(userProfileId, userProfileToMatch.Entity.UserProfileId))
            {
                return(RedirectToAction("Index", "Error", new { errorMessage = MessageConstants.ChatNotAvailable.Replace(' ', '-') }));
            }

            var response = new MessageHandler().UpdateMessageStatus(userId, userProfileToMatch.Entity.UserId);

            if (!response.CompletedRequest)
            {
                return(RedirectToAction("Index", "Error", new { errorMessage = response.ErrorMessage.Replace(' ', '-') }));
            }

            ViewBag.toUsername = id;
            return(View());
        }