예제 #1
0
        public IHttpActionResult PostDeleveryMethod(DeleveryMethod deleveryMethod)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.DeleveryMethods.Add(deleveryMethod);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (DeleveryMethodExists(deleveryMethod.ID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = deleveryMethod.ID }, deleveryMethod));
        }
예제 #2
0
        public IHttpActionResult PutDeleveryMethod(int id, DeleveryMethod deleveryMethod)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != deleveryMethod.ID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #3
0
        public IHttpActionResult GetDeleveryMethod(int id)
        {
            DeleveryMethod deleveryMethod = db.DeleveryMethods.Find(id);

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

            return(Ok(deleveryMethod));
        }
예제 #4
0
        public IHttpActionResult DeleteDeleveryMethod(int id)
        {
            DeleveryMethod deleveryMethod = db.DeleveryMethods.Find(id);

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

            db.DeleveryMethods.Remove(deleveryMethod);
            db.SaveChanges();

            return(Ok(deleveryMethod));
        }