public ActionResult Create([Bind(Include = "GroupId,Name")] ProductGroup productGroup) { if (ModelState.IsValid) { db.ProductGroups.Add(productGroup); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productGroup)); }
public ActionResult Create([Bind(Include = "ProductId,Nmae,Description,Quantity,UnitOfMeasure,GroupId")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.GroupId = new SelectList(db.ProductGroups, "GroupId", "Name", product.GroupId); return(View(product)); }
public ActionResult Create([Bind(Include = "UnitStock,LocationCode,SaapumiseränId,Id")] Stock stock) { if (ModelState.IsValid) { db.Stocks.Add(stock); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SaapumiseränId = new SelectList(db.Recieved_ammounts, "SaapumiseränId", "Price", stock.SaapumiseränId); return(View(stock)); }
public ActionResult Create([Bind(Include = "SaapumiseränId,ProductId,Date,ExpireDate,Price,VendorName,LocationCode")] Recieved_ammount recieved_ammount) { if (ModelState.IsValid) { db.Recieved_ammounts.Add(recieved_ammount); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductId = new SelectList(db.Products, "ProductId", "Nmae", recieved_ammount.ProductId); return(View(recieved_ammount)); }
// GET: api/ReduceProduct public IEnumerable <Recieved_ammount> Get(int?SaapumiseranId) { //Query entry from entity JalkahoitolaEntities entities = new JalkahoitolaEntities(); Recieved_ammount EntryToModify = (from p in entities.Recieved_ammounts where p.SaapumiseranId == SaapumiseranId select p).SingleOrDefault(); int?id = EntryToModify.ProductId; //Take the last one and remove if (EntryToModify.UnitStock == 1) { EntryToModify.UnitStock = EntryToModify.UnitStock - 1; //EntryToModify = null; entities.Recieved_ammounts.Remove(EntryToModify); entities.SaveChanges(); } //If there's more than one, just reduce the amount if (EntryToModify.UnitStock > 1) { EntryToModify.UnitStock = EntryToModify.UnitStock - 1; entities.SaveChanges(); } //Get updated list from db and return it to client List <Recieved_ammount> items = (from o in entities.Recieved_ammounts where o.ProductId == id select o).ToList(); entities.Dispose(); List <Recieved_ammount> result = new List <Recieved_ammount>(); foreach (Recieved_ammount item in items) { Recieved_ammount data = new Recieved_ammount(); if (item.UnitStock > 0) { data.ProductId = item.ProductId; data.SaapumiseranId = item.SaapumiseranId; data.VendorName = item.VendorName; data.ExpireDate = item.ExpireDate; data.Date = item.Date; data.Price = item.Price; data.UnitStock = item.UnitStock; result.Add(data); } } return(result); }
public ProductGroup Post([FromBody] ProductGroup value) { JalkahoitolaEntities entities = new JalkahoitolaEntities(); entities.ProductGroups.Add(value); entities.SaveChanges(); entities.Dispose(); return(value); }
// GET: api/RemoveProduct/5 public int Get(int?id) { JalkahoitolaEntities entities = new JalkahoitolaEntities(); List <int?> items = (from o in entities.Recieved_ammounts where o.ProductId == id select o.UnitStock).ToList(); if (items.Sum() == 0 || items.Sum() == null) { Product ProductToBeRemoved = (from o in entities.Products where o.ProductId == id select o).First(); entities.Products.Remove(ProductToBeRemoved); entities.SaveChanges(); } entities.Dispose(); return(1); }
// GET: api/RemoveProductGroup // [HttpGet] public int Get(int id) { JalkahoitolaEntities entities = new JalkahoitolaEntities(); int items = (from p in entities.Products where p.GroupId == id select p).Count(); if (items == 0) { ProductGroup ProductGroupToBeRemoved = (from p in entities.ProductGroups where p.GroupId == id select p).First(); entities.ProductGroups.Remove(ProductGroupToBeRemoved); entities.SaveChanges(); } entities.Dispose(); return(items); }
public int Post([FromBody] Recieved_ammount value) { /* * Recieved_ammount testvalue = new Recieved_ammount(); * testvalue.ProductId = value.ProductId; * testvalue.SaapumiseränId = value.SaapumiseränId; * testvalue.Date = value.Date; * testvalue.ExpireDate = value.ExpireDate; * testvalue.Price = value.Price; * testvalue.VendorName = value.VendorName; * testvalue.LocationCode = value.LocationCode; * testvalue.Product = value.Product; * testvalue.Stocks = value.Stocks; * return testvalue; */ Recieved_ammount testvalue = new Recieved_ammount(); JalkahoitolaEntities entities = new JalkahoitolaEntities(); entities.Recieved_ammounts.Add(value); int result = entities.SaveChanges(); entities.Dispose(); return(result); }
// POST: api/Product public Product Post([FromBody] Product value) { JalkahoitolaEntities entities = new JalkahoitolaEntities(); /* Testing part * Product newProduct = new Product(); * newProduct.Nmae = value.Nmae; * newProduct.Description = value.Description; * newProduct.Quantity = value.Quantity; * newProduct.UnitOfMeasure = value.UnitOfMeasure; * newProduct.GroupId = value.GroupId; * newProduct.Entery_Date = value.Entery_Date; * newProduct.Expire = value.Expire; * newProduct.Person_Name = value.Person_Name; * entities.Products.Add(newProduct); * entities.SaveChanges(); * entities.Dispose(); * return newProduct; */ entities.Products.Add(value); entities.SaveChanges(); entities.Dispose(); return(value); }