public IActionResult SetIndexProductsToCostCenter(long?id)
        {
            if (id == null)
            {
                _toastNotification.AddErrorToastMessage("Need to select a Base Unit", new ToastrOptions
                {
                    PositionClass = ToastPositions.TopCenter
                });
                return(RedirectToAction(nameof(ListCostCenter)));
            }

            var costCenter = _farm.GetCostCenterById(id.Value);

            var model = new ProductCostCenterViewModel
            {
                CostCenterId = costCenter.Id,
                Name         = _farm.GetCostCenterProductName(costCenter.Id),
                Active       = _farm.GetCostCenterProductActive(costCenter.Id)
            };

            model.Products = _farm.GetSelectListProducts(costCenter.Id);
            ViewBag.Name   = costCenter.Name;
            ViewBag.Code   = costCenter.Code;
            return(View(model));
        }
        public IActionResult AddProductsToCostCenter()
        {
            var products = new ProductCostCenterViewModel();
            var list     = (List <SelectListItem>)_farm.GetProducts().Select(x => new SelectListItem
            {
                Value = x.Name,
                Text  = x.Name
            });

            list.Add(new SelectListItem {
                Text = "Select a Product", Value = string.Empty, Selected = true
            });
            products.Products = list;
            return(View(products));
        }
        public IActionResult SetIndexProductsToCostCenterPost(ProductCostCenterViewModel model
                                                              , params string[] selectedProducts)
        {
            if (!selectedProducts.Any())
            {
                _toastNotification.AddWarningToastMessage("Need to select a product", new ToastrOptions
                {
                    PositionClass = ToastPositions.TopCenter
                });
                var costCenter2 = _farm.GetCostCenterById(model.CostCenterId);
                model.Products = _farm.GetSelectListProducts(costCenter2.Id);
                ViewBag.Name   = costCenter2.Name;
                ViewBag.Code   = costCenter2.Code;

                return(View(nameof(AddProductsToCostCenter), model));
            }

            var farm = _farm.AddProductsToCostCenter(model, GetCurrentUserAsync().Result.UserName, selectedProducts)
                       .Result;

            if (farm.Succeeded)
            {
                _toastNotification.AddSuccessToastMessage(farm.OkMessage, new ToastrOptions
                {
                    PositionClass = ToastPositions.TopCenter
                });
                return(RedirectToAction(nameof(ListCostCenter)));
            }

            _toastNotification.AddWarningToastMessage(farm.Errors, new ToastrOptions
            {
                PositionClass = ToastPositions.TopCenter
            });
            var costCenter = _farm.GetCostCenterById(model.CostCenterId);

            model.Products = _farm.GetSelectListProducts(costCenter.Id);
            ViewBag.Name   = costCenter.Name;
            ViewBag.Code   = costCenter.Code;
            return(View(nameof(AddProductsToCostCenter), model));
        }