예제 #1
0
        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);
        }
예제 #2
0
        public static ModelPlace CreatePlace(string name, string description, string address, double latitude,
                                             double longitude, ModelUser loggedUser,
                                             MainContext db)
        {
            var place = new ModelPlace
            {
                Name        = name,
                Description = description,
                Address     = address,
                Author      = loggedUser,
                Latitude    = latitude,
                Longitude   = longitude
            };

            loggedUser.OwnedPlaces.Add(place);
            db.Places.Add(place);
            db.SaveChanges();
            return(place);
        }
예제 #3
0
        public static ModelPhoto GetPhotoById(int?placeId, int?photoId, MainContext db)
        {
            ModelPlace place = GetPlaceById(placeId, db);

            if (place == null)
            {
                return(null);
            }
            var photos = from modelPhoto in db.Photos where modelPhoto.PhotoId == photoId select modelPhoto;

            if (!photos.Any())
            {
                return(null);
            }
            if (photos.Count() > 1)
            {
                throw new InDataError();
            }
            if (!place.Photos.Contains(photos.First()))
            {
                throw new NotContaining();
            }
            return(photos.First());
        }