コード例 #1
0
        public IHttpActionResult Postrepas(repas repas)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.repas.Add(repas);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (repasExists(repas.label))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = repas.label }, repas));
        }
コード例 #2
0
        public IHttpActionResult Putrepas(string id, repas repas)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != repas.label)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public IHttpActionResult Deleterepas(string id)
        {
            repas repas = db.repas.Find(id);

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

            db.repas.Remove(repas);
            db.SaveChanges();

            return(Ok(repas));
        }
コード例 #4
0
        public IHttpActionResult Getrepas(string id)
        {
            repas         repas = db.repas.Find(id);
            RepaViewModel rep   = new RepaViewModel();

            if (repas == null)
            {
                return(NotFound());
            }
            else
            {
                rep.description     = repas.description;
                rep.label           = repas.label;
                rep.photo           = repas.photo;
                rep.idSpecN         = repas.idSpecN;
                rep.label_typeRepas = repas.label_typeRepas;
                return(Ok(rep));
            }
        }