public ActionResult GetStoreProductForDatatable(Guid?batchId)
        {
            // Guid guidBatchId = Guid.Parse(batchId);
            var storeProducts = _dbContext.StoreProducts.Where(s => s.BatchId == batchId).ToList();
            List <StoreProductsViewModel> storeProductsViewModelList = new List <StoreProductsViewModel>();

            foreach (var storeProduct in storeProducts)
            {
                StoreProductsViewModel storeProductViewModel = new StoreProductsViewModel();
                storeProductViewModel.Id = storeProduct.Id;
                storeProductViewModel.ProductEnterDate = storeProduct.ProductEnterDate;
                storeProductViewModel.MRPPerUnit       = storeProduct.MRPPerUnit;
                storeProductViewModel.ProductName      = storeProduct.Product.Name;
                storeProductViewModel.Quantity         = storeProduct.Quantity;
                storeProductsViewModelList.Add(storeProductViewModel);
            }

            var result = new
            {
                iTotalRecords        = storeProducts.Count,
                iTotalDisplayRecords = storeProducts.Count,
                aaData = storeProductsViewModelList
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult _Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StoreProduct           storeProduct = _dbContext.StoreProducts.Find(id);
            StoreProductsViewModel viewModel    = new StoreProductsViewModel();

            viewModel.Id               = storeProduct.Id;
            viewModel.BatchId          = storeProduct.BatchId;
            viewModel.BatchNumber      = storeProduct.BatchNumber;
            viewModel.CostPricePerUnit = storeProduct.CostPricePerUnit;
            viewModel.Quantity         = storeProduct.Quantity;
            viewModel.MRPPerUnit       = storeProduct.MRPPerUnit;
            viewModel.ProductEnterDate = storeProduct.ProductEnterDate;
            viewModel.ProductName      = storeProduct.Product.Name;
            viewModel.Code             = storeProduct.Product.Code;
            if (storeProduct == null)
            {
                return(HttpNotFound());
            }
            string modelString = RenderRazorViewToString("_Edit", viewModel);

            //ViewBag.BatchId = new SelectList(_dbContext.Batch, "Id", "Name", storeProduct.BatchId);
            return(Json(new { ModelString = modelString }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetStoreProductsForAutocomplete(string term, Guid batchId)
        {
            Product[] productsMatching = String.IsNullOrWhiteSpace(term) ? null
                : _dbContext.Products.Where(ii => ii.Code.Contains(term) || ii.Name.Contains(term)).ToArray();
            List <StoreProductsViewModel> storeProductsViewModelList = new List <StoreProductsViewModel>();


            foreach (var storeProducts in productsMatching.ToList())
            {
                foreach (var storeProduct in storeProducts.StoreProducts.Where(b => b.BatchId == batchId))
                {
                    StoreProductsViewModel storeProductsViewModel = new StoreProductsViewModel();
                    storeProductsViewModel.Id               = storeProduct.Id;
                    storeProductsViewModel.Code             = storeProducts.Code;
                    storeProductsViewModel.AutoGenerateName = storeProducts.AutoGenerateName;
                    storeProductsViewModel.MRPPerUnit       = storeProduct.Product.SalePrice;
                    storeProductsViewModelList.Add(storeProductsViewModel);
                }
            }

            return(Json(storeProductsViewModelList.Select(m => new
            {
                Id = m.Id,
                value = m.ProductName,
                label = String.Format("{0}: {1}: {2}", m.AutoGenerateName, m.Code, m.MRPPerUnit),
                MRPPerUnit = m.MRPPerUnit,
                Name = m.ProductName,
                Code = m.Code,
                AutoGenerateName = m.AutoGenerateName,
                ModelNumber = m.ModelNumber
            }), JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StoreProduct           storeProduct = _dbContext.StoreProducts.Find(id);
            StoreProductsViewModel viewModel    = new StoreProductsViewModel();

            viewModel.Id               = storeProduct.Id;
            viewModel.BatchId          = storeProduct.BatchId;
            viewModel.StoreId          = storeProduct.Batch.StoreId;
            viewModel.BatchNumber      = storeProduct.BatchNumber;
            viewModel.CostPricePerUnit = storeProduct.CostPricePerUnit;
            viewModel.Quantity         = storeProduct.Quantity;
            viewModel.MRPPerUnit       = storeProduct.MRPPerUnit;
            viewModel.ProductEnterDate = storeProduct.ProductEnterDate;
            viewModel.ProductId        = storeProduct.Product.Id;
            viewModel.ProductName      = storeProduct.Product.Name;
            viewModel.Code             = storeProduct.Product.Code;
            // viewModel.SalePrice = storeProduct.SalePrice;
            if (storeProduct == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Batches = new SelectList(_dbContext.Batch, "Id", "Name", storeProduct.BatchId);
            ViewBag.Stores  = new SelectList(_dbContext.Stores, "Id", "Name", storeProduct.Batch.StoreId);
            return(View(viewModel));
        }
        public ActionResult GetBatchesForDatatable()
        {
            var batches = _dbContext.Batch.ToList();
            List <BatchViewModel> batchViewModelList = new List <BatchViewModel>();

            foreach (var batch in batches)
            {
                BatchViewModel batchViewModel = new BatchViewModel();
                batchViewModel.Id          = batch.Id;
                batchViewModel.Name        = batch.Name;
                batchViewModel.EnteredDate = batch.EnteredDate;
                batchViewModelList.Add(batchViewModel);
                List <StoreProductsViewModel> storeProductsViewModelList = new List <StoreProductsViewModel>();
                foreach (var storeProduct in batch.StoreProducts)
                {
                    StoreProductsViewModel storeProductsViewModel = new StoreProductsViewModel();
                    storeProductsViewModel.Id          = storeProduct.Id;
                    storeProductsViewModel.ProductName = storeProduct.Product.Name;
                    storeProductsViewModel.Quantity    = storeProduct.Quantity;
                    storeProductsViewModelList.Add(storeProductsViewModel);
                }
                batchViewModel.StoreProductsViewModel = storeProductsViewModelList;
            }

            //     var jsonObject = JsonConvert.SerializeObject(ProductViewModelList);
            // return View();
            var result = new
            {
                iTotalRecords        = batches.Count,
                iTotalDisplayRecords = batches.Count,
                aaData = batchViewModelList
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #6
0
        public ActionResult IndexFullHeight()
        {
            StoreIndexViewModel   storeIndexViewModel = new StoreIndexViewModel();
            List <StoreViewModel> storeViewModelLst   = new List <StoreViewModel>();
            var stores   = db.Stores.ToList();
            var products = db.Products.ToList();

            foreach (var store in stores)
            {
                StoreViewModel storeViewModel = new StoreViewModel();
                storeViewModel.Id   = store.Id;
                storeViewModel.Name = store.Name;
                storeViewModelLst.Add(storeViewModel);
                List <BatchViewModel> batchesViewModelLst = new List <BatchViewModel>();
                foreach (var batch in store.Batches)
                {
                    BatchViewModel batchViewModel = new BatchViewModel();
                    batchViewModel.Id          = batch.Id;
                    batchViewModel.StoreId     = batch.StoreId;
                    batchViewModel.Name        = batch.Name;
                    batchViewModel.EnteredDate = batch.EnteredDate;
                    batchesViewModelLst.Add(batchViewModel);
                    List <StoreProductsViewModel> storeProductsViewModelLst = new List <StoreProductsViewModel>();
                    if (batch.StoreProducts.Count != 0)
                    {
                        foreach (var storeProduct in batch.StoreProducts)
                        {
                            StoreProductsViewModel storeProductsViewModel = new StoreProductsViewModel();
                            storeProductsViewModel.Id               = storeProduct.Id;
                            storeProductsViewModel.BatchId          = storeProduct.BatchId;
                            storeProductsViewModel.ProductId        = storeProduct.ProductId;
                            storeProductsViewModel.ProductEnterDate = storeProduct.ProductEnterDate;
                            Product product = products.Where(p => p.Id == storeProduct.ProductId).FirstOrDefault();
                            storeProductsViewModel.ProductName         = product.Name;
                            storeProductsViewModel.AutoGenerateName    = product.AutoGenerateName;
                            storeProductsViewModel.Code                = product.Code;
                            storeProductsViewModel.ModelNumber         = product.ModelNumber;
                            storeProductsViewModel.MRPPerUnit          = storeProduct.MRPPerUnit;
                            storeProductsViewModel.CostPricePerUnit    = storeProduct.CostPricePerUnit;
                            storeProductsViewModel.DiscountRatePerUnit = storeProduct.DiscountRatePerUnit;
                            storeProductsViewModel.Quantity            = storeProduct.Quantity;
                            storeProductsViewModelLst.Add(storeProductsViewModel);
                            //batchViewModel.StoreProductsViewModel.Add(storeProductsViewModel);
                        }
                    }
                    batchViewModel.StoreProductsViewModel = storeProductsViewModelLst;
                }
                storeViewModel.BatchesViewModel = batchesViewModelLst;
            }
            storeIndexViewModel.StoreViewModel = storeViewModelLst;
            return(View(storeIndexViewModel));
        }
 public ActionResult Edit(StoreProductsViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         StoreProduct storeProduct = _dbContext.StoreProducts.Find(viewModel.Id);
         storeProduct.ProductId               = viewModel.ProductId;
         storeProduct.BatchId                 = viewModel.BatchId;
         storeProduct.CostPricePerUnit        = viewModel.CostPricePerUnit;
         storeProduct.MRPPerUnit              = storeProduct.MRPPerUnit;
         storeProduct.Quantity                = viewModel.Quantity;
         _dbContext.Entry(storeProduct).State = EntityState.Modified;
         _dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BatchId = new SelectList(_dbContext.Batch, "Id", "Name", viewModel.BatchId);
     ViewBag.Stores  = new SelectList(_dbContext.Stores, "Id", "Name", viewModel.StoreId);
     return(View(viewModel));
 }
 public ActionResult Create(StoreProductsViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         StoreProduct storeProduct = new StoreProduct();
         storeProduct.Id               = Guid.NewGuid();
         storeProduct.BatchId          = viewModel.BatchId;
         storeProduct.CostPricePerUnit = viewModel.CostPricePerUnit;
         storeProduct.Quantity         = viewModel.Quantity;
         storeProduct.CostPricePerUnit = viewModel.CostPricePerUnit;
         storeProduct.MRPPerUnit       = viewModel.MRPPerUnit;
         storeProduct.ProductEnterDate = viewModel.ProductEnterDate;
         storeProduct.ProductId        = viewModel.ProductId;
         //   storeProduct.SalePrice = viewModel.SalePrice;
         _dbContext.StoreProducts.Add(storeProduct);
         _dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Batches = new SelectList(_dbContext.Batch, "Id", "Name");
     ViewBag.Stores  = new SelectList(_dbContext.Stores, "Id", "Name");
     return(View(viewModel));
 }
        public ActionResult Index()
        {
            ViewBag.Batches  = new SelectList(_dbContext.Batch, "Id", "Name");
            ViewBag.Stores   = new SelectList(_dbContext.Stores, "Id", "Name");
            ViewBag.Contacts = new SelectList(_dbContext.Contacts, "Id", "FullName");

            var storeProducts = _dbContext.StoreProducts.OrderBy(d => d.CreatedDate).ToList();
            List <StoreProductsViewModel>        storeProductsViewModelList = new List <StoreProductsViewModel>();
            IEnumerable <StoreProductsViewModel> storeProductsViewModelEnu;

            foreach (var storeProduct in storeProducts)
            {
                StoreProductsViewModel viewModel = new StoreProductsViewModel();
                viewModel.Id               = storeProduct.Id;
                viewModel.ProductName      = storeProduct.Product.Name;
                viewModel.ProductEnterDate = storeProduct.ProductEnterDate;
                viewModel.Quantity         = storeProduct.Quantity;
                viewModel.BatchNumber      = storeProduct.Batch.Name;
                viewModel.AutoGenerateName = storeProduct.Product.AutoGenerateName;
                storeProductsViewModelList.Add(viewModel);
            }
            storeProductsViewModelEnu = storeProductsViewModelList;
            return(View(storeProductsViewModelEnu));
        }