public override void Submit(BaseRegistration registration) { if (registration.GetBrokenRules().Count() > 0) { StringBuilder brokenRules = new StringBuilder(); brokenRules.AppendLine(Resources.infoDisapproveRegistrationState_002); foreach (BusinessRule businessRule in registration.GetBrokenRules()) { brokenRules.AppendLine(businessRule.Rule); } throw new ApplicationException(brokenRules.ToString()); } }
/// <summary> /// Extract application registrations from registry /// </summary> /// <param name="registry"></param> /// <returns></returns> private static List <ApplicationRegistrationModel> ApplicationsIn(IoTHubServices registry) { var registrations = registry.Devices .Select(d => d.Twin) .Select(t => BaseRegistration.ToRegistration(t)) .ToList(); var endpoints = registrations .OfType <EndpointRegistration>() .GroupBy(d => d.ApplicationId) .ToDictionary( k => k.Key, v => v.Select(e => e.ToServiceModel().Registration).ToList()); return(registrations .OfType <ApplicationRegistration>() .Select(a => a.ToServiceModel()) .Select(a => new ApplicationRegistrationModel { Application = a, Endpoints = endpoints[a.ApplicationId] }) .ToList()); }
public override void Submit(BaseRegistration registration) { throw new NotImplementedException(); }
public override void Cancel(BaseRegistration registration) { registration.SetStateTo(RegistrationStates.Cancel); }
public override void Disapprove(BaseRegistration registration) { throw new InvalidOperationException(Resources.errorApproveRegistrationState_001); }
public override void Disapprove(BaseRegistration registration) { registration.SetStateTo(RegistrationStates.Disapprove); }
public override void Submit(BaseRegistration registration) { }
//public async Task<HttpResponseMessage> RegisterEmail(Guid eventid, [FromBody] string returnedEmail) public async Task <HttpResponseMessage> RegisterEmail(Guid eventid, [FromBody] Newtonsoft.Json.Linq.JObject data) { string sourceUriTxt = ""; string returnedEmail = ""; if (Request.Properties.ContainsKey("MS_HttpContext")) { var ctx = Request.Properties["MS_HttpContext"] as HttpContextBase; if (ctx != null) { // var zz = ctx.Request.UserHostAddress; var sourceUrl = ctx.Request.UrlReferrer; sourceUriTxt = sourceUrl.AbsoluteUri.ToString(); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } Newtonsoft.Json.Linq.JToken j = (Newtonsoft.Json.Linq.JToken)data.SelectToken("recaptcha"); Type type = typeof(string); string recapchaResponse = (string)System.Convert.ChangeType(j.ToString(), type); ReCaptcha.RecapchaControl challengeTest = new ReCaptcha.RecapchaControl(); if (!challengeTest.CheckRecapchaChallenge(recapchaResponse)) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } j = (Newtonsoft.Json.Linq.JToken)data.SelectToken("email"); returnedEmail = (string)System.Convert.ChangeType(j.ToString(), type); try { if (returnedEmail != null) { Event @event = new Event(); @event = await db.Events.Where(s => s.GID == eventid && s.Active == true).FirstOrDefaultAsync(); if (@event == null) { // Event not found or not active return(Request.CreateResponse(HttpStatusCode.BadRequest)); } // Okay the event is valid and active BaseRegistration baseRegistration = new BaseRegistration() { Email = HttpUtility.HtmlEncode(returnedEmail), Date = DateTime.UtcNow }; Contact @contact = await db.Contacts.Where(s => s.Email == baseRegistration.Email).FirstOrDefaultAsync(); if (@contact != null && !Settings.AllowDuplicateeMail) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var registrationUid = Guid.NewGuid(); IList <FieldTrip> fieldTrips = await db.FieldTrips.Where(s => s.EventId == @event.EventId).ToListAsync(); IList <FieldTripChoice> fieldTripChoices = new List <FieldTripChoice>(); foreach (var entry in fieldTrips) { fieldTripChoices.Add(new FieldTripChoice { FieldTripId = entry.FieldTripId, RecordDeleted = false }); } IList <AvailableWorkshop> availableWorkshops = await db.AvailableWorkshops.Where(s => s.EventId == @event.EventId).ToListAsync(); IList <Workshop> workshops = new List <Workshop>(); foreach (var entry in availableWorkshops) { workshops.Add(new Workshop { AvailableWorkshopId = entry.AvailableWorkshopId, RecordDeleted = false }); } Registration registration = new Registration() { ValidationUid = registrationUid, Contact = new Contact() { Email = baseRegistration.Email, RecordDeleted = false }, // Field trip options need to be added here EventId = @event.EventId, FieldTripChoices = fieldTripChoices, Workshops = workshops, InitialCreationDate = DateTime.Now, RecordDeleted = false }; db.Registrations.Add(registration); await db.SaveChangesAsync(); if (registration.RegistrationId > 0) { // PK value, so record has been saved okay // var id = Guid.NewGuid(); // Send email bool testMode = Settings.TestMode; HttpStatusCode emailStatus = await SendEmail(baseRegistration.Email, @event.ContactEmail, registrationUid.ToString(), sourceUriTxt, testMode); var response = new HttpResponseMessage(HttpStatusCode.Created) { Content = new StringContent(baseRegistration.Email) }; //response.Headers.Location = // new Uri(Url.Link("DefaultApi", new { action = "status", id = id })); return(response); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } //var verify = db.Events.Select(s => s.Registrations.Where(w => w.EventId == @event.EventId && w.Contact.Email == baseRegistration.Email)).FirstOrDefaultAsync(); //if (verify != null) //{ // // var id = Guid.NewGuid(); // // Send email // HttpStatusCode emailStatus = await SendEmail(baseRegistration.Email, @event.ContactEmail, registrationUid.ToString()); // var response = new HttpResponseMessage(HttpStatusCode.Created) // { // Content = new StringContent(baseRegistration.Email) // }; // //response.Headers.Location = // // new Uri(Url.Link("DefaultApi", new { action = "status", id = id })); // return response; //} //else //{ // return Request.CreateResponse(HttpStatusCode.BadRequest); //} ////return CreatedAtRoute("DefaultApi", new { action = "status", id = id }, value); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public override void Cancel(BaseRegistration registration) { throw new InvalidOperationException(Resources.CancelRegistrationState); }
public async Task <HttpResponseMessage> RegisterEmail(Guid eventid, [FromBody] string value) { if (Request.Properties.ContainsKey("MS_HttpContext")) { var ctx = Request.Properties["MS_HttpContext"] as HttpContextBase; if (ctx != null) { // var zz = ctx.Request.UserHostAddress; var sourceUrl = ctx.Request.UrlReferrer; } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } if (value != null) { Event @event = await db.Events.Where(s => s.GID == eventid && s.Active == true).FirstOrDefaultAsync(); if (@event == null) { // Event not found or not active return(Request.CreateResponse(HttpStatusCode.BadRequest)); } // Okay the event is valid and active BaseRegistration baseRegistration = new BaseRegistration() { Email = HttpUtility.HtmlEncode(value), Date = DateTime.UtcNow }; Registration registration = new Registration() { Contact = new Contact() { Email = baseRegistration.Email }, EventId = @event.EventId }; db.Registrations.Add(registration); await db.SaveChangesAsync(); var verify = db.Events.Select(s => s.Registrations.Where(w => w.EventId == @event.EventId && w.Contact.Email == baseRegistration.Email)).FirstOrDefaultAsync(); if (verify != null) { // var id = Guid.NewGuid(); var response = new HttpResponseMessage(HttpStatusCode.Created) { Content = new StringContent(baseRegistration.Email) }; //response.Headers.Location = // new Uri(Url.Link("DefaultApi", new { action = "status", id = id })); return(response); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } //return CreatedAtRoute("DefaultApi", new { action = "status", id = id }, value); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public abstract void Submit(BaseRegistration registration);
public abstract void Cancel(BaseRegistration registration);
public abstract void Disapprove(BaseRegistration registration);
public override void Approve(BaseRegistration registration) { registration.SetStateTo(RegistrationStates.ApproveEdit); }