public IList<Climb> LogClimbAuthorize(CheckIn checkIn, LoggedClimb log)
        {
            //-- (JSK 2011:09.11) Don't think it makes sense to cache this:
            //var validClimbs = PerfCache.GetClimbsForCheckIn(checkIn.LocationID, checkIn.Utc);

            var validClimbs = new GeoService().GetClimbsOfLocationForLogging(checkIn.LocationID, checkIn.Utc);

            if (checkIn.UserID != CfIdentity.UserID)
            {
                var error = string.Format("Cannot log climbs for CheckIn with ID[{0}] because it does not belong to the current logged in user[{1}]", checkIn.ID, CfIdentity.UserID);
                throw new ArgumentException(error);
            }

            try
            {
                ClimbExperience experience = (ClimbExperience)log.Experince;
                ClimbGradeOpinion oppinion = (ClimbGradeOpinion)log.GradeOpinion;
                ClimbOutcome outcome = (ClimbOutcome)log.Outcome;
            }
            catch (Exception ex) { throw new ArgumentException(ex.Message); }

            if (log.Rating < 0 || log.Rating > 5) { throw new ArgumentException("Rating must be between 0 and 5."); }

            var climb = validClimbs.Where(c => c.ID == log.ClimbID).SingleOrDefault();
            if (climb == default(Climb))
            {
                var error = string.Format("Climb with ID[{0}] is not a valid climb to log @ {1} on {2}", log.ClimbID,
                    AppLookups.GetCacheIndexEntry(checkIn.LocationID).Name, checkIn.Utc);
                throw new ArgumentException(error);
            }

            return validClimbs;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="place"></param>
        /// <returns></returns>
        public dynamic CreateTemplateDynamicData(CheckIn obj, CfCacheIndexEntry place)
        {
            var commentData = "No comment";
            if (!string.IsNullOrEmpty(obj.Comment))
            {
                if (obj.Comment.Length < 255) { commentData = obj.Comment; }
                else { commentData = obj.Comment.Excerpt(255) + " ..."; }
            }

            dynamic data = new { Place = place.Name, Comment = commentData };
            return data;
        }
Exemplo n.º 3
0
        public void AddMedia(CheckIn ci, Media media)
        {
            if (ci.UserID != CfIdentity.UserID) { throw new UnauthorizedAccessException("Cannot add media to a check in that does not belong to you"); }
            if (ci.Media.Count >= 5) { throw new NotSupportedException("Climbfind only supports up to 5 pieces of media per check in."); }

            checkInRepo.AddMedia(ci, media);

            //-- Make sure our feed post renders correctly
            if (ci.Media.Where(m => m.ID == media.ID).Count() == 0)
            {
                ci.Media.Add(media);
            }

            //-- Update the post so the feed shows accurate data
            postSvc.UpdateCheckInPost(ci);
        }
Exemplo n.º 4
0
        public VisitDto(CheckIn c, CachedLocationDetails l, string by, string byPic)
        {
            ID = c.ID.ToString("N");
            LocID = c.LocationID.ToString("N");
            LocName = l.ShortDisplayName;
            Utc = c.Utc.ToEpochTimeString();
            if (c.OutUtc.HasValue) { UtcOut = c.OutUtc.Value.ToEpochTimeString(); }
            By = by;
            ByID = c.UserID.ToString("N");
            ByPic = byPic;
            Comment = c.Comment;
            Climbs = new List<VisitLoggedClimbDto>();
            foreach (var cl in c.LoggedClimbs) { Climbs.Add(new VisitLoggedClimbDto(cl)); }
            Media = new List<VisitMediaDto>();
            foreach (var m in c.Media) { Media.Add(new VisitMediaDto() { ID = m.ID.ToString("N"), ThumbUrl = m.ThumbUrlRelative() }); }

            if (Media.Count > 0) { ThumbUrl = Media[0].ThumbUrl; }
            else if (l.HasAvatar) { ThumbUrl = string.Format("/media/tm/{0}", l.Avatar); }
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        public CheckIn UpdateCheckIn(CheckIn checkIn)
        {
            if (checkIn.UserID != CfIdentity.UserID) { throw new UnauthorizedAccessException("Cannot edit a check in that does not belong to you"); }

            checkInRepo.Update(checkIn);

            //-- Update the post so the feed shows accurate data
            postSvc.UpdateCheckInPost(checkIn);

            return checkIn;
        }
Exemplo n.º 7
0
        public void RemoveMedia(CheckIn ci, Media media)
        {
            if (ci.UserID != CfIdentity.UserID) { throw new UnauthorizedAccessException("Cannot remove media from check in that does not belong to you"); }

            checkInRepo.RemoveMedia(ci, media.ID);
            new MediaService().DeleteMedia(media);

            //-- Update the post so the feed shows accurate data
            postSvc.UpdateCheckInPost(ci);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="checkIn"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        public LoggedClimb LogClimb(CheckIn checkIn, LoggedClimb log)
        {
            var validClimbs = LogClimbAuthorize(checkIn, log);

            var climb = validClimbs.Where(c => c.ID == log.ClimbID).SingleOrDefault();
            log.ClimbName = string.Format("{0} {1}", climb.GradeLocal, climb.Name);
            log.ID = Guid.NewGuid();
            log.UserID = CfIdentity.UserID;
            log.Denorm_LocationID = checkIn.LocationID;
            log.CheckInID = checkIn.ID;

            //-- If the check in is not live (current-ish) we use the check in time as the log reference
            if (log.Utc == default(DateTime)) { log.Utc = DateTime.UtcNow; }
            if (checkIn.Utc < DateTime.UtcNow.AddDays(-1)) { log.Utc = checkIn.Utc; }

            var existingWithClimb = checkIn.LoggedClimbs.Where(l=>l.ClimbID == climb.ID);
            if (existingWithClimb.Count() > 0) {
                var existing = existingWithClimb.First();
                DeleteLoggedClimb(null, existing.ID);
                checkIn.LoggedClimbs.Remove(existing);
            }

            logCRepo.Create(log);

            //-- Make sure our feed post renders correctly
            checkIn.LoggedClimbs.Add(log);

            //-- Create our opinion against the climb object
            //-- note we forfeit the creation of a post for the feed about the opinion by passing in "Guid.Empty"
            new ContentService().CreateOpinion(new Opinion() { ID = Guid.NewGuid(), Comment = log.Comment, Utc = log.Utc,
                    ObjectID = log.ClimbID, Rating = log.Rating, UserID = CfIdentity.UserID }, Guid.Empty);

            //-- Update the post so the feed shows accurate data
            postSvc.UpdateCheckInPost(checkIn);

            return log;
        }
Exemplo n.º 9
0
        public void DeleteLoggedClimb(CheckIn ci, Guid loggedClimbID)
        {
            var log = GetLoggedClimbById(loggedClimbID);
            //-- TODO more
            logCRepo.Delete(log.ID);

            //-- Update the post so the feed shows accurate data
            //-- If ci is null it meas we're deleting an existing entry that is about to be updated and the post will
            //-- be updated regardless
            if (ci != null) { postSvc.UpdateCheckInPost(ci); }
        }
Exemplo n.º 10
0
        public void DeleteCheckIn(CheckIn checkIn)
        {
            if (checkIn.UserID != CfIdentity.UserID) { throw new UnauthorizedAccessException("Cannot delete a check in that does not belong to you"); }

            checkInRepo.DeleteCheckIn(checkIn);

            //-- Delete the post so the feed shows accurate data
            postSvc.DeleteCheckInPost(checkIn);
        }
Exemplo n.º 11
0
 public CheckIn CreateCurrentCheckIn(CheckIn checkIn)
 {
     checkIn.Utc = DateTime.UtcNow;
     return CreateCheckIn(checkIn);
 }
Exemplo n.º 12
0
 //, Media = o.Media.ToList(), Climbs = o.LoggedClimbs }
 internal Post UpdateCheckInPost(CheckIn o)
 {
     return UpdateTypedPost(o.ID, new { CheckIn = o, Place = GetPostPlace(o.LocationID) });
 }
Exemplo n.º 13
0
 internal void DeleteCheckInPost(CheckIn obj)
 {
     DeleteTypedPost(postRepo.GetByID(obj.ID));
 }
Exemplo n.º 14
0
 /// <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);
 }
Exemplo n.º 15
0
        private void FixupCheckIn(CheckIn previousValue)
        {
            if (previousValue != null && previousValue.LoggedClimbs.Contains(this))
            {
                previousValue.LoggedClimbs.Remove(this);
            }

            if (CheckIn != null)
            {
                if (!CheckIn.LoggedClimbs.Contains(this))
                {
                    CheckIn.LoggedClimbs.Add(this);
                }
                if (CheckInID != CheckIn.ID)
                {
                    CheckInID = CheckIn.ID;
                }
            }
        }