internal static async Task <ResultType> Validate <T>(ContextAdapter context, Action <T> configure = null) where T : ValidationContext <T>, new() { var handler = GetHandler <T>(context); if (handler == null) { return(ResultType.ContinueExecution); } var eventContext = EventContext <T> .Create(context, configure); await handler.Invoke(eventContext); if (eventContext.HasFailed) { var includeTusResumableHeaderInResponse = true; // Do not leak information on the tus endpoint during authorization. if (eventContext is EventContext <AuthorizeContext> ) { includeTusResumableHeaderInResponse = false; } await context.Response.Error(eventContext.StatusCode, eventContext.ErrorMessage, includeTusResumableHeaderInResponse); return(ResultType.StopExecution); } return(ResultType.ContinueExecution); }
public IHttpActionResult Post(JObject json) { string userKey = this.Request.Headers.GetValues("uk").FirstOrDefault(); bool auth = false; using (UserContext userContext = new UserContext()) { auth = userContext.Authenticate(userKey); } if (auth) { string name = json["Name"]?.ToString(); string address = json["Address"]?.ToString(); string description = json["Description"]?.ToString(); if (!int.TryParse(json["EventId"]?.ToString(), out int eventId)) { eventId = 0; } if (!int.TryParse(json["TypeId"]?.ToString(), out int typeId) || !double.TryParse(json["Longitude"]?.ToString(), out double longitude) || !double.TryParse(json["Latitude"]?.ToString(), out double latitude) || !DateTime.TryParse(json["Date"]?.ToString(), out DateTime date) || string.IsNullOrEmpty(name) && string.IsNullOrEmpty(address) && string.IsNullOrEmpty(description)) { return(BadRequest()); } else { User user; using (UserContext userContext = new UserContext()) { Event getEvent; user = userContext.Get(userKey); if (eventId == 0) { getEvent = EventContext.Create(typeId, user.Id, name, description, address, date, longitude, latitude); } else { getEvent = EventContext.Update(eventId, typeId, user.Id, name, description, address, date, longitude, latitude); } if (getEvent != null) { return(Ok(getEvent)); } } } } return(Ok("Unauthorized")); }
internal static async Task Notify <T>(ContextAdapter context, Action <T> configure = null) where T : EventContext <T>, new() { var handler = GetHandler <T>(context); if (handler == null) { return; } var eventContext = EventContext <T> .Create(context, configure); await handler.Invoke(eventContext); }