public static void UpdateOrderDetailSession(string pageToken, OrderDetailSessionViewModel orderDetail, bool isGroupProducts = false, bool isAddForTransferOrder = false) { if (!string.IsNullOrEmpty(pageToken)) { var orderDetailsDictionary = HttpContext.Current.Session["OrderDetailsSession"] as Dictionary <string, List <OrderDetailSessionViewModel> > ?? new Dictionary <string, List <OrderDetailSessionViewModel> >(); var hasKey = orderDetailsDictionary.ContainsKey(pageToken); var existingDetailsList = new List <OrderDetailSessionViewModel>(); if (hasKey) { existingDetailsList = orderDetailsDictionary[pageToken]; var existingOrderDetail = existingDetailsList.FirstOrDefault(m => m.OrderDetailID == orderDetail.OrderDetailID); if (existingOrderDetail == null && isGroupProducts) { existingOrderDetail = existingDetailsList.FirstOrDefault(m => m.ProductId == orderDetail.ProductId); } if (existingOrderDetail != null) { if (isGroupProducts) { if (orderDetail.OrderDetailID > 0) { existingOrderDetail.Qty = orderDetail.Qty; } else { if (existingOrderDetail != null && isAddForTransferOrder) { existingOrderDetail.Qty += orderDetail.Qty; } else { existingOrderDetail.Qty = orderDetail.Qty; } } } else { existingOrderDetail.Qty = orderDetail.Qty; existingOrderDetail.ProductMaster.SKUCode = orderDetail.ProductMaster.SKUCode; existingOrderDetail.CaseQuantity = orderDetail.CaseQuantity; existingOrderDetail.Price = orderDetail.Price; existingOrderDetail.ProductId = orderDetail.ProductId; existingOrderDetail.AccountCode = orderDetail.AccountCode; existingOrderDetail.Notes = orderDetail.Notes; existingOrderDetail.TotalAmount = orderDetail.TotalAmount; existingOrderDetail.TaxAmount = orderDetail.TaxAmount; existingOrderDetail.TaxID = orderDetail.TaxID; existingOrderDetail.WarrantyID = orderDetail.WarrantyID; existingOrderDetail.WarrantyAmount = orderDetail.WarrantyAmount; existingOrderDetail.ProductMaster.Name = orderDetail.ProductMaster.Name; existingOrderDetail.TaxName = orderDetail.TaxName; } var index = existingDetailsList.IndexOf(existingOrderDetail); existingDetailsList[index] = existingOrderDetail; } else { existingDetailsList.Add(orderDetail); } orderDetailsDictionary[pageToken] = existingDetailsList; } else { existingDetailsList = new List <OrderDetailSessionViewModel> { orderDetail }; orderDetailsDictionary.Add(pageToken, existingDetailsList); } HttpContext.Current.Session["OrderDetailsSession"] = orderDetailsDictionary; } }
public PartialViewResult _OrderDetail(int?Id, string pageSessionToken) { ViewBag.cases = false; DateTime?exp_dte = null; var orderId = 0; if (!string.IsNullOrEmpty(Request.Params["OrderID"])) { orderId = int.Parse(Request.Params["OrderID"]); } if (Request.Params["exp_date"] != "") { exp_dte = DateTime.Parse(Request.Params["exp_date"].ToString()); } var value = int.Parse(Request.Params["did"] ?? "0"); if (Request.Params["rec_qty"] != null) { ViewBag.RecQty = Request.Params["rec_qty"].ToString(); } ViewBag.Products = new SelectList(_productServices.GetAllValidProductMasters(CurrentTenantId), "ProductId", "NameWithCode"); ViewBag.ProductAccounts = new SelectList(new List <ProductAccountCodes>(), "ProdAccCodeID", "ProdAccCode"); if (!string.IsNullOrEmpty(Request.Params["account"])) { var accountId = int.Parse(Request.Params["account"]); var data = (from pac in AccountServices.GetAllProductAccountCodesByAccount(accountId) select new { pac.ProdAccCodeID, pac.ProdAccCode }).ToList(); ViewBag.ProductAccounts = new SelectList(data, "ProdAccCodeID", "ProdAccCode"); } if (!string.IsNullOrEmpty(Request.Params["product"])) { var productid = int.Parse(Request.Params["product"]); var product = _productServices.GetProductMasterById(productid); if (product != null) { ViewBag.ProductCurrentPrice = product.SellPrice; } } ViewBag.GlobalWarranties = new SelectList(LookupServices.GetAllTenantWarrenties(CurrentTenantId), "WarrantyID", "WarrantyName"); var taxes = (from gtax in LookupServices.GetAllValidGlobalTaxes(CurrentTenant.CountryID) select new { TaxId = gtax.TaxID, TaxName = gtax.TaxName + " - " + gtax.PercentageOfAmount + " %" }).ToList(); ViewBag.GlobalTaxes = new SelectList(taxes, "TaxId", "TaxName"); if (value == 0) { ViewBag.IsTransferOrderAdd = true; return(PartialView("Create", new OrderDetailSessionViewModel { ExpectedDate = exp_dte, OrderID = !string.IsNullOrEmpty(Request.Params["oid"]) ? (int.Parse(Request.Params["oid"])) : orderId, TenentId = CurrentTenantId, WarehouseId = CurrentWarehouseId })); } else { if (Request.UrlReferrer.AbsolutePath.Contains("ProcessOrder")) { var cObject = OrderService.GetOrderDetailsById(value); ViewBag.productId = cObject.ProductId; var product = _productServices.GetProductMasterById(cObject.ProductId); ViewBag.cases = product?.ProcessByCase; ViewBag.processcase = product?.ProductsPerCase == null ? 1 : product.ProductsPerCase; if (product?.ProcessByCase != null && product?.ProcessByCase == true) { ViewBag.caseProcess = (cObject.Qty / (product?.ProductsPerCase == null ? 1 : product.ProductsPerCase)); } var cOrderSessionViewModel = AutoMapper.Mapper.Map(cObject, new OrderDetailSessionViewModel()); return(PartialView("Create", cOrderSessionViewModel)); } var odList = GaneOrderDetailsSessionHelper.GetOrderDetailSession(pageSessionToken); var model = odList.FirstOrDefault(a => a.OrderDetailID == value && a.IsDeleted != true); if (model != null) { ViewBag.productId = model.ProductId; var product = _productServices.GetProductMasterById(model.ProductId); ViewBag.cases = product?.ProcessByCase; ViewBag.processcase = product?.ProductsPerCase == null ? 1 : product.ProductsPerCase; if (product?.ProcessByCase != null && product?.ProcessByCase == true) { ViewBag.caseProcess = (model.Qty / (product?.ProductsPerCase == null ? 1 : product.ProductsPerCase)); } } if (model == null) { model = new OrderDetailSessionViewModel() { OrderID = orderId }; ViewBag.IsTransferOrderAdd = true; } return(PartialView("Create", model)); } }