public ActionResult Add() { string name = HttpContext.User.Identity.Name; List <SalePoint> salePointList = new List <SalePoint>(); salePointList = AgroExpressDBAccess.GetSalePointListForUSer(name); SalePointProductAdd salePointProductTransfer = new SalePointProductAdd(); salePointProductTransfer.salepointlist = salePointList.Select(x => new SelectListItem { Value = x.PKSalePointID.ToString(), Text = x.SalePointName }); List <ProductTransferInfo> PTI = new List <ProductTransferInfo>(); var MilkInfo = AgroExpressDBAccess.IsProductExist("Milk"); if (MilkInfo != null) { PTI.Add(new ProductTransferInfo { ProductId = MilkInfo.PKProductId, Amount = null }); } else { Product MilkInfoAdd = new Product { ProductName = "Milk", SellingUnit = "Ltr", Stock = 0 }; AgroExpressDBAccess.AddProduct(MilkInfoAdd); MilkInfo = AgroExpressDBAccess.IsProductExist("Milk"); PTI.Add(new ProductTransferInfo { ProductId = MilkInfo.PKProductId, Amount = null }); } // Product dropdown list var ProductInf = AgroExpressDBAccess.GetAllEnabledProduct(); ProductInf = ProductInf.Where(a => a.ProductName.ToLower() != "milk").ToList(); salePointProductTransfer.product = ProductInf.Select(x => new SelectListItem { Value = x.PKProductId.ToString(), Text = x.ProductName }); // int len = ProductInf.Count; for (int i = 0; i < len; i++) { PTI.Add(new ProductTransferInfo { ProductId = null, Amount = null }); } salePointProductTransfer.TransferedProductInfo = PTI; salePointProductTransfer.Date = System.DateTime.Now.Date; return(View(salePointProductTransfer)); }
public ActionResult Add(Product product) { if (ModelState.IsValid) { var productobj = AgroExpressDBAccess.IsProductExist(product.ProductName); if (productobj != null) { ModelState.AddModelError("ProductName", "Product name already exist"); return(View(product)); } if (AgroExpressDBAccess.AddProduct(product)) { ViewBag.success = "Registration Successsfull"; ModelState.Clear(); Product producttem = new Product(); return(View(producttem)); } } return(View(product)); }
public ActionResult Add(SalePointProductAdd Request) { if (ModelState.IsValid) { string name = HttpContext.User.Identity.Name; string operatorName = AgroExpressDBAccess.GetFullNamebyUserID(name); List <ProductTransferInfo> PTI = Request.TransferedProductInfo; int len = PTI.Count; List <SalePointProductConsume> newProduct = new List <SalePointProductConsume>(); for (int i = 0; i < len; i++) { if (PTI[i].ProductId != null && (PTI[i].Amount != null)) { newProduct.Add(new SalePointProductConsume { SalePointId = Request.SalePointId, Date = Request.Date, ProductId = (int)PTI[i].ProductId, Amount = (int)PTI[i].Amount, OperatorName = operatorName }); } } ViewBag.message = AgroExpressDBAccess.AddSalePointProduct(newProduct); if (ViewBag.message == "yes") { return(RedirectToAction(nameof(Index))); } } foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { string errorme = error.ToString(); } } List <SalePoint> salePointList = new List <SalePoint>(); salePointList = AgroExpressDBAccess.GetSalePointListForUSer(HttpContext.User.Identity.Name); SalePointProductAdd salePointProductTransfer = new SalePointProductAdd(); salePointProductTransfer.salepointlist = salePointList.Select(x => new SelectListItem { Value = x.PKSalePointID.ToString(), Text = x.SalePointName }); List <ProductTransferInfo> PTI1 = new List <ProductTransferInfo>(); var MilkInfo = AgroExpressDBAccess.IsProductExist("Milk"); if (MilkInfo != null) { PTI1.Add(new ProductTransferInfo { ProductId = MilkInfo.PKProductId, Amount = null }); } else { Product MilkInfoAdd = new Product { ProductName = "Milk", SellingUnit = "Ltr", Stock = 0 }; AgroExpressDBAccess.AddProduct(MilkInfoAdd); MilkInfo = AgroExpressDBAccess.IsProductExist("Milk"); PTI1.Add(new ProductTransferInfo { ProductId = MilkInfo.PKProductId, Amount = 0 }); } // Product dropdown list var ProductInf = AgroExpressDBAccess.GetAllEnabledProduct(); ProductInf = ProductInf.Where(a => a.ProductName.ToLower() != "milk").ToList(); salePointProductTransfer.product = ProductInf.Select(x => new SelectListItem { Value = x.PKProductId.ToString(), Text = x.ProductName }); // int len1 = ProductInf.Count; for (int i = 0; i < len1; i++) { PTI1.Add(new ProductTransferInfo { ProductId = null, Amount = null }); } salePointProductTransfer.TransferedProductInfo = PTI1; return(View(salePointProductTransfer)); }
private ProductSaleAdd ProductSaleInitial() { string name = HttpContext.User.Identity.Name; ProductSaleAdd ProductSale = new ProductSaleAdd(); ProductSale.SaleDate = System.DateTime.UtcNow.AddHours(6); List <SalePoint> salePointList = new List <SalePoint>(); salePointList = AgroExpressDBAccess.GetSalePointListForUSer(name); if (salePointList != null) { ProductSale.salepointlist = salePointList.Select(x => new SelectListItem { Value = x.PKSalePointID.ToString(), Text = x.SalePointName }); } List <Area> arealist = AgroExpressDBAccess.GetallEnabledArea(); if (arealist != null) { arealist = arealist.Where(a => salePointList.Any(b => b.PKSalePointID == a.SalePointId)).ToList(); ProductSale.Area = arealist.Select(x => new SelectListItem { Value = x.PKAreaId.ToString(), Text = x.AreaName }); } List <SubArea> sarealist = AgroExpressDBAccess.GetallEnabledSubArea(); if (sarealist != null) { sarealist = sarealist.Where(a => arealist.Any(b => b.PKAreaId == a.AreaId)).ToList(); ProductSale.SubArea = sarealist.Select(x => new SelectListItem { Value = x.PKSubAreaId.ToString(), Text = x.SubAreaName }); } List <Product> productList = AgroExpressDBAccess.GetAllEnabledProduct(); List <ProductSaleInfo> PSI = new List <ProductSaleInfo>(); var MilkInfo = AgroExpressDBAccess.IsProductExist("Milk"); if (MilkInfo != null) { PSI.Add(new ProductSaleInfo { ProductId = MilkInfo.PKProductId, Amount = null, Rate = null, Servicecharge = null }); } else { Product MilkInfoAdd = new Product { ProductName = "Milk", SellingUnit = "Ltr", Stock = 0 }; AgroExpressDBAccess.AddProduct(MilkInfoAdd); MilkInfo = AgroExpressDBAccess.IsProductExist("Milk"); PSI.Add(new ProductSaleInfo { ProductId = MilkInfo.PKProductId, Amount = null, Rate = null, Servicecharge = null }); } // Product dropdown list productList = productList.Where(a => a.ProductName.ToLower() != "milk").ToList(); ProductSale.product = productList.Select(x => new SelectListItem { Value = x.PKProductId.ToString(), Text = x.ProductName }); // int len = productList.Count; for (int i = 0; i < len; i++) { PSI.Add(new ProductSaleInfo { ProductId = null, Amount = null, Rate = null, Servicecharge = 0 }); } ProductSale.ProductSaleInfo = PSI; List <Customer> customer = AgroExpressDBAccess.GetallEnabledCustomer(); customer = customer.Where(a => sarealist.Any(b => b.PKSubAreaId == a.SubAreaId)).ToList(); ProductSale.Customer = customer.Select(x => new SelectListItem { Value = x.PKCustomerId.ToString(), Text = x.FullName }); return(ProductSale); }