public IHttpActionResult PostMaterial(Product material)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Materials.Add(material);

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

            return CreatedAtRoute("DefaultApi", new { id = material.ID }, material);
        }
        public IHttpActionResult PostProduct(Product product)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Products.Add(product);

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

            return CreatedAtRoute("DefaultApi", new { id = product.ID }, product);
        }
Beispiel #3
0
 public static Product Create(string name,string shortDiscription,string fullDiscription,PricingMethod priceMethod,decimal price,Guid baseUnitID)
 {
     Product product = new Product();
     product.Name = name;
     product.FullName = shortDiscription;
     product.FullDescription = fullDiscription;
     product.ShortDescription = shortDiscription;
     //product.PackingQuantity = packingQuantity;
     //product.Weight = weight;
     product.PricingMethod = priceMethod;
     product.ListPrice = price;
     product.BaseUnitID = baseUnitID;
        // product.ProductCatagorySettings = new HashSet<ProductCatagorySetting>();
     return product;
 }
        public IHttpActionResult PutMaterial(Guid id, Product material)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }