public async Task <IActionResult> Create(ProductWithDefectCreateViewModel vm)
        {
            if (ModelState.IsValid)
            {
                await _bll.ProductsWithDefect.AddAsync(vm.ProductWithDefect);

                await _bll.SaveChangesAsync();

                return(RedirectToAction("Index", "Defects"));
            }
            vm.DefectSelectList  = new SelectList(await _bll.Defects.AllAsyncByShop(User.GetShopId(), null, null, null, null), nameof(Defect.Id), nameof(Defect.Description));
            vm.ProductSelectList = new SelectList(await _bll.Products.AllAsyncByShopForDropDown(User.GetShopId()), nameof(Product.Id), nameof(Product.ProductName));

            return(View(vm));
        }
        public async Task <IActionResult> Edit(int id, ProductWithDefectCreateViewModel vm)
        {
            if (id != vm.ProductWithDefect.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _bll.ProductsWithDefect.Update(vm.ProductWithDefect);
                await _bll.SaveChangesAsync();

                return(RedirectToAction("Details", "Defects", new { id = vm.ProductWithDefect.DefectId }));
            }
            vm.DefectSelectList  = new SelectList(await _bll.Defects.AllAsyncByShop(User.GetShopId(), null, null, null, null), nameof(Defect.Id), nameof(Defect.Description));
            vm.ProductSelectList = new SelectList(await _bll.Products.AllAsyncByShopForDropDown(User.GetShopId()), nameof(Product.Id), nameof(Product.ProductName));

            return(View(vm));
        }
        // GET: ProductsWithDefect

        /*  public async Task<IActionResult> Index()
         * {
         *    var productWithDefect = await _bll.ProductsWithDefect.AllAsyncByShop(User.GetShopId());
         *    return View(productWithDefect);
         * }
         *
         * // GET: ProductsWithDefect/Details/5
         * public async Task<IActionResult> Details(int? id)
         * {
         *    if (id == null)
         *    {
         *        return NotFound();
         *    }
         *
         *    var productWithDefect = await _bll.ProductsWithDefect.FindAsync(id);
         *    if (productWithDefect == null)
         *    {
         *        return NotFound();
         *    }
         *
         *    return View(productWithDefect);
         * }*/

        // GET: ProductsWithDefect/Create
        public async Task <IActionResult> Create(int?id)
        {
            var vm = new ProductWithDefectCreateViewModel()
            {
                DefectSelectList  = new SelectList(await _bll.Defects.AllAsyncByShop(User.GetShopId(), null, null, null, null), nameof(Defect.Id), nameof(Defect.Description)),
                ProductSelectList = new SelectList(await _bll.Products.AllAsyncByShopForDropDown(User.GetShopId()), nameof(Product.Id), nameof(Product.ProductName))
            };

            foreach (var defect in vm.DefectSelectList)
            {
                if (!defect.Value.Equals(id.ToString()))
                {
                    continue;
                }
                defect.Selected = true;
                break;
            }

            return(View(vm));
        }
        // GET: ProductsWithDefect/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var productWithDefect = await _bll.ProductsWithDefect.FindAsync(id);

            if (productWithDefect == null)
            {
                return(NotFound());
            }

            var vm = new ProductWithDefectCreateViewModel()
            {
                ProductWithDefect = productWithDefect,
                DefectSelectList  = new SelectList(await _bll.Defects.AllAsyncByShop(User.GetShopId(), null, null, null, null), nameof(Defect.Id), nameof(Defect.Description)),
                ProductSelectList = new SelectList(await _bll.Products.AllAsyncByShopForDropDown(User.GetShopId()), nameof(Product.Id), nameof(Product.ProductName))
            };

            return(View(vm));
        }