public HttpResponseMessage Post(PERFIL_PROFISSIONAL obj) { try { Validate(obj); if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } ctx.PerfilProfissional.Add(obj); ctx.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.TratarMensagem())); } }
public ActionResult Create(CadastroProfissionalViewModel obj) { if (!ModelState.IsValid) { return(View(obj)); } try { Guid id = Guid.Parse(User.Identity.GetUserId()); var newobj = new PERFIL_PROFISSIONAL(id, obj.ID_ESPECIALIDADE, obj.RESUMO_CURRICULO); ctx.PerfilProfissional.Add(newobj); ctx.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.TratarMensagem()); return(View(obj)); } }
public HttpResponseMessage Put(Guid idUsuario, int idEspecialidade, PERFIL_PROFISSIONAL obj) { try { var item = ctx.PerfilProfissional.FirstOrDefault(w => w.ID_USUARIO == idUsuario & w.ID_ESPECIALIDADE == idEspecialidade); item.AtualizaValores(obj.RESUMO_CURRICULO); ctx.Entry(item).State = EntityState.Modified; Validate(item); if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } ctx.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.TratarMensagem())); } }