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(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));
        }