public async Task <IActionResult> Create(ProductInOrderCreateViewModel vm)
        {
            if (ModelState.IsValid)
            {
                await _bll.ProductsInOrder.AddAsync(vm.ProductInOrder);

                await _bll.SaveChangesAsync();

                return(RedirectToAction("Index", "Orders"));
            }
            vm.OrderSelectList   = new SelectList(await _bll.Orders.AllAsyncByShop(User.GetShopId(), null, null, null, null), nameof(Order.Id), nameof(Order.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, ProductInOrderCreateViewModel vm)
        {
            if (id != vm.ProductInOrder.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _bll.ProductsInOrder.Update(vm.ProductInOrder);
                await _bll.SaveChangesAsync();

                return(RedirectToAction("Details", "Orders", new { id = vm.ProductInOrder.OrderId }));
            }

            vm.OrderSelectList   = new SelectList(await _bll.Orders.AllAsyncByShop(User.GetShopId(), null, null, null, null), nameof(Order.Id), nameof(Order.Description));
            vm.ProductSelectList = new SelectList(await _bll.Products.AllAsyncByShopForDropDown(User.GetShopId()), nameof(Product.Id), nameof(Product.ProductName));

            return(View(vm));
        }
        // GET: ProductsInOrder/Create
        public async Task <IActionResult> Create(int?id)
        {
            var vm = new ProductInOrderCreateViewModel()
            {
                OrderSelectList   = new SelectList(await _bll.Orders.AllAsync(), nameof(Order.Id), nameof(Order.Description)),
                ProductSelectList = new SelectList(await _bll.Products.AllAsync(), nameof(Product.Id), nameof(Product.ProductName))
            };

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

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

        // GET: ProductsInOrder/Create
        public async Task <IActionResult> Create(int?id)
        {
            var vm = new ProductInOrderCreateViewModel()
            {
                OrderSelectList   = new SelectList(await _bll.Orders.AllAsyncByShop(User.GetShopId(), null, null, null, null), nameof(Order.Id), nameof(Order.Description)),
                ProductSelectList = new SelectList(await _bll.Products.AllAsyncByShopForDropDown(User.GetShopId()), nameof(Product.Id), nameof(Product.ProductName))
            };


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

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

            var productInOrder = await _bll.ProductsInOrder.FindAsync(id);

            if (productInOrder == null)
            {
                return(NotFound());
            }
            var vm = new ProductInOrderCreateViewModel()
            {
                ProductInOrder    = productInOrder,
                OrderSelectList   = new SelectList(await _bll.Orders.AllAsyncByShop(User.GetShopId(), null, null, null, null), nameof(Order.Id), nameof(Order.Description)),
                ProductSelectList = new SelectList(await _bll.Products.AllAsyncByShopForDropDown(User.GetShopId()), nameof(Product.Id), nameof(Product.ProductName))
            };

            return(View(vm));
        }