public async Task <IActionResult> CreateCategory(string name, string description, List <IFormFile> images) { // If the user sends `images` POST param then the list<IFormFile> will be populated, if the user sends `images[]` instead, then it will be empty // this is why I populate that list with this little trick if (images?.Count == 0) { images = Request.Form.Files.GetFiles("images[]").ToList(); } Category category = await _categoriesService.Create(name, description, images, Convert.ToInt64(_usersService.GetCurrentUserId())); return(StatusCodeAndDtoWrapper.BuildSuccess(CategoryDto.Build(category), "Category created successfully")); }
public static HomeResponse Build(List <Entities.Tag> tags, List <Entities.Category> categories) { List <TagDto> tagDtos = new List <TagDto>(tags.Count); List <CategoryDto> categoryDtos = new List <CategoryDto>(tags.Count); foreach (var tag in tags) { tagDtos.Add(TagDto.Build(tag)); } foreach (var category in categories) { categoryDtos.Add(CategoryDto.Build(category)); } return(new HomeResponse { Tags = tagDtos, Categories = categoryDtos }); }