public async Task <IActionResult> SetMainPhoto(int bikeId, int id) { var bike = await _bikeRepo.GetBike(bikeId); if (!bike.Photos.Any(p => p.Id == id)) { return(Unauthorized()); } var photoFromRepo = await _bikeRepo.GetPhoto(id); if (photoFromRepo.IsMain) { return(BadRequest("This is already the main photo")); } var currentMainPhoto = await _bikeRepo.GetMainPhotoForBike(bikeId); currentMainPhoto.IsMain = false; photoFromRepo.IsMain = true; if (await _bikeRepo.SaveAll()) { return(NoContent()); } return(BadRequest("Could not set photo to main")); }