public async Task <IActionResult> CategoryOneAddAsync(FormCategory c, List <FormCategory> SubCategorys) { var category = new CategoryOne() { CategoryOneId = c.Id, Icon = c.Icon, Name = c.Name, url = c.url }; if (c.File != null) { category.ImgUrl = await FilesSave.FileSave(rootPath, @"\Upload\Category\", c.File); } else { category.ImgUrl = c.ImgUrl; } if (SubCategorys != null) { var SubC = new List <Category>(); foreach (var item in SubCategorys) { var cs = new Category() { CategoryId = item.Id, Icon = item.Icon, Name = item.Name, url = item.url }; if (item.File != null) { cs.ImgUrl = await FilesSave.FileSave(rootPath, @"\Upload\Category\", item.File); } else { cs.ImgUrl = item.ImgUrl; } SubC.Add(cs); } category.SubCategory = SubC; } if (c.Id == 0) { await _CategoryText.CategoryOneAddAsync(category); } else { await _CategoryText.CategoryOneAddAsync(category, c.Id); } return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> SubCategoryAddAsync(int id, List <FormCategory> SubCategorys) { var sc = new List <Category>(); foreach (var item in SubCategorys) { var ImgUrl = item.ImgUrl; if (item.File != null) { ImgUrl = await FilesSave.FileSave(rootPath, @"\Upload\Category\", item.File); } sc.Add(new Category { CategoryId = item.Id, Icon = item.Icon, Name = item.Name, url = item.url, ImgUrl = ImgUrl }); } await _CategoryText.CategoryOneAddAsync(sc, id); return(RedirectToAction("Index", "Home")); }