예제 #1
0
        public IActionResult Post([FromBody] UserRegisterViewModel user)
        {
            //add model validator filters, add ModelState.IsValid and throw BadRequest(ModelState)
            if (user == null)
            {
                var error = "Arguments of request is null";
                _logger.LogInformation(error);
                return(BadRequest(new { error }));
            }

            if (_dal.IsAlreadyExistLogin(user.Login))
            {
                var error = "Логин занят";
                _logger.LogInformation(error);
                return(BadRequest(new ResponseError(error)));
            }

            _logger.LogInformation("Add '{userTitle}' user", user.Login);
            var createdData = _dal.Add(user);

            _logger.LogInformation("Create is succussful");
            return(Ok(new ProfileViewModel(createdData)));
        }