Exemplo n.º 1
0
        [HttpPost] //IEnumerable<IUser>
        public dynamic CreateUserAccount([FromBody] User request)
        {
            //https://www.carlrippon.com/integrating-validation-in-angular-2-and-asp-net-core/
            //I think the above example uses reactive forms which is what we want
            //this link - http://jasonwatmore.com/post/2018/05/10/angular-6-reactive-forms-validation-example
            //shows how to do reactive and has a link on how to do template driven which is what we curenlty have
            //but the funky syntax will be hard to explain to students I think
            if (!ModelState.IsValid)
            {
                return(_userData.CreateUserAccount(request));
            }

            var results = _userData.CreateUserAccount(request);

            //If there is an exception from the method we will want to
            //create an exception class and fill it with data from the exception
            //and we can then return that data instead of whatever the method
            //would normally return if there was no exception
            if (results.Error != null)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, new ErrorJson
                {
                    Error = results.Error,
                    Internalcode = results.Internalcode
                }));
            }
            else
            {
                return(results);
            }
        }