public IActionResult AddBrand(AdminBrandViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                string username = User.Identity.Name;

                Store store = _user.GetUserStore(username);

                if (!_store.ExistsBrand(viewModel.Name))
                {
                    if (viewModel.Img != null)
                    {
                        if (Path.GetExtension(viewModel.Img.FileName) != ".jpg")
                        {
                            ModelState.AddModelError("Img", "فایل با پسوند jpg بارگزاری شود");
                        }
                        else
                        {
                            string filePath = "";
                            viewModel.ImgName = CodeGenerators.FileCode() + Path.GetExtension(viewModel.Img.FileName);
                            filePath          = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/brands/", viewModel.ImgName);

                            using (var stream = new FileStream(filePath, FileMode.Create))
                            {
                                viewModel.Img.CopyTo(stream);
                            }

                            Brand brand = new Brand()
                            {
                                Img     = viewModel.ImgName,
                                Name    = viewModel.Name,
                                NotShow = true,
                                StoreId = store.UserId
                            };

                            _store.AddBrand(brand);

                            return(RedirectToAction(nameof(ShowBrands)));
                        }
                    }
                    else
                    {
                        Brand brand = new Brand()
                        {
                            Img     = null,
                            Name    = viewModel.Name,
                            NotShow = true,
                            StoreId = store.UserId
                        };

                        _store.AddBrand(brand);

                        return(RedirectToAction(nameof(ShowBrands)));
                    }
                }
            }

            return(View(viewModel));
        }
        public IActionResult EditBrand(int id)
        {
            Brand brand = _admin.GetBrand(id);

            AdminBrandViewModel viewModel = new AdminBrandViewModel()
            {
                Name    = brand.Name,
                ImgName = brand.Img,
                NotShow = brand.NotShow
            };

            return(View(viewModel));
        }
        public IActionResult EditBrand(AdminBrandViewModel viewModel, int id)
        {
            if (ModelState.IsValid)
            {
                Brand brand = _admin.GetBrand(id);

                if (viewModel.Img != null)
                {
                    if (Path.GetExtension(viewModel.Img.FileName) != ".jpg")
                    {
                        ModelState.AddModelError("Img", "فایل با پسوند jpg بارگزاری شود");
                    }
                    else
                    {
                        string filePath = "";
                        viewModel.ImgName = CodeGenerators.FileCode() + Path.GetExtension(viewModel.Img.FileName);
                        filePath          = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/brands/", viewModel.ImgName);

                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            viewModel.Img.CopyTo(stream);
                        }

                        _admin.UpdateBrand(id, viewModel.Name, viewModel.ImgName, viewModel.NotShow);

                        return(RedirectToAction(nameof(ShowBrands)));
                    }
                }
                else
                {
                    _admin.UpdateBrand(id, viewModel.Name, brand.Img, viewModel.NotShow);

                    return(RedirectToAction(nameof(ShowBrands)));
                }
            }

            return(View(viewModel));
        }