public ActionResult LocationIndoorNew(string countryUrlPart, string areaNameUrlPart, LocationIndoorNewViewModel m) { PerformLocationAddValidation(areaNameUrlPart, m.Latitude, m.Longitude, m.Name, AppLookups.Country(countryUrlPart), true); if (ModelState.IsValid) { var location = geoSvc.CreateLocationIndoor(new LocationIndoor() { Address = m.Address, MapAddress = m.Address, CountryID = m.CountryID, Latitude = m.Latitude, Longitude = m.Longitude, Name = m.Name, Website = m.Website, TypeID = m.TypeID }); return(Redirect(location.SlugUrl)); } else { var country = AppLookups.Country(countryUrlPart); ViewBag.Country = country; var area = new GeoService().GetArea(country.ID, areaNameUrlPart); ViewBag.Area = area; ViewBag.ExistingLocations = new GeoService().GetLocationsOfArea(area.ID).Where( a => a.Type == CfType.CommercialIndoorClimbing || a.Type == CfType.PrivateIndoorClimbing).ToList(); return(View(m)); } }
private void UpdateRatedObject(Guid id, List <Opinion> allOpinions) { var cacheEntry = AppLookups.GetCacheIndexEntry(id); if (cacheEntry.Type == CfType.ClimbOutdoor || cacheEntry.Type == CfType.ClimbIndoor) { UpdateOpinion <ClimbRepository, Climb>(id, allOpinions); } else if (cacheEntry.Type == CfType.ClimbingArea || cacheEntry.Type == CfType.Province || cacheEntry.Type == CfType.City) { UpdateOpinion <AreaRepository, Area>(id, allOpinions); } else if (cacheEntry.Type.ToPlaceCateogry() == PlaceCategory.IndoorClimbing) { UpdateOpinion <LocationIndoorRepository, LocationIndoor>(id, allOpinions); } else if (cacheEntry.Type.ToPlaceCateogry() == PlaceCategory.OutdoorClimbing) { UpdateOpinion <LocationOutdoorRepository, LocationOutdoor>(id, allOpinions); } else { throw new NotImplementedException("UpdateRatedObject does not yet support type : " + cacheEntry.Type.ToString()); } }
public ActionResult Detail(Guid id) { var pc = pcSvc.GetPartnerCallById(id); if (pc != null) { ViewBag.PartnerCall = pc; var place = AppLookups.GetCacheIndexEntry(pc.PlaceID); var model = PrepareNewCallViewData(place); ViewBag.Post = new PostService().GetPostByID(id); ViewBag.PlaceEntry = place; return(View(model)); } else { var pcwi = pcSvc.GetPartnerCallWorkItemByPartnerCallId(id); if (pcwi == null) { return(View("PageNotFound")); } else { return(RedirectToRoute("UserProfile", new { id = pcwi.OnBehalfOfUserID })); } } }
public Message GetLocation(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } Guid locID = Guid.ParseExact(id, "N"); //-- TODO, check cache var loc = AppLookups.GetCacheIndexEntry(locID); if (loc.Type.ToPlaceCateogry() == PlaceCategory.IndoorClimbing) { var l = geoSvc.GetLocationIndoorByID(loc.ID); return(ReturnAsJson(new LocationIndoorDetailDto(l))); } else if (loc.Type.ToPlaceCateogry() == PlaceCategory.OutdoorClimbing) { var l = geoSvc.GetLocationOutdoorByID(loc.ID); return(ReturnAsJson(new LocationOutdoorDetailDto(l))); } else { return(Failed("Service not invoked correctly - ID not valid for operation")); } }
public Message GetClimb(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } Guid climbID = Guid.ParseExact(id, "N"); ////-- TODO, check cache var climb = AppLookups.GetCacheIndexEntry(climbID); if (climb.Type == CfType.ClimbIndoor) { var c = geoSvc.GetIndoorClimbByID(climb.ID); return(ReturnAsJson(new ClimbIndoorDetailDto(c))); } else if (climb.Type == CfType.ClimbOutdoor) { var c = geoSvc.GetOutdoorClimbByID(climb.ID); return(ReturnAsJson(new ClimbOutdoorDetailDto(c))); } else { return(Failed("Service not invoked correctly - ID not valid for operation")); } }
public Message GetClimbsOfLocationAtCheckIn(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } try { Guid ciID = Guid.ParseExact(id, "N"); var ci = new VisitsService().GetCheckInById(ciID); if (ci == null) { throw new Exception("Visit does not exist, it may have been deleted."); } ////-- TODO, check cache var loc = AppLookups.GetCacheIndexEntry(ci.LocationID); var dto = GetClimbsOfLocation(loc, ci.Utc); return(ReturnAsJson(dto)); } catch (Exception ex) { return(Failed("Could not get climbs for visit: " + ex.Message)); } }
public Message GetUsersOpinions(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } Guid userID = Guid.ParseExact(id, "N"); var dto = new List <OpinionDto>(); var latestOpinions = new ContentService().GetUsersLatestOpinions(userID, 30); var profile = CfPerfCache.GetClimber(userID); foreach (var m in latestOpinions) { var obj = AppLookups.GetCacheIndexEntry(m.ObjectID); if (obj != null) { dto.Add(new OpinionDto(m.ID, m.Rating, m.Utc, obj.Name, m.UserID, profile.Avatar, m.Comment)); } } return(ReturnAsJson(dto)); }
/// <summary> /// Get distinct, no-null list of deduc CacheIndexEntry for a given set of place ids /// </summary> /// <param name="placeIDs"></param> /// <returns></returns> private List <CfCacheIndexEntry> GetGeoDeducPlaces(IEnumerable <Guid> placeIDs) { var geoDeduciblePlaces = new List <CfCacheIndexEntry>(); foreach (var id in placeIDs) { var place = CfCacheIndex.Get(id); if (place != null) { //-- Have to add if check for opinions of provinces bug if (place.Type == CfType.Province) { geoDeduciblePlaces.Add(place); } else { geoDeduciblePlaces.AddRange(CfPerfCache.GetGeoDeduciblePlaces(place)); } } } var feedPlaceIDs = geoDeduciblePlaces.Select(p => p.ID).Distinct().ToList(); return((from c in feedPlaceIDs where AppLookups.GetCacheIndexEntry(c) != null select AppLookups.GetCacheIndexEntry(c)).ToList()); }
public CheckIn CreateCheckIn(CheckIn visit) { var user = usrRepo.GetByID(CfIdentity.UserID); var place = AppLookups.GetCacheIndexEntry(visit.LocationID); if (place == null) { throw new ArgumentException("Unable to check in - No location found for " + visit.LocationID); } visit.ID = Guid.NewGuid(); visit.UserID = user.ID; if (visit.Latitude.HasValue && visit.Longitude.HasValue) { //-- It's a verified check-in, let's do something } //-- TODO check the person isn't checking in again within 1 hour to the same location var ci = checkInRepo.Create(visit); postSvc.CreateCheckInPost(ci, user.PrivacyPostsDefaultIsPublic); if (!user.PlaceMostRecentUtc.HasValue || ci.Utc > user.PlaceMostRecentUtc.Value) { user.PlaceMostRecent = visit.LocationID; user.PlaceMostRecentUtc = visit.Utc; usrRepo.Update(user); } return(ci); }
/// <summary> /// /// </summary> /// <param name="obj"></param> /// <returns></returns> public LocationOutdoor CreateLocationOutdoor(LocationOutdoor obj) { var user = CfPerfCache.GetClimber(CfIdentity.UserID); CreateLocationOutdoorAuthorization(obj); obj.NameUrlPart = obj.Name.ToUrlFriendlyString(); locOutdoorRepo.Create(obj); var modPlaceDetail = objModMetaRepo.Create(new ObjectModMeta(obj, currentUser.UserID)); //-- Update the cache AppLookups.AddIndexEntryToCache(obj.ToCacheIndexEntry()); ClaimObject(obj); //-- Save post for the feed //PostService.CreateLocationCreatedPost(obj); var action = SaveModActionAndUpdateModProfile(ModActionType.LocationOutdoorAdd, null, obj, modPlaceDetail, (m, actionID) => m.SetCreated(actionID), mp => mp.PlacesAdded++, "added {0} {1}", obj.Type, obj.Name); postSvc.CreateContentAddPost(action, obj.ID, user.PrivacyPostsDefaultIsPublic); //-- Shoot off a notification to moderators return(obj); }
/// <summary> /// /// </summary> /// <remarks>Called by the parent methods CreateClimbIndoor & CreateClimbOutdoor</remarks> private ObjectModMeta CreateClimb <T>(T obj, List <int> categories, CfType climbType, Action saveClimbToDB) where T : Climb { CreateClimbAuthorization(obj, categories); obj.ID = Guid.NewGuid(); obj.TypeID = (byte)climbType; obj.NameUrlPart = obj.Name.ToUrlFriendlyString(); if (obj.NameShort == null) { obj.NameShort = string.Empty; } if (obj.SetterID == Guid.Empty) { obj.SetterID = null; } obj.GradeCfNormalize = GradeConvert(obj.GradeLocal); //-- Add climb category/tags if (categories.Count > 0) { foreach (var c in categories) { obj.ClimbTags.Add(new ClimbTag(obj.ID, c)); } } saveClimbToDB(); var meta = objModMetaRepo.Create(new ObjectModMeta(obj, currentUser.UserID)); AppLookups.AddIndexEntryToCache(obj.ToCacheIndexEntry()); return(meta); }
public ActionResult UnclaimPage(Guid id) { var p = AppLookups.GetCacheIndexEntry(id); geoSvc.UnclaimObject(p); return(RedirectToAction("Index")); }
public ActionResult Edit(Guid id) { CfCacheIndexEntry place = AppLookups.GetCacheIndexEntry(id); if (place == null) { return(new PlacesController().PlaceNotFound()); } else if (place.Type == CfType.ClimbIndoor) { return(RedirectToAction("ClimbIndoorEdit", new { id = id })); } else if (place.Type == CfType.ClimbOutdoor) { return(RedirectToAction("ClimbOutdoorEdit", new { id = id })); } else { var category = place.Type.ToPlaceCateogry(); if (category == PlaceCategory.Area) { return(RedirectToAction("AreaEdit", new { id = id })); } else if (category == PlaceCategory.IndoorClimbing) { return(RedirectToAction("LocationIndoorEdit", new { id = id })); } else if (category == PlaceCategory.OutdoorClimbing) { return(RedirectToAction("LocationOutdoorEdit", new { id = id })); } throw new Exception(string.Format("Category [{0}] from place [{1}][2] not supported by moderate edit", category, place.Name, place.IDstring)); } }
public ActionResult CountryDetail(string countryUrlPart) { ViewBag.Current = country; ViewBag.Provinces = AppLookups.CountrysProvinces(country.ID); var areas = geoSvc.GetCitiesAndMajorClimbingAreasOfCountry(country.ID); ViewBag.Cities = areas.Where(a => a.Type == CfType.City).ToList().RandomSample(12); var climbingAreas = areas.Where(a => a.Type == CfType.ClimbingArea).ToList(); ViewBag.ClimbingAreas = climbingAreas.RemoveAllChildAreas().RandomSample(12); var geoJsonUrl = Stgs.MapSvcRelativeUrl + "country/" + countryUrlPart; var mapModel = new Bing7GeoJsonMapViewModel("climbing-map-" + countryUrlPart, 730, 460, geoJsonUrl) { MapTypeId = "road" }; mapModel.ViewOptions = new Bing7MapViewOptionsViewModel(mappingSvc.GetCustomCountryBingMapView(country)); ViewBag.MapModel = mapModel; ViewBag.TopClimbs = geoSvc.GetTopClimbOfCountry(country.ID, 24); ViewBag.TopLocations = geoSvc.GetTopLocationsOfCountry(country.ID); return(View("CountryDetail")); }
public ActionResult SubscriptionSuggestion(Guid id) { var place = AppLookups.GetCacheIndexEntry(id); ViewBag.Place = place; return(View()); }
public ActionResult ProvinceDetail(Area area, IEnumerable <Location> locationsOfArea) { var provinces = AppLookups.CountrysProvinces(area.CountryID); provinces.Remove(area); ViewBag.Provinces = provinces; var intersectingAreas = geoSvc.GetIntersectingAreasWithGeoInflate(area); ViewBag.Cities = intersectingAreas.Where(p => p.Type == CfType.City).ToList(); var intersectingParentClimbingAreas = intersectingAreas.Where(p => p.Type == CfType.ClimbingArea && p.ShapeArea > area.ShapeArea).ToList(); var intersectingChildClimbingAreas = intersectingAreas.Where(p => p.Type == CfType.ClimbingArea && p.ShapeArea < area.ShapeArea).ToList().RemoveAllChildAreas().Take(20).ToList(); var displayClimbingAreas = new List <Area>(intersectingParentClimbingAreas); displayClimbingAreas.AddRange(intersectingChildClimbingAreas); ViewBag.ClimbingAreas = displayClimbingAreas.OrderByDescending(l => l.Rating).ToList(); var geoJsonUrl = Stgs.MapSvcRelativeUrl + "province/" + area.ID.ToString(); ViewBag.MapModel = new Bing7GeoJsonMapViewModel("rock-climbing-map-" + area.NameUrlPart, 730, 420, geoJsonUrl) { ViewOptions = ViewBag.MapView }; return(View("ProvinceDetail")); }
/// <summary> /// /// </summary> /// <param name="obj"></param> public void DeleteLocationIndoor(LocationIndoor obj) { var meta = DeleteLocationIndoorAuthorization(obj); locIndoorRepo.Delete(obj.ID); //-- Update the cache AppLookups.RemoveCacheIndexEntry(obj.ID); var modWhoAddedArea = modProfileRepo.GetByID(meta.CreatedByUserID); if (modWhoAddedArea.PlacesAdded > 0) { modWhoAddedArea.PlacesAdded--; modProfileRepo.Update(modWhoAddedArea); //-- Remove the points associated with this place var actionsWithPoints = modActionRepo.GetAll().Where(a => a.OnObjectID == meta.ID); ReverseActions(actionsWithPoints); } //-- update the principal details with the details we just updated (if they are the same person who deleted it) CfPrincipal.AttachModProfile(modProfileRepo.GetByID(currentUser.UserID)); //-- Incase the name changed during the life of the object, we want to save the meta with the same name as the object was when it was deleted. meta.Name = obj.VerboseDisplayName; var action = SaveModActionAndUpdateModProfile(ModActionType.LocationIndoorDelete, obj, null, meta, (m, actionID) => m.SetDeleted(actionID), null, "deleted {0} {1}", obj.Type, obj.Name); postSvc.DeleteContentAddPost(action); }
public Message LeaveOpinion(string id, string rating, string comment) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } try { var objID = Guid.ParseExact(id, "N"); var obj = AppLookups.GetCacheIndexEntry(objID); var opinion = new ContentService().CreateOpinion(new Opinion() { Comment = comment, ObjectID = obj.ID, Rating = byte.Parse(rating) }, obj.ID); var by = CfPerfCache.GetClimber(CfIdentity.UserID); var dto = new OpinionDto(opinion, by); return(ReturnAsJson(dto)); } catch (Exception ex) { return(Failed("Opinion failed : " + ex.Message)); } }
/// <summary> /// /// </summary> /// <param name="obj"></param> public void DeleteArea(Area obj) { var meta = DeleteAreaAuthorization(obj); //-- TODO: Shoot off notifications areaRepo.Delete(obj); //-- Update the cache AppLookups.RemoveCacheIndexEntry(obj.ID); var modWhoAddedArea = modProfileRepo.GetByID(meta.CreatedByUserID); if (modWhoAddedArea.PlacesAdded > 0) { modWhoAddedArea.PlacesAdded--; modProfileRepo.Update(modWhoAddedArea); //-- Remove the points associated with this place var actionsWithPoints = modActionRepo.GetAll().Where(a => a.OnObjectID == meta.ID); ReverseActions(actionsWithPoints); } //-- update the principal details with the details we just updated (if they are the same person who deleted it) CfPrincipal.AttachModProfile(modProfileRepo.GetByID(currentUser.UserID)); meta.Name = obj.VerboseDisplayName; var action = SaveModActionAndUpdateModProfile(ModActionType.AreaDelete, obj, null, meta, (m, actionID) => m.SetDeleted(actionID), null, "deleted {0} {1}", obj.Type, obj.Name); postSvc.DeleteContentAddPost(action); }
public ActionResult PlaceAjaxRefresh(Guid id) { var posts = new List <PostRendered>(); var postType = GetPostTypeFromQueryString(); if (id == Guid.Empty) { posts = postSvc.GetPostForEverywhere(postType, ClientAppType.CfWeb); } else if (id == Stgs.MyFeedID) { posts = postSvc.GetUsersFeed(CfIdentity.UserID, postType, ClientAppType.CfWeb).Posts; } else { var place = AppLookups.GetCacheIndexEntry(id); if (place.Type.ToPlaceCateogry() == PlaceCategory.Area) { posts = postSvc.GetPostForArea(id, postType, ClientAppType.CfWeb); } else { posts = postSvc.GetPostForLocation(id, postType, ClientAppType.CfWeb); } } return(PartialView("Partials/FeedPostList", new FeedPostListViewData() { FeedPosts = posts, UserHasDeletePostRights = CfPrincipal.IsGod() })); }
/// <summary> /// /// </summary> /// <remarks>Called by the parent methods CreateClimbIndoor & CreateClimbOutdoor</remarks> private void DeleteClimb(Climb obj) { climbRepo.Delete(obj.ID); //-- Remove from the cache AppLookups.RemoveCacheIndexEntry(obj.ID); }
public JsonResult SearchAreaForNewArea(string parentAreaID, string countryUrlPart, string locality) { var country = AppLookups.Country(countryUrlPart); Guid parentID; Area parentArea = default(Area); if (Guid.TryParse(parentAreaID, out parentID)) { parentArea = geoSvc.GetAreaByID(parentID); } List <GeocodeResult> results = new List <GeocodeResult>(); if (parentArea == default(Area)) { results = new GeocodeService().Geocode(country, locality); } else { //-- we need to blur the geography otherwise places that are coast to the coast fail... SqlGeography blurredGeo = parentArea.Geo.STBuffer(1500); //-- 1.5Km buffer zone results = new GeocodeService().Geocode(country, locality, blurredGeo); } if (results.Count == 0) { return(Json(new { Success = false })); } else { return(Json(new { Success = true, Results = results })); } }
/// <summary> /// /// </summary> /// <param name="o"></param> /// <param name="placeID"></param> /// <param name="isPrivate"></param> /// <returns></returns> internal Post CreateOpinionPost(Opinion o, Guid placeID, bool isPublic) { var place = AppLookups.GetCacheIndexEntry(placeID); var postMgr = new cf.Content.Feed.V0.OpinionPostManager(); dynamic data = postMgr.CreateTemplateDynamicData(o, GetPostPlace(o.ObjectID)); return(postMgr.CreatePost(o.ID, o.UserID, place, isPublic, data)); }
/// <summary> /// /// </summary> /// <param name="ci"></param> /// <returns></returns> internal Post CreateCheckInPost(CheckIn ci, bool isPublic) { var place = AppLookups.GetCacheIndexEntry(ci.LocationID); var postMgr = new cf.Content.Feed.V1.CheckInPostManager(); dynamic data = postMgr.CreateTemplateDynamicData(ci, place); return(postMgr.CreatePost(ci.ID, ci.UserID, ci.Utc, place, isPublic, data)); }
/// <summary> /// /// </summary> /// <param name="userID"></param> /// <param name="area"></param> /// <returns></returns> public Post CreateTalkPost(Guid placeID, string comment) { var place = AppLookups.GetCacheIndexEntry(placeID); var postMgr = new cf.Content.Feed.V0.TalkPostManager(); dynamic data = postMgr.CreateTemplateDynamicData(new { Comment = comment, Place = place }); return(postMgr.CreatePost(Guid.NewGuid(), CfIdentity.UserID, place, true, data)); }
private List <GeocodeResult> BingGeocodeCountryRegionQuery(Country country, string locality) { string countryRegionISO2 = AppLookups.CountryIso2(country.ID).ToUpper(); string url = string.Format("http://dev.virtualearth.net/REST/v1/Locations?CountryRegion={0}&locality={1}&key={2}&output=xml", countryRegionISO2, locality, BingMapsApiKey); string xml = new Uri(url).ExecuteRestCall(); return(ParseBingXmlResponse(xml)); }
public static MvcHtmlString FlagImage(this HtmlHelper helper, IHasCountry obj) { if (obj.CountryID == 0 || obj.CountryID == 117) { return(new MvcHtmlString(string.Format(@"<img src=""{0}/flags/nn.png"" alt=""Unknown Country"" />", Stgs.StaticRt))); } return(FlagImage(helper, AppLookups.Country(obj.CountryID))); }
public ActionResult ActionPlaceList(Guid id) { var place = AppLookups.GetCacheIndexEntry(id); var modPlace = geoSvc.GetObjectModeMeta(id); ViewBag.ModActions = geoSvc.GetModeratorActionsOnObject(id); ViewBag.ModPlace = modPlace; ViewBag.Place = place; return(View()); }
public Message GetCountry(string id) { //-- TODO: check country and pass back friendly error if not found page var countryWithOutGeo = AppLookups.Country(id); var country = geoSvc.GetCountryByID(countryWithOutGeo.ID); var mapItemCollection = mapSvc.GetCountryMapItems(country); return(ReturnMapItemCollectionAsJson(mapItemCollection)); }
public ActionResult New(Guid id) { var place = AppLookups.GetCacheIndexEntry(id); //-- Return PlaceNotFound //if (place == null) { return } var model = PrepareNewCallViewData(place); return(View("New", model)); }