public async Task <ActionResult> GetActivitiesByUser() { var eventProps = GetDefaultCustomProperties(); try { var userObjectId = ClaimsHelper.GetUserObjectIdClaim((ClaimsIdentity)HttpContext.User.Identity); var results = await Database.GetActivitiesByUserAsync(userObjectId).ConfigureAwait(false); Logger.TrackEvent(EventNames.ActivitiesQueriedByUser, eventProps); return(Ok(results)); } catch (ClaimsValidationException ex) { eventProps.Add("User.Claims", ex.GetClaims()); Logger.TrackEvent(EventNames.ClaimsValidationError, eventProps); return(Unauthorized()); } catch (ModelValidationException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { Logger.TrackException(ex); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult> RemoveLiftingActivity([FromRoute] long activityId) { var eventProps = GetDefaultCustomProperties(); try { var userId = ClaimsHelper.GetUserObjectIdClaim((ClaimsIdentity)HttpContext.User.Identity); await Database.RemoveLiftingActivityAsync(activityId, userId).ConfigureAwait(false); eventProps.Add("ActivityType", nameof(DistanceActivity)); eventProps.Add("ActivityID", activityId.ToString()); Logger.TrackEvent(EventNames.LiftingActivityRemoved, eventProps); } catch (ClaimsValidationException ex) { eventProps.Add("User.Claims", ex.GetClaims()); Logger.TrackEvent(EventNames.ClaimsValidationError, eventProps); return(Unauthorized()); } catch (ModelValidationException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { Logger.TrackException(ex); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(Ok()); }
public async Task <ActionResult> AddDistanceActivity([FromBody] DistanceActivity activity) { var eventProps = GetDefaultCustomProperties(); try { activity.UserObjectId = ClaimsHelper.GetUserObjectIdClaim((ClaimsIdentity)HttpContext.User.Identity); await Database.AddDistanceActivityAsync(activity).ConfigureAwait(false); eventProps.Add("ActivityType", nameof(DistanceActivity)); eventProps.Add("DistanceType", activity.Type.ToString()); eventProps.Add("ActivityPurpose", activity.Purpose.ToString()); eventProps.Add("ActivityDate", activity.Date.ToString()); Logger.TrackEvent(EventNames.NewDistanceActivitySubmitted, eventProps); } catch (ClaimsValidationException ex) { eventProps.Add("User.Claims", ex.GetClaims()); Logger.TrackEvent(EventNames.ClaimsValidationError, eventProps); return(Unauthorized()); } catch (ModelValidationException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { Logger.TrackException(ex); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(Ok()); }