Exemplo n.º 1
0
        public IActionResult Create([FromBody] UserForCreatedDto model)
        {
            var user = Mapper.Map <User>(model);

            if (!ValidateEntity(user))
            {
                return(new UnprocessableEntityResult(ModelState));
            }

            var result = _repository.Add(user);

            return(result.IsFaulted
                ? (IActionResult) new StatusCodeResult(StatusCodes.Status501NotImplemented)
                : Created("Get", user));
        }
Exemplo n.º 2
0
        public IActionResult Update(string id, [FromBody] UserForCreatedDto model)
        {
            var user = _repository.Get(id).Result;

            if (user == null)
            {
                return(NotFound());
            }

            Mapper.Map(model, user);
            if (!ValidateEntity(user))
            {
                return(new UnprocessableEntityResult(ModelState));
            }

            var result = _repository.Update(id, user);

            return(result.Result
                ? (IActionResult)Ok(user)
                : new StatusCodeResult(StatusCodes.Status501NotImplemented));
        }