public ActionResult SharedEdit(/*[Bind(Include = "Name")]*/ Sharing entry, string action) { string currentUser = User.Identity.GetUserId(); string currentUserEmail = User.Identity.GetUserName(); bool isAllowed = db.Inventories.Where(inv => inv.Id == entry.InventoryId && (inv.UserId == currentUser || inv.SharedUsers.Any(s => s.Email == currentUserEmail && (s.Permission == AccessLevel.Edit || s.Permission == AccessLevel.Admin)))).Any(); if (ModelState.IsValid && isAllowed) { db.Entry(entry).State = EntityState.Modified; db.SaveChanges(); if (action == "SaveAndOpen") { return(RedirectToAction("Open", "Inventories", new { id = entry.InventoryId })); } else { return(RedirectToAction("Shared", "Inventories", new { inventoryid = entry.InventoryId })); } } return(View(entry)); }
//Update Stock records public static void UpdateRequisitionWithRItems(InventoryDbContext inventoryDbContext, RequisitionModel requisition) { try { var checkStatus = true; foreach (var rItems in requisition.RequisitionItems) { inventoryDbContext.RequisitionItems.Attach(rItems); inventoryDbContext.Entry(rItems).Property(x => x.ReceivedQuantity).IsModified = true; inventoryDbContext.Entry(rItems).Property(x => x.PendingQuantity).IsModified = true; if (rItems.ReceivedQuantity >= rItems.PendingQuantity) { inventoryDbContext.Entry(rItems).Property(x => x.RequisitionItemStatus).IsModified = true; } else { checkStatus = false; } } if (checkStatus) { inventoryDbContext.Requisitions.Attach(requisition); inventoryDbContext.Entry(requisition).Property(x => x.RequisitionStatus).IsModified = true; } inventoryDbContext.SaveChanges(); } catch (Exception ex) { throw ex; } }
public async Task Delete(int id) { var dealerToInactivate = await _inventoryDbContext.Dealers.FindAsync(id); // note: we dont delete record, only set active flag to false dealerToInactivate.Active = false; _inventoryDbContext.Entry(dealerToInactivate).State = EntityState.Modified; await _inventoryDbContext.SaveChangesAsync(); }
public async Task <IActionResult> PutSales(int id, Sales sales) { if (id != sales.Id) { return(BadRequest()); } _context.Entry(sales).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SalesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutCategory(string id, Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != category.CatCode) { return(BadRequest()); } db.Entry(category).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutProductInventory(int id, ProductInventory productInventory) { if (id != productInventory.Id) { return(BadRequest()); } _context.Entry(productInventory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductInventoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCustomer(int id, Customer customer) { if (id != customer.Id) { return(BadRequest()); } _context.Entry(customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutStock(string id, Stock stock) { if (id != stock.Description) { return(BadRequest()); } _context.Entry(stock).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StockExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit(int id, Product product) { product.ProductId = id; context.Entry(product).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); return(RedirectToAction("Index")); }
public JsonResult AcceptRequest(int requestID, Request request) { try { var updateStatus = new ERequest() { RequestId = requestID, Status = "Accepted" }; using (var context = new InventoryDbContext()) { context.Request.Attach(updateStatus); context.Entry(updateStatus).Property(x => x.Status).IsModified = true; context.SaveChanges(); } return(Json(string.Empty)); } catch (Exception ex) { return(Json(ex.ToString())); } }
//[ValidateAntiForgeryToken] public ActionResult Edit(Inventory inventory) { if (ModelState.IsValid) { _db.Entry(inventory).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(inventory)); }
public ActionResult Edit([Bind(Include = "SuppliersId,SuppliersName,CellNo,Address,AddedBy,IsActive")] Supplier supplier) { if (ModelState.IsValid) { db.Entry(supplier).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(supplier)); }
public ActionResult Edit(Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Edit([Bind(Include = "Invno,Qty,Amount,TransDate,Prodid")] Sale sale) { if (ModelState.IsValid) { db.Entry(sale).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sale)); }
public ActionResult Edit([Bind(Include = "EmployeeId,EmployeeName,Email,CellNo,Address,Salary,AddedBy,IsActive")] Employee employee) { if (ModelState.IsValid) { db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employee)); }
public ActionResult Edit([Bind(Include = "ProductID,ProductName,Quantity,ImageUrl,AddedBy,IsActive")] Stock stock) { if (ModelState.IsValid) { db.Entry(stock).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(stock)); }
public ActionResult Edit([Bind(Include = "CustomerId,CustomerName,Address,CellNo,AddedBy,OrderId")] Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
//[Authorize] public async Task <ActionResult> Edit([Bind(Include = "id,productName,partNumber,productLabel,startingInventory,InventoryReceived,InventoryShipped,InventoryOnHand,MinimumRequired")] Products products) { if (ModelState.IsValid) { db.Entry(products).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(products)); }
public ActionResult Edit([Bind(Include = "OrderId,OrderDate,ProductId,CustomerId,AddedBy,Quantity,UnitPrice")] Order order) { if (ModelState.IsValid) { db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "CustomerName", order.CustomerId); ViewBag.ProductId = new SelectList(db.Stocks, "ProductID", "ProductName", order.ProductId); return(View(order)); }
public ActionResult Edit([Bind(Include = "Id,PurchaseDate,ProductId,Quantity,UnitPrice,Total,SuppliersId,AddedBy")] Purchase purchase) { if (ModelState.IsValid) { db.Entry(purchase).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductId = new SelectList(db.Stocks, "ProductID", "ProductName", purchase.ProductId); ViewBag.SuppliersId = new SelectList(db.Suppliers, "SuppliersId", "SuppliersName", purchase.SuppliersId); return(View(purchase)); }
public static void UpdateWardInventory(InventoryDbContext inventoryDbContext, List <DispatchItemsModel> dispatchItems) { try { if (dispatchItems != null) { foreach (var stkItem in dispatchItems) { var wardItem = inventoryDbContext.WardStock.Where(i => i.ItemId == stkItem.ItemId && i.StockType == "inventory" && i.DepartmentId == stkItem.DepartmentId).FirstOrDefault(); if (wardItem != null) { wardItem.AvailableQuantity = wardItem.AvailableQuantity + Convert.ToInt32(stkItem.DispatchedQuantity); inventoryDbContext.Entry(wardItem).State = EntityState.Modified; } else { var inventory = (from inv in inventoryDbContext.Stock join goods in inventoryDbContext.GoodsReceiptItems on inv.GoodsReceiptItemId equals goods.GoodsReceiptItemId where inv.ItemId == stkItem.ItemId select new { BatchNo = inv.BatchNO, MRP = goods.ItemRate, inv.ExpiryDate }).FirstOrDefault(); WARDStockModel wardStock = new WARDStockModel(); wardStock.ItemId = stkItem.ItemId; wardStock.AvailableQuantity = Convert.ToInt32(stkItem.DispatchedQuantity); wardStock.DepartmentId = stkItem.DepartmentId; wardStock.StockType = "inventory"; if (inventory != null) { wardStock.BatchNo = inventory.BatchNo; wardStock.MRP = Convert.ToDouble(inventory.MRP); wardStock.ExpiryDate = inventory.ExpiryDate; } inventoryDbContext.WardStock.Add(wardStock); } } } //Update Stock records inventoryDbContext.SaveChanges(); } catch (Exception ex) { throw ex; } }
//this function is used in DISPATCH-ALL //here function updates only quantities and their status public static void UpdateRequisitionandRItems(InventoryDbContext inventoryDbContext, List <RequisitionModel> requisitions) { try { foreach (var req in requisitions) { foreach (var rItems in req.RequisitionItems) { inventoryDbContext.RequisitionItems.Attach(rItems); inventoryDbContext.Entry(rItems).Property(x => x.ReceivedQuantity).IsModified = true; inventoryDbContext.Entry(rItems).Property(x => x.PendingQuantity).IsModified = true; inventoryDbContext.Entry(rItems).Property(x => x.RequisitionItemStatus).IsModified = true; } inventoryDbContext.Requisitions.Attach(req); inventoryDbContext.Entry(req).Property(x => x.RequisitionStatus).IsModified = true; } inventoryDbContext.SaveChanges(); } catch (Exception ex) { throw ex; } }
public async Task <bool> UpdateProductAsync(Product product) { context.Product.Attach(product); context.Entry(product).State = EntityState.Modified; try { return(await context.SaveChangesAsync() > 0 ? true : false); } catch (Exception exp) { logger.LogError($"Error in {nameof(UpdateProductAsync)}: " + exp.Message); } return(false); }
//this is used for ReturnToVendor //here we are updating only stock's available quantity public static void UpdateStockAvailQty(InventoryDbContext inventoryDbContext, List <StockModel> Stock) { try { foreach (var stkItem in Stock) { inventoryDbContext.Stock.Attach(stkItem); inventoryDbContext.Entry(stkItem).Property(x => x.AvailableQuantity).IsModified = true; } inventoryDbContext.SaveChanges(); } catch (Exception ex) { throw ex; } }
//Update Stock records public static void UpdateStock(InventoryDbContext inventoryDbContext, List <StockModel> Stock) { try { foreach (var stkItem in Stock) { inventoryDbContext.Entry(stkItem).State = EntityState.Modified; } //Update Stock records inventoryDbContext.SaveChanges(); } catch (Exception ex) { throw ex; } }
// GET: Coffee public async Task <IActionResult> Index() { List <CoffeeViewModel> lcvm = new List <CoffeeViewModel>(); List <CoffeeModel> coffeeList = await _context.Coffees.ToListAsync(); foreach (var c in coffeeList) { _context.Entry(c).Reference("Country").Load(); _context.Entry(c).Reference("Variety").Load(); CoffeeViewModel cvm = new CoffeeViewModel { Item = c }; lcvm.Add(cvm); } return(View(lcvm)); }
public ActionResult Edit(/*[Bind(Include = "Name,Category,Type,Amount,Size,Color, InventoryId")]*/ Models.Item item) { string currentUser = User.Identity.GetUserId(); string currentUserEmail = User.Identity.GetUserName(); item.Size = string.IsNullOrWhiteSpace(item.Size) ? null : item.Size.Trim(); bool isAllowed = db.Inventories.Where(inv => inv.Id == item.InventoryId && (inv.UserId == currentUser || inv.SharedUsers.Any(s => s.Email == currentUserEmail && (s.Permission == AccessLevel.Edit || s.Permission == AccessLevel.Admin)))).Any(); if (ModelState.IsValid && isAllowed) { db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Open", "Inventories", new { id = item.InventoryId })); } return(View(item)); }
public int UploadImageInDataBase(HttpPostedFileBase file, Item item) { item.Image = ConvertToBytes(file); var Content = new Item { Description = item.Description, Image = item.Image }; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); int i = db.SaveChanges(); if (i == 1) { return(1); } else { return(0); } }
public InventoryCompanyModel UpdateCompany(InventoryCompanyModel model) { db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(model); }
public async Task UpdateAsync(T entity) { _dbContext.Entry(entity).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); }