public static ModelPhoto AddPhoto(ModelPlace place, ModelUser user, string url, MainContext db) { if (!user.Equals(place.Author)) { throw new UnauthorizedAccessException(); } var photo = new ModelPhoto { Place = place, Url = url }; db.Photos.Add(photo); place.Photos.Add(photo); db.SaveChanges(); return(photo); }