Esempio n. 1
0
        public HttpResponseMessage Post(FORMACAO obj)
        {
            try
            {
                Validate(obj);
                if (!ModelState.IsValid)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }

                ctx.Formacao.Add(obj);
                ctx.SaveChanges();

                return(Request.CreateResponse(HttpStatusCode.Created));
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
        public HttpResponseMessage Put(Guid idUsuario, int idEspecialidade, int idFormacao, FORMACAO obj)
        {
            try
            {
                var item = ctx.Formacao.FirstOrDefault(w => w.ID_USUARIO == idUsuario & w.ID_ESPECIALIDADE == idEspecialidade & w.ID_FORMACAO == idFormacao);

                item.AtualizaDados(obj.INSTITUICAO, obj.NOME_CURSO, obj.ANO_FORMACAO);
                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()));
            }
        }