Beispiel #1
0
        private dynamic RegisterUser()
        {
            var user = this.Bind <UserModel>();

            Response response;

            if (string.IsNullOrEmpty(user.UserName) || string.IsNullOrEmpty(user.Password))
            {
                response = new Response {
                    StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = "Invalid details provided"
                };
            }
            else
            {
                if (!_userRegistration.IsUserValid(user.UserName))
                {
                    response = new Response {
                        StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = "Invalid details provided"
                    };
                }
                else
                {
                    response = _userRegistration.RegisterUser(user.UserName, user.Password) ?
                               new Response {
                        StatusCode = HttpStatusCode.OK, ReasonPhrase = "User Created"
                    }
                        : new Response {
                        StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = "Unable to created requested user"
                    };
                }
            }

            return(response);
        }