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; }
public LoggedClimb LogClimbUpdate(LoggedClimb log) { logCRepo.Update(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(new CheckInRepository().GetCheckInByID(log.CheckInID)); return log; }
/// <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; }
public VisitLoggedClimbDto(LoggedClimb l) { ID = l.ID.ToString("N"); ClimbID = l.ClimbID.ToString("N"); Name = l.ClimbName; Experience = l.Experince; Outcome = l.Outcome; Utc = l.Utc.ToEpochTimeString(); }