예제 #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _chatRepository.GetUser(0, model.Name);
                if (user != null)
                {
                    ModelState.AddModelError("", "A user with this name is already in the system");
                    return(View(model));
                }

                // TODO: make submit application instead add to users
                user = new User {
                    Name             = model.Name,
                    Password         = model.Password,
                    Role             = "User",
                    CanCreateRoom    = true,
                    CanWriteMessages = true
                };

                _chatRepository.AddUser(user);
                return(RedirectToAction("Login", "Account"));
            }

            return(View(model));
        }
예제 #2
0
        public ChatModel NewUser(User user)
        {
            ChatModel model = new ChatModel();

            if (_chatRepo.ActiveUserCount() >= MAX_USERS)
            {
                model.TooManyUsers = true;
                model.Messages     = new List <Message>();
                model.Users        = new List <User>();

                return(model);
            }

            _chatRepo.AddUser(ObjectTranslator.GetDbUser(user));

            model.Messages = GetLatestMessages().ToList();
            model.Users    = GetActiveUsers().ToList();

            return(model);
        }
예제 #3
0
        public async Task <IActionResult> AddUser(Guid chatId, string userId)
        {
            await _chatRep.AddUser(chatId, userId);

            return(Ok());
        }