public ActionResult EditarTarefa(TarefaEdicaoModel model) { try { if (ModelState.IsValid) { TarefaDto dto = Montador.MontaModeloDominioEViceVersa.Monta(model); tarefaAplicacaoServico.AlterarTarefa(dto); return Json(new { TarefaModel = dto },"application/json",Encoding.UTF8); } else { HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; IList<String> erros = new List<String>(); foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { erros.Add(error.ErrorMessage); } } throw new ExcecaoTarefa(Json(erros,"application/json",Encoding.UTF8).ToString()); } } catch (ExcecaoTarefa et) { return Json(new { ExcecaoTarefa = String.Format("Erro: {0}", et.Message) }, "application/json", Encoding.UTF8); } catch (Exception ex) { HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError; return Json(new { ExcecaoTarefa = String.Format("Erro: {0}", ex.Message) }, "application/json", Encoding.UTF8); } }
public static TarefaEdicaoModel MontaTarefaEdicaoModel(TarefaDto dto) { if (dto != null) { TarefaEdicaoModel model = new TarefaEdicaoModel() { DataDaEntrega = dto.DataDaEntrega, Descricao = dto.Descricao, Estado = (EstadoTarefaModel)dto.Estado, IdUsuario = dto.Usuario.Id, Nome = dto.Nome }; return model; } else { return null; } }
public static TarefaDto Monta(TarefaEdicaoModel model) { if (model != null) { TarefaDto dto = new TarefaDto() { DataDaEntrega = model.DataDaEntrega, Descricao = model.Descricao, Estado = (EstadoTarefa)model.Estado, Nome = model.Nome }; return dto; } else { return null; } }