public IActionResult AddSubCategory() { var model = new AddSubCategoryVM { _lista = _database.category.Select(e => new SelectListItem { Value = e.CategoryID.ToString(), Text = e.CategoryName }).ToList() }; _database.Add(new AdminActivity { ActivityID = 3, AdminID = Int32.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)), DateOfActivity = DateTime.Now }); _database.SaveChanges(); return(View(model)); }
public IActionResult SaveSubCategory(AddSubCategoryVM model) { string uniquefileName = null; if (model.Image != null) { string uploadsFolder = Path.Combine(hosting.WebRootPath, "images"); uniquefileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName; string filePath = Path.Combine(uploadsFolder, uniquefileName); model.Image.CopyTo(new FileStream(filePath, FileMode.Create)); } SubCategory subcategory = new SubCategory { SubCategoryName = model.subcategoryName, CategoryID = model.categoryID, ImageUrl = uniquefileName }; _Iproduct.AddSubCategory(subcategory); return(Redirect("/Administration/Index")); }