public HttpResponseMessage Atualizar(HttpRequestMessage request, MarcaViewModel marcaVM) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState.Keys.SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray()); } else { Marca novaMarca = _marcaRep.GetSingle(marcaVM.Id); Usuario usuario = _usuarioRep.GetSingle(int.Parse(HttpContext.Current.User.Identity.GetUserId())); if (novaMarca.Produtos.Count > 0 && marcaVM.Ativo == false) { return request.CreateErrorResponse(HttpStatusCode.PreconditionFailed, "Não é possível ser desativado"); } else { novaMarca.AtualizarMarca(marcaVM, usuario); } _unitOfWork.Commit(); // Update view model marcaVM = Mapper.Map <Marca, MarcaViewModel>(novaMarca); response = request.CreateResponse(HttpStatusCode.OK, marcaVM); } return response; })); }