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)); }