public Message GetTodayPartnerCallsForPlace(string id) { try { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } Guid pID = Guid.ParseExact(id, "N"); var calls = pcSvc.GetPlacesGeoDeducTodayPartnerCalls(pID); var dto = new List <PartnerCallDto>(); foreach (var c in calls) { //-- Here we use perf cache instead of Include()/join because it's likely the user will have revisited the same place var place = CfCacheIndex.Get(c.PlaceID); if (place != null) { var user = CfPerfCache.GetClimber(c.UserID); var callDto = new PartnerCallDto(place, c, user); dto.Add(callDto); } } return(ReturnAsJson(dto)); } catch (Exception ex) { CfTrace.Error(ex); return(Failed("Partner search failed : " + ex.Message)); } }
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 GetMyPartnerCalls() { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } var calls = pcSvc.GetUsersLatestPartnerCalls(CfIdentity.UserID, 10); var dto = new List <PartnerCallDto>(); var user = CfPerfCache.GetClimber(CfIdentity.UserID); foreach (var c in calls) { //-- Here we use perf cache instead of Include()/join because it's likely the user will have revisited the same place var place = CfCacheIndex.Get(c.PlaceID); if (place != null) { var callDto = new PartnerCallDto(place, c, user); dto.Add(callDto); } } return(ReturnAsJson(dto)); }
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 LogClimbUpdate(string logID, string outcome, string experience, string gradeOpinion, string rating, string comment) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } try { var lID = Guid.ParseExact(logID, "N"); var log = visitsSvc.GetLoggedClimbById(lID); if (log == default(LoggedClimb)) { throw new ArgumentException("Logged climb does not exist as part of the specified check in!"); } log.Comment = comment; log.Experince = byte.Parse(experience); log.Outcome = byte.Parse(outcome); log.GradeOpinion = byte.Parse(gradeOpinion); log.Rating = byte.Parse(rating); visitsSvc.LogClimbUpdate(log); var dto = new LoggedClimbDetailDto(log, "", "", ""); return(ReturnAsJson(dto)); } catch (Exception ex) { return(Failed("Log climb failed : " + ex.Message + " " + ex.Source)); } }
public Message CheckOut(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } try { Guid ciID = Guid.ParseExact(id, "N"); var ci = visitsSvc.GetCheckInById(ciID); //-- in case the visit has been deleted and we're trying to check out via the app. if (ci == null) { return(ReturnAsJson(new VisitDto())); } else { var co = visitsSvc.CheckOut(ciID); var location = CfPerfCache.GetLocation(co.LocationID); return(ReturnAsJson(new VisitDto(co, location, CfIdentity.DisplayName, ""))); } } catch (Exception ex) { return(Failed("Check out failed : " + ex.Message)); } }
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 GetConversation(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } try { var userID = Guid.ParseExact(id, "N"); var conversation = new ConversationService().GetConversationByPartyIDs(userID, CfIdentity.UserID);; var me = CfPerfCache.GetClimber(CfIdentity.UserID); var with = CfPerfCache.GetClimber(userID); var conversationDto = new ConversationDetailDto(conversation, with, me); foreach (var m in conversation.Messages) { conversationDto.Messages.Add(new ConversationMessageDto(m)); } return(ReturnAsJson(conversationDto)); } catch (Exception ex) { return(Failed("Message failed : " + 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)); }
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)); } }
public Message CommentOnPost(string id, string comment) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } try { var postID = Guid.ParseExact(id, "N"); var post = postSvc.GetPostByID(postID); var com = postSvc.CreateComment(post, comment); var profile = CfPerfCache.GetClimber(CfIdentity.UserID); var dto = new PostCommentDto(com, profile); return(ReturnAsJson(dto)); } catch (Exception ex) { return(Failed("Comment failed : " + ex.Message)); } }
/// <summary> /// Reads the headers to determine client location & identity /// </summary> /// <returns>Service execution context</returns> private SvcContext InflateContext() { var ctx = new SvcContext(); var latLon = new LatLon(); if (latLon.Inflate()) { ctx.ClientGeolocation = latLon; } //else { ctx.Invalid = true; ctx.ContextMessage = Forbidden("Operation not allowed"); return ctx; } SimpleWebToken swttoken = null; if (!IsAuthenticated(HttpContext.Current, out swttoken)) { ctx.Invalid = true; if (swttoken == null) { ctx.ContextMessage = Unauthorized("Token required"); } else if (swttoken.IsExpired) { ctx.ContextMessage = Unauthorized("Token expired"); } else { ctx.ContextMessage = Unauthorized("Token invalid"); } } return(ctx); }
public Message GetLatestGeoFeedPosts() { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } return(GetMobilePosts(() => postSvc.GetGeoFeed(ctx.Lat, ctx.Lon, PostType.Unknown, ClientAppType.CfiPhone))); }
private Message GetPost(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } Guid postID = Guid.ParseExact(id, "N"); return(ReturnAsJson(GetMobilePost(postSvc.GetPostRenderedByID(postID, ClientAppType.CfiPhone)))); }
public Message GetClimberByFacebookID(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } var p = new UserService().GetProfileByFacebookID(long.Parse(id)); return(ReturnAsJson(new ProfileDto(p))); }
public Message GetNearestLocations() { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } var places = new MobileService().GetNearestLocationsV1(ctx.Lat, ctx.Lon, 11); return(ReturnAsJson(places)); }
public Message GetMe() { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } var p = usrSvc.GetProfileByID(CfIdentity.UserID); return(ReturnAsJson(new ProfileDto(p))); }
public Message GetAreaLite(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } Guid areaID = Guid.ParseExact(id, "N"); var area = new GeoService().GetAreaByID(areaID); var dto = new AreaDetailDto(area); return(ReturnAsJson(dto)); }
public Message GetClimber(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } Guid userID = Guid.ParseExact(id, "N"); var p = new UserService().GetProfileByID(userID); var dto = new ProfileDto(p); return(ReturnAsJson(dto)); }
public Message GetLoggedClimb(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } Guid loggedClimbID = Guid.ParseExact(id, "N"); var log = visitsSvc.GetLoggedClimbById(loggedClimbID); var climb = geoSvc.GetClimbByID(log.ClimbID); return(ReturnAsJson(new LoggedClimbDetailDto(log, climb.GradeLocal, climb.Avatar, ""))); }
public Message NewPartnerCall(string loc, string start, string end, string preferredLevel, string comment) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } try { Guid locID = Guid.ParseExact(loc, "N"); var place = CfCacheIndex.Get(locID); var startDateTime = DateTime.ParseExact(start, "dddMMMddyyyyhhmmtt", CultureInfo.InvariantCulture); var endDateTime = default(DateTime); if (end != "default") { endDateTime = DateTime.ParseExact(end, "dddMMMddyyyyhhmmtt", CultureInfo.InvariantCulture); } var pc = pcSvc.CreatePartnerCall(new PartnerCall() { Comment = comment, StartDateTime = startDateTime, EndDateTime = endDateTime, ForIndoor = true, ForOutdoor = true, PlaceID = place.ID, PreferredLevel = byte.Parse(preferredLevel) } ); var user = CfPerfCache.GetClimber(CfIdentity.UserID); var dto = new PartnerCallDto(place, pc, user); if (!pcSvc.UserHasSubscriptionForRelatedGeo(place.ID)) { pcSvc.CreatePartnerCallSubscription(new PartnerCallSubscription() { ForIndoor = pc.ForIndoor, ForOutdoor = pc.ForOutdoor, PlaceID = pc.PlaceID, EmailRealTime = true, MobileRealTime = false, ExactMatchOnly = false }); } return(ReturnAsJson(dto)); } catch (Exception ex) { return(Failed("PartnerCall failed : " + ex.Message)); } }
private Message GetMobilePosts(Func <List <PostRendered> > getPostsDelegate) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } var dto = new List <PostDto>(); var posts = getPostsDelegate(); foreach (var p in posts) { dto.Add(GetMobilePost(p)); } return(ReturnAsJson(dto)); }
public Message GetGeoContext() { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } var places = new MobileService().GetNearestLocationsV1(ctx.Lat, ctx.Lon, 12); var areas = new GeoService().GetIntersectingAreasOfPoint(ctx.Lat, ctx.Lon); foreach (var a in areas) { places.Add(new LocationResultDto(a.ID, a.TypeID, a.CountryID, a.Name, a.NameShort, a.Avatar, a.Latitude, a.Longitude, 0, a.Rating, a.RatingCount)); } return(ReturnAsJson(places)); }
public Message GetObjectsLatestMedia(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } Guid objectID = Guid.ParseExact(id, "N"); var dto = new List <MediaDto>(); foreach (var m in new MediaService().GetObjectsMostRecentMedia(objectID, 15)) { dto.Add(new MediaDto(m.ID, m.Title, m.TypeID, m.AddedUtc, m.Profile.DisplayName, m.AddedByUserID, m.Profile.Avatar, m.Content, m.Rating, m.RatingCount)); } return(ReturnAsJson(dto)); }
public Message GetVisit(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } try { Guid ciID = Guid.ParseExact(id, "N"); var ci = visitsSvc.GetCheckInById(ciID); var loc = CfPerfCache.GetLocation(ci.LocationID); var ciDto = new VisitDto(ci, loc, CfIdentity.DisplayName, ""); return(ReturnAsJson(ciDto)); } catch { return(Failed("Query failed")); } }
public Message GetLogsForUser(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } Guid uID = Guid.ParseExact(id, "N"); var logs = visitsSvc.GetUsersMostRecentLoggedClimbs(uID, 50); var dto = new List <LoggedClimbDetailDto>(); var user = CfPerfCache.GetClimber(uID); foreach (var l in logs) { dto.Add(new LoggedClimbDetailDto(l, l.Climb.GradeLocal, l.Climb.Avatar, "")); } return(ReturnAsJson(dto)); }
public Message GetMyLogsForClimb(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } Guid climbID = Guid.ParseExact(id, "N"); var climb = geoSvc.GetClimbByID(climbID); //CfPerfCache.GetClimb(climbID); var logs = visitsSvc.GetUsersLoggedClimbs(CfIdentity.UserID).Where(c => c.ClimbID == climb.ID); var dto = new List <LoggedClimbDetailDto>(); foreach (var l in logs) { dto.Add(new LoggedClimbDetailDto(l, climb.GradeLocal, climb.Avatar, "")); } return(ReturnAsJson(dto)); }
public Message GetLocationsRecentVisits(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } Guid locationID = Guid.ParseExact(id, "N"); var dto = new List <VisitDto>(); var location = CfPerfCache.GetLocation(locationID); foreach (var c in new VisitsService().GetLocationsCheckIns(locationID).OrderByDescending(c => c.Utc).Take(12)) { var p = CfPerfCache.GetClimber(c.UserID); dto.Add(new VisitDto(c, location, p.DisplayName, p.Avatar)); } return(ReturnAsJson(dto)); }
public Message GetLogsForClimb(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } Guid climbID = Guid.ParseExact(id, "N"); var climb = geoSvc.GetClimbByID(climbID); var logs = visitsSvc.GetClimbsLogs(climbID, 25); var dto = new List <LoggedClimbDetailDto>(); foreach (var l in logs) { var user = CfPerfCache.GetClimber(l.UserID); dto.Add(new LoggedClimbDetailDto(l, climb.GradeLocal, user.Avatar, user.DisplayName)); } return(ReturnAsJson(dto)); }
public Message DeleteLoggedClimb(string id) { SvcContext ctx = InflateContext(); if (ctx.Invalid) { return(ctx.ContextMessage); } try { var lcID = Guid.ParseExact(id, "N"); var log = visitsSvc.GetLoggedClimbById(lcID); visitsSvc.DeleteLoggedClimb(log.CheckIn, log.ID); return(ReturnAsJson(new { Success = true })); } catch (Exception ex) { return(Failed("Operation failed : " + ex.Message)); } }
/// <summary> /// Reads the headers to determine client location & identity /// </summary> /// <returns>Service execution context</returns> private SvcContext InflateContext() { var ctx = new SvcContext(); var latLon = new LatLon(); if (latLon.Inflate()) { ctx.ClientGeolocation = latLon; } //else { ctx.Invalid = true; ctx.ContextMessage = Forbidden("Operation not allowed"); return ctx; } SimpleWebToken swttoken = null; if (!IsAuthenticated(HttpContext.Current, out swttoken)) { ctx.Invalid = true; if (swttoken == null) { ctx.ContextMessage = Unauthorized("Token required"); } else if (swttoken.IsExpired) { ctx.ContextMessage = Unauthorized("Token expired"); } else { ctx.ContextMessage = Unauthorized("Token invalid"); } } return ctx; }