コード例 #1
0
        public ActionResult Index(string username, bool? addUser, bool? getUser, bool? logOff, bool? orderById,string message)
        {

            try
            {
                if (unitOfWork == null)
                    unitOfWork = new UnitOfWork();

                if (addUser != null && (bool)addUser)
                {
                    if (unitOfWork.ChatUserList.Find(username) == null)
                    {
                        unitOfWork.ChatUserList.AddUser(username);
                        return View();
                    }
                    else
                    {
                        object errorMessage = "username " + "\"" + username + "\"" + " already exists";
                        //var model = new UserListViewModel { userList = unitOfWork.ChatUserList.GetAllUsers() };
                        return View("Index", errorMessage);
                    }
                }

                if (getUser != null && (bool)getUser == true)
                {
                    var user = unitOfWork.ChatUserList.Find(username);
                    user.IsOnline = true;

                    var model = new MessageListViewModel
                    {
                        chatMessageList = unitOfWork.ChatMessageList.OrderByDate(),
                        userMessageList = unitOfWork.ChatMessageList.GetUserMessages(username)
                    };

                    return PartialView("MessageListPartial", model);
                }

                if (!Request.IsAjaxRequest())
                {

                    //var model = new UserListViewModel {  userList = unitOfWork.ChatUserList.GetAllUsers() };
                    object model = "Select the username from list or add new username";
                    return View(model);
                }                          

                if (!String.IsNullOrEmpty(message))
                {
                    var user = unitOfWork.ChatUserList.Find(username);
                    unitOfWork.ChatMessageList.AddMessage(user, message);

                    MessageListViewModel model;

                    if (orderById != null && (bool)orderById == true)
                    {
                        model = new MessageListViewModel
                        {
                            chatMessageList = unitOfWork.ChatMessageList.OrderById(),
                            userMessageList = unitOfWork.ChatMessageList.GetUserMessages(username)
                        };
                    }
                    else
                    {
                        model = new MessageListViewModel
                        {
                            chatMessageList = unitOfWork.ChatMessageList.OrderByDate(),
                            userMessageList = unitOfWork.ChatMessageList.GetUserMessages(username)
                        };
                    }

                    return PartialView("MessageListPartial", model);
                }
                
               
                return View();
            }

            catch (Exception ex)
            {
                //в случае ошибки посылаем статусный код 500
                Response.StatusCode = 500;
                return Content(ex.Message);
            }
        }
コード例 #2
0
        public ActionResult UpdateMessageHistory(string username, bool? orderById)
        {
            MessageListViewModel model;

            if (orderById != null && (bool)orderById == true)
            {
                model = new MessageListViewModel
                {
                    chatMessageList = unitOfWork.ChatMessageList.OrderById(),
                    userMessageList = unitOfWork.ChatMessageList.GetUserMessages(username)
                };
            }
            else
            {
                model = new MessageListViewModel
                {
                    chatMessageList = unitOfWork.ChatMessageList.OrderByDate(),
                    userMessageList = unitOfWork.ChatMessageList.GetUserMessages(username)
                };
            }

            return PartialView("MessageListPartial", model);
        }