public ActionResult Create(StockCardViewModel stockCardViewModel) { string itemNo = null; if (TempData.ContainsKey("id")) { itemNo = TempData["id"].ToString(); } InventoryViewModel i = InventoryDAO.GetInventoryByItemNo(itemNo); stockCardViewModel.balance = i.balance; stockCardViewModel.category = i.category; stockCardViewModel.description = i.description; stockCardViewModel.itemNo = i.itemNo; stockCardViewModel.dateModified = DateTime.Today; bool result = StockCardDAO.CreateStockCard(stockCardViewModel); if (result) { return(RedirectToAction("Index", new { id = itemNo })); } else { return(View("~/Views/Shared/Error.cshtml")); } }
public bool SaleProduct(List <SalesDetailsViewModel> orders) { var result = false; foreach (var item in orders) { var existingStock = context.tbl_Stock.Where(s => s.ProductId == item.productId).FirstOrDefault(); if (existingStock != null) { existingStock.QuantitySupplied -= item.quantity; } if (context.SaveChanges() > 0) { AddSalesDetails(item); var stockCard = new StockCardViewModel { dateRecieved = existingStock.DeliveryDate, quantityRecieved = existingStock.QuantitySupplied, //quantityRemaining = existingStock.QuantitySupplied - existingStock.QuantitySold, stockId = existingStock.StockId, createdOn = existingStock.CreatedOn, createdBy = existingStock.CreatedBy, lastDateUpdated = DateTime.Now }; card.AddStockCarda(stockCard); result = true; } else { return(false); } } return(result); }
public void AddStockCarda(StockCardViewModel entity) { var data = new tbl_StockCard { StockId = entity.stockId, QuantityRecieved = entity.quantityRecieved, QuantitySold = entity.quantitySold, DateRecieved = entity.dateRecieved, LastDateUpdated = entity.lastDateUpdated, CreatedOn = entity.createdOn, CreatedBy = entity.createdBy }; context.tbl_StockCard.Add(data); }
public HttpResponseMessage UpdateStockCard([FromBody] StockCardViewModel model) { try { var data = stockcardrepository.UpdateStockCard(model); if (data != null) { return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, Result = model, Message = "The record Updated Successfully" })); } return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, message = " There was an Error updating the record" })); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, message = $"There was an Error updating the record { ex.Message }" })); } }
public StockCardViewModel AddStockCard(StockCardViewModel entity) { var data = new tbl_StockCard { StockId = entity.stockId, QuantityRecieved = entity.quantityRecieved, QuantitySold = entity.quantitySold, DateRecieved = entity.dateRecieved, LastDateUpdated = entity.lastDateUpdated, CreatedOn = entity.createdOn, CreatedBy = entity.createdBy }; context.tbl_StockCard.Add(data); context.SaveChanges(); return(entity); }
public StockCardViewModel UpdateStockCard(StockCardViewModel entity) { var data = (from d in context.tbl_StockCard where d.StockCardId == entity.stockCardId select d).SingleOrDefault(); data = new tbl_StockCard { StockCardId = entity.stockCardId, StockId = entity.stockId, QuantityRecieved = entity.quantityRecieved, QuantitySold = entity.quantitySold, DateRecieved = entity.dateRecieved, LastDateUpdated = entity.lastDateUpdated, CreatedOn = entity.createdOn, }; context.tbl_StockCard.Add(data); context.SaveChanges(); return(entity); }
/// <summary> /// Create a new stock card record /// </summary> /// <param name="model">stock card info</param> /// <returns></returns> public static bool CreateStockCard(StockCardViewModel model) { using (var dbContextTransaction = DbFactory.Instance.context.Database.BeginTransaction()) { try { // change the inventory balance... var item = DbFactory.Instance.context.Inventories.Where(x => x.itemNo == model.itemNo).First(); if (item.balance == null) { item.balance = 0; } if (item.balance >= -model.quantity) { item.balance = item.balance + model.quantity; StockCard sc = new StockCard() { itemNo = model.itemNo, remark = model.remark, quantity = model.quantity, balance = (int)item.balance, dateModified = DateTime.Now.Date }; DbFactory.Instance.context.StockCards.Add(sc); DbFactory.Instance.context.SaveChanges(); // Commit the transaction dbContextTransaction.Commit(); return(true); } } catch (Exception e) { dbContextTransaction.Rollback(); } return(false); } }
public void AddStockEntry(StockViewModel entity) { var data = new tbl_Stock { ProductId = entity.productId, StockCode = entity.stockCode, PurchaseOrderDetailId = entity.purchaseOrderDetailId, PurchaseOrderId = entity.purchaseOrderId, QuantitySupplied = entity.quantitySupplied, SupplyDate = entity.supplyDate, CostPerItem = entity.costPerItem, SellingPrice = entity.sellingPrice, BranchId = entity.branchId, DeliveryDate = entity.deliveryDate, IsActive = true, CreatedOn = entity.createdOn, CreatedBy = "admin", }; context.tbl_Stock.Add(data); //context.SaveChanges(); //data.StockId = data.StockId; var stockCard = new StockCardViewModel { dateRecieved = data.DeliveryDate, quantityRecieved = data.QuantitySupplied, //quantityRemaining = data.quantityRemaining, stockId = data.StockId, createdOn = entity.createdOn, createdBy = data.CreatedBy, lastDateUpdated = DateTime.Now }; card.AddStockCarda(stockCard); // return entity ; }
// GET: StockCard/Create public ActionResult Create() { string itemNo = null; if (TempData.ContainsKey("id")) { itemNo = TempData["id"].ToString(); TempData["id"] = itemNo; } InventoryViewModel i = InventoryDAO.GetInventoryByItemNo(itemNo); StockCardViewModel stockCardViewModel = new StockCardViewModel(); stockCardViewModel.balance = i.balance; stockCardViewModel.category = i.category; stockCardViewModel.description = i.description; stockCardViewModel.itemNo = i.itemNo; string today = DateTime.Now.ToShortDateString(); ViewBag.date = today; return(View(stockCardViewModel)); }