Beispiel #1
0
        public IHttpActionResult PostSaleUnit(SaleUnit saleUnit)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.SaleUnits.Add(saleUnit);

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

            return(CreatedAtRoute("DefaultApi", new { id = saleUnit.ID }, saleUnit));
        }
Beispiel #2
0
        public IHttpActionResult PutSaleUnit(int id, SaleUnit saleUnit)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
        public IHttpActionResult GetSaleUnit(int id)
        {
            SaleUnit saleUnit = db.SaleUnits.Find(id);

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

            return(Ok(saleUnit));
        }
Beispiel #4
0
        public IHttpActionResult DeleteSaleUnit(int id)
        {
            SaleUnit saleUnit = db.SaleUnits.Find(id);

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

            db.SaleUnits.Remove(saleUnit);
            db.SaveChanges();

            return(Ok(saleUnit));
        }