/// <summary> /// Is for either saving new or modify exisiting record. /// To save new record method will call add method based on the paramter on configId = -1. /// </summary> /// <param name="inventoryDisplay"></param> /// <returns></returns> public JsonResult Save(InventoryOutConfigViewDisplay inventoryDisplay) { var result = new CustomJsonResult { Status = true, Message = "Successful", ConfigId = -1 }; if (inventoryDisplay.IsDatabaseInsert) { return(Add(inventoryDisplay)); } else { // saving // assuming that information exist in the database // now lets verify. // CategoryId is verifing for double checking if inevntory categoryid are same with this InventoryOutConfigID. // Which must be same. var inventoryOutConfig = db.InventoryOutConfigs .FirstOrDefault(n => n.InventoryOutConfigID == inventoryDisplay.InventoryOutConfigID && n.CategoryID == inventoryDisplay.CategoryID); if (inventoryOutConfig != null) { // exist in the database. // now first check for quantity mismatch. var quantityTypeExt = new QuantityTypeExtension(); decimal multiplier = 0; /* * * Passing DiscardCategoryID because Category id is for that inventory item category * which is irrelevent here. We are deduction small products by DiscardCategoryID * and so we are passing DiscardCategoryID instead of CategoryID * */ if (!quantityTypeExt.Mismatch(inventoryDisplay.DiscardCategoryID, inventoryDisplay.QuantityTypeID, out multiplier, false)) { //if it doesn't mismatch. inventoryOutConfig.DiscardItemCategory = inventoryDisplay.DiscardCategoryID; inventoryOutConfig.PerSaleQuantity = inventoryDisplay.Quantity; inventoryOutConfig.QtyType = inventoryDisplay.QuantityTypeID; db.SaveChanges(); return(Json(result)); } } } result.Status = false; result.Message = "Either quantity type validation failed or server internal error. Try again with different quantity type."; return(Json(result)); }
public JsonResult Add(InventoryOutConfigViewDisplay inventory) { var result = new CustomJsonResult { Status = true, Message = "Successful", ConfigId = -1 }; if (inventory != null) { var quantityTypeExt = new QuantityTypeExtension(); decimal multiplier = 0; /* * * Passing DiscardCategoryID because Category id is for that inventory item category * which is irrelevent here. We are deduction small products by DiscardCategoryID * and so we are passing DiscardCategoryID instead of CategoryID * */ if (!quantityTypeExt.Mismatch(inventory.DiscardCategoryID, inventory.QuantityTypeID, out multiplier, false)) { var inventoryOutConfig = new InventoryOutConfig() { CategoryID = inventory.CategoryID, //category of that inventory DiscardItemCategory = inventory.DiscardCategoryID, //discarding category when item is sold. For say burguer category needs to deduct from breads. QtyType = inventory.QuantityTypeID, PerSaleQuantity = inventory.Quantity //keep the same quantity and id deduct by mathematics multiplication in the real time selling not here. }; db.InventoryOutConfigs.Add(inventoryOutConfig); db.SaveChanges(); //updating configid. result.ConfigId = inventoryOutConfig.InventoryOutConfigID; return(Json(result)); } } result.Status = false; result.Message = "Either quantity type validation failed or server internal error. Try again with different quantity type."; return(Json(result)); }