public ActionResult Inventorization() { ApplicationUserManager UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); ApplicationUser user = UserManager.FindByName(User.Identity.Name); var WarehouseId = user.Claims.SingleOrDefault(c => c.ClaimType == "WarehouseId").ClaimValue; var warehouse = db.Warehouses.Find(Int32.Parse(WarehouseId)); if (warehouse.Status == false) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (HttpContext.Session["Inv"] == null) { var goods = db.Goods.Where(g => g.Status == true).Include(g => g.MeasureUnit).Include(g => g.Supplier); List <InventorizationViewModel> InventorizationsList = new List <InventorizationViewModel>(); foreach (var item in goods.ToList()) { var Inventorization = new InventorizationViewModel() { Id = item.Id, MeasureUnit = item.MeasureUnit, Name = item.Name, Supplier = item.Supplier }; InventorizationsList.Add(Inventorization); } HttpContext.Session["Inv"] = InventorizationsList; } return(View(HttpContext.Session["Inv"])); }
public ActionResult InventorizationSend(InventorizationViewModel model, int goodsQuantity) { Goods goods = db.Goods.Find(model.Id); ApplicationUserManager UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); ApplicationUser user = UserManager.FindByName(User.Identity.Name); var WarehouseId = user.Claims.SingleOrDefault(c => c.ClaimType == "WarehouseId").ClaimValue; GoodsMovement goodsMovement = goods.GoodsMovements.FirstOrDefault(gm => gm.WarehouseId.ToString() == WarehouseId && gm.Date.Date == DateTime.Now.Date); int goodsBalance = goodsMovement.GoodsBalance; InventoryResult inventoryResult = new InventoryResult { GoodsId = model.Id, ActualGoodsBalance = goodsQuantity, RegisteredGoodsBalance = goodsBalance, InventoryDate = DateTime.Now, WarehouseId = Int32.Parse(WarehouseId) }; db.InventoryResults.Add(inventoryResult); db.SaveChanges(); ((List <InventorizationViewModel>)HttpContext.Session["Inv"]).Find(x => x.Id == model.Id).Status = true; model.Status = ((List <InventorizationViewModel>)HttpContext.Session["Inv"]).Find(x => x.Id == model.Id).Status; return(PartialView("InventorizationPartial", model)); }