Exemplo n.º 1
0
        public IHttpActionResult PostSTH(STH sTH)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.STH.Add(sTH);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (STHExists(sTH.CodigoSTH))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = sTH.CodigoSTH }, new STHDTO(sTH)));
        }
Exemplo n.º 2
0
        public IHttpActionResult PutSTH(string id, STH sTH)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != sTH.CodigoSTH)
            {
                return(BadRequest());
            }

            db.Entry(sTH).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!STHExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 3
0
 public STHDTO(STH s)
 {
     if (s == null)
     {
         return;
     }
     CodigoSTH      = s.CodigoSTH;
     SolicitacaoCod = s.SolicitacaoCod;
     DataAbertura   = s.DataAbertura;
 }
Exemplo n.º 4
0
        public IHttpActionResult GetSTH(string id)
        {
            STH sTH = db.STH.Find(id);

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

            return(Ok(new STHDTO(sTH)));
        }
Exemplo n.º 5
0
        public IHttpActionResult DeleteSTH(string id)
        {
            STH sTH = db.STH.Find(id);

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

            STHDTO s = new STHDTO(sTH);

            db.STH.Remove(sTH);
            db.SaveChanges();

            return(Ok(s));
        }