public async Task <ActionResult> Upload(int?roomId, int?profileId, IFormFile file) // If I want many files use IFormFileCollection { //host.IsDevelopment() // Check if it is devoloment for crate other Directory for test if (file == null) { return(BadRequest("Null File")); } if (file.Length == 0) { return(BadRequest("Empty File")); } if (file.Length > MAX_BYTES) { return(BadRequest("Max file size exceeded")); } if (ACCEPTED_FILE_TYPE.Any(a => a == Path.GetExtension(file.FileName).ToLower())) { return(BadRequest("Invalid file type")); } if (roomId.HasValue) { // Code upload photo room var room = await roomService.GetRoom(roomId.Value); if (room == null) { return(NotFound()); } var photo = photoService.UploadPhoto(file, host); await roomService.AddPhoto(roomId.Value, photo); await uow.CompleteAsync(); var photoResource = mapper.Map <Photo, PhotoResource>(photo); return(Ok(photoResource)); } else if (profileId.HasValue) { // Code upload photo profile var profile = await profileService.GetProfile(profileId.Value); if (profile == null) { return(NotFound()); } var photo = photoService.UploadPhoto(file, host); await profileService.AddPhoto(profileId.Value, photo); await uow.CompleteAsync(); var photoResource = mapper.Map <Photo, PhotoResource>(photo); return(Ok(photoResource)); } else { return(NotFound()); } }