public async Task <ActionResult> Create(Stock stock) { string messag1 = ""; string messag2 = ""; if (ModelState.IsValid) { stock.Date = DateTime.Now; _db.Stocks.Add(stock); //User myUser = myDBContext.Users.SingleOrDefault(user => user.Username == username); //var user = _db.Users.Where(c => c.Email.Equals(model.Email)).SingleOrDefault(); //Product product = await _db.Products.FindAsync(int.Parse(stock.Name)); Product product = await _db.Products.SingleOrDefaultAsync(s => s.ProductId.Equals(stock.ProductId)); if (product == null) { return(HttpNotFound()); } else { int incomingValue = stock.Quantity; if (product.StockQuantity == null) { product.StockQuantity = 0; } if (stock.Status.Equals(PopUp.Status.Add)) { product.StockQuantity += incomingValue; } else if (stock.Status.Equals(PopUp.Status.Remove)) { product.StockQuantity -= incomingValue; } } if (product.StockQuantity < 0) { messag1 = "Sorry stock Removal is UNSUCCESSFUL"; messag2 = "You should have more item to subtract from"; return(RedirectToAction("Index", new { val1 = messag1, val2 = messag2 })); //return RedirectToAction("Details", "Consultants", new { id = pescription.ConsultantID }); } else { messag1 = "Successfully Updated"; _db.Entry(product).State = EntityState.Modified; await _db.SaveChangesAsync(); return(RedirectToAction("Index", new { val1 = messag1 })); } } return(View(stock)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,SupplierName,PhoneNumber,Address")] Supplier supplier) { if (ModelState.IsValid) { _db.Entry(supplier).State = EntityState.Modified; await _db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(supplier)); }
public async Task <ActionResult> Edit([Bind(Include = "CustomerId,AddressType,BuildingNo,StreetName,TownName,StateName")] ShippingDetail shippingDetail) { if (ModelState.IsValid) { db.Entry(shippingDetail).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "FirstName", shippingDetail.CustomerId); return(View(shippingDetail)); }
public async Task <ActionResult> Edit([Bind(Include = "ProductId,MerchantId,CategoryId,Name,AlternativeName,Price,Quantity,Unit,OtherUnitName,Description,ProductDiscount,DiscountPrice,IsApproved,DateAdded,StockQuantity,InternalImage,ItemPictureUrl")] Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", product.CategoryId); ViewBag.MerchantId = new SelectList(db.Merchants, "MerchantId", "CompanyName", product.MerchantId); return(View(product)); }