Esempio n. 1
0
        public async Task <ActionResult <UserDTO> > Post([FromBody] UserDTO dto)
        {
            try
            {
                //Link Generator
                var location = LinkGenerator.GetPathByAction("Get", "User", new { id = dto.UserId });
                if (string.IsNullOrWhiteSpace(location))
                {
                    return(BadRequest("Could not use current Id"));
                }

                dto.DateOfRegistration = DateTime.Now.Date;

                var user = Mapper.Map <User>(dto);

                //Da risolvere
                await UnitOfWork.AddUserAsync(user);

                return(Created($"/api/users/{user.UserId}", Mapper.Map <UserDTO>(user)));
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
            return(BadRequest());
        }