public IActionResult Create() { var model = new AddingItemViewModel { DisplayingCategories = unitOfWork.ItemRepository.GetAllCategories() }; return(View(model)); }
public async Task <IActionResult> Add(AddingItemViewModel model) { if (!ModelState.IsValid) { model.DisplayingCategories = unitOfWork.ItemRepository.GetAllCategories(); return(View("Create", model)); } var item = mapper.Map <Item>(model); item.UserId = User.FindFirstValue(ClaimTypes.NameIdentifier); item.Images = (await ImagesSaver.SaveFormImages(model.Cover, model.Images, Path.Combine(environment.WebRootPath, configuration.Value.ImagesFolder))).ToList(); item.Categories = unitOfWork.ItemRepository.GetCategoriesByCollectionId(model.CategoriesIds).ToList(); unitOfWork.ItemRepository.Add(item); unitOfWork.Complete(); return(Redirect("/")); }