예제 #1
0
        public void Disable(int touristAttractionId)
        {
            var attraction = new TouristAttraction {
                Id = touristAttractionId, Active = false
            };

            context.TouristAttractions.Attach(attraction);
            context.Entry(attraction).Property(a => a.Active).IsModified = true;
            context.SaveChanges();
            //After update it will be needed to recreate the matrix

            _touristAttractionConnectionRepository.RecalculateConnections(attraction.Id);
        }
        public void Approve(TouristAttractionSuggestion suggestion, int approverId)
        {
            suggestion.Approved     = true;
            suggestion.AnsweredBy   = approverId;
            suggestion.AnsweredDate = DateTime.UtcNow;
            context.TouristAttractionSuggestions.Attach(suggestion);
            context.Entry(suggestion).Property(s => s.Rating).IsModified      = true;
            context.Entry(suggestion).Property(s => s.WebsiteUrl).IsModified  = true;
            context.Entry(suggestion).Property(s => s.AnsweredBy).IsModified  = true;
            context.Entry(suggestion).Property(s => s.Approved).IsModified    = true;
            context.Entry(suggestion).Property(s => s.PhoneNumber).IsModified = true;

            context.Entry(suggestion).Property(s => s.AnsweredDate).IsModified = true;

            //Creation of new touristic attraction
            var newAttraction = context.TouristAttractionSuggestions
                                .Where(s => s.Id == suggestion.Id)
                                .Select(s => new TouristAttraction
            {
                CreatedBy   = approverId,
                Active      = true,
                Address     = s.Address,
                CategoryId  = s.CategoryId,
                CityId      = s.CityId,
                Geoposition = new Geoposition {
                    Latitude = s.Geoposition.Latitude, Longitude = s.Geoposition.Longitude
                },
                GooglePlaceId = s.GooglePlaceId,
                Name          = s.Name,
                PhoneNumber   = suggestion.PhoneNumber,
                Rating        = suggestion.Rating,
                WebsiteUrl    = suggestion.WebsiteUrl
            }).First();

            context.TouristAttractions.Add(newAttraction);
            context.SaveChanges();
            //After save it will be needed to recreate the matrix
            _touristAttractionConnectionRepository.RecalculateConnections(newAttraction.Id);
        }