public List <Photo> Add(PhotoRechercheViewModel prvm) { if (!prvm.Photos.Any()) { return(null); } var photos = new List <Photo>(); foreach (var p in prvm.Photos.Where(_ => _ != null)) { var photo = FileManagerService.Upload(p); if (photo == null) { return(null); } if (prvm.Recherche != null) { if (photo.Recherches == null) { photo.Recherches = new List <Recherche>(); } photo.Recherches.Add(db.Recherches.Find(prvm.Recherche.Id)); } if (prvm.Animal != null) { photo.Animal = db.Animaux.Find(prvm.Animal.Id); } db.Photos.Add(photo); photos.Add(photo); } db.SaveChanges(); return(photos); }
public List <Photo> UpdatePhotosAnimal(PhotoRechercheViewModel prvm) { return(Add(prvm)); }