public IHttpActionResult Accept(Guid id) { try { var registration = _registrationRepository.GetById(id); var visitor = _visitorRepository.GetById(registration.Visitor.Id); var eventItem = _eventRepository.GetById(registration.Event.Id); var scan = Scan.Create(DateTime.Now, "Alsnog geaccepteerd", registration); registration.Scans.Add(scan); var body = new CheckinBody() { Name = visitor.Name, City = visitor.City, Email = visitor.Email, NumberOfVisitors = registration.NumberOfVisitors, Postcode = visitor.Postcode, TimeSlot = eventItem.TimeRange.ToString() }; var message = new CheckinMessage() { Status = 200, Description = "Alsnog geaccepteerd" }; var response = new CheckinResponse() { Data = body, Message = message }; registration.Visited = true; _registrationRepository.Update(registration); return(Ok(response)); } catch (Exception) { throw; } }
public Option <Scan> Read(ScanFile scanFile) { { using var scan = Hdf.Open(scanFile.Filepath); if (scan.FileIdentifier < 0L) { return(Optional.None <Scan>($"The scan file at '{scanFile.Filepath}' does not exist or is not a valid HDF document")); } var outcome = Optional.Some(); var regions = new List <Region>(); scan.IterateGroup("/entry1/instrument", (n, t, _) => { foreach (var __ in outcome) { if (t == ObjectType.Group) { var energies = scan.GetData <double>($"/entry1/instrument/{n}/energies"); if (energies != null) { // Starting energy value (energies), counts / creation time Unix (image_data) energies.Value.FirstOrNone("The 'energies' array must contain at least one value") .FlatMap(sev => scan.GetData <double>($"/entry1/instrument/{n}/image_data").SomeNotNull("Region must contain dataset 'image_data'") .Filter(id => id.ChangeTime.HasValue, "Dataset 'image_data' does not specify a change time") .Map(id => new { StartingEnergyValue = sev, CreationTimeUnix = id.ChangeTime.Value, ImageData = id.Value })) // Excitation energy (excitation_energy) .FlatMap(d => scan.GetData <double>($"/entry1/instrument/{n}/excitation_energy").Value.SingleOrNone("The 'excitation_energy' array must contain exactly one value") .FlatMap(ee => { try { return(Optional.Some(Convert.ToUInt16(ee))); } catch { return(Optional.None <ushort>($"Excitation energy value must be convertible to a 16-bit unsigned integer (was {ee})")); } }) .Map(ee => new { d.StartingEnergyValue, d.CreationTimeUnix, d.ImageData, ExcitationEnergy = ee }) ) // Step time (step_time) .FlatMap(d => scan.GetData <double>($"/entry1/instrument/{n}/step_time").SomeNotNull("Region must contain dataset 'step_time'") .FlatMap(st => st.Value.SingleOrNone("The 'step_time' array must contain exactly one value")) .Map(st => new { d.StartingEnergyValue, d.CreationTimeUnix, d.ImageData, d.ExcitationEnergy, StepTime = st })) // Energy step (energy_step) .FlatMap(d => scan.GetData <double>($"/entry1/instrument/{n}/energy_step").SomeNotNull("Region must contain dataset 'energy_step'") .FlatMap(es => es.Value.SingleOrNone("The 'energy_step' array must contain exactly one value")) .Map(es => new { d.StartingEnergyValue, d.CreationTimeUnix, d.ImageData, d.ExcitationEnergy, d.StepTime, EnergyStep = es })) // Energy mode (energy_mode) .FlatMap(d => scan.GetString($"/entry1/instrument/{n}/energy_mode").SomeNotNull("Region must contain dataset 'energy_mode'") .Map(em => new { d.StartingEnergyValue, d.CreationTimeUnix, d.ImageData, d.ExcitationEnergy, d.StepTime, d.EnergyStep, EnergyMode = em })) .FlatMap(d => Region.Create(n, d.CreationTimeUnix, d.StartingEnergyValue, d.ImageData, d.ExcitationEnergy, d.StepTime, d.EnergyStep, d.EnergyMode)) .Match( some: r => regions.Add(r), none: e => outcome = Optional.None(Error.Create($"Failed to read region '{n}' in file '{scanFile.Filename}'").CausedBy(e)) ); } } } }); return(outcome.FlatMap(() => Scan.Create(scanFile, regions))); } }
public IHttpActionResult Checkin(Guid id) { try { var registration = _registrationRepository.GetById(id); if (registration == null) { var message = new CheckinMessage() { Status = 602, Description = "Onbekende ticket" }; var response = new CheckinResponse() { Data = null, Message = message }; return(Content(HttpStatusCode.BadRequest, response)); } var visitor = _visitorRepository.GetById(registration.Visitor.Id); var eventItem = _eventRepository.GetById(registration.Event.Id); var currentDate = DateTime.Now; if (registration.Visited) { var scan = Scan.Create(DateTime.Now, "Ticket is al gebruikt", registration); registration.Scans.Add(scan); _registrationRepository.Update(registration); var body = new CheckinBody() { Name = visitor.Name, City = visitor.City, Email = visitor.Email, NumberOfVisitors = registration.NumberOfVisitors, Postcode = visitor.Postcode, TimeSlot = eventItem.TimeRange.ToString() }; var message = new CheckinMessage() { Status = 601, Description = "Ticket is al gebruikt" }; var response = new CheckinResponse() { Data = body, Message = message }; return(Content(HttpStatusCode.BadRequest, response)); } if (currentDate >= eventItem.TimeRange.Start && currentDate <= eventItem.TimeRange.End) { var scan = Scan.Create(DateTime.Now, "Geaccepteerd", registration); registration.Scans.Add(scan); var body = new CheckinBody() { Name = visitor.Name, City = visitor.City, Email = visitor.Email, NumberOfVisitors = registration.NumberOfVisitors, Postcode = visitor.Postcode, TimeSlot = eventItem.TimeRange.ToString() }; var message = new CheckinMessage() { Status = 200, Description = "Geaccepteerd" }; var response = new CheckinResponse() { Data = body, Message = message }; registration.Visited = true; _registrationRepository.Update(registration); return(Ok(response)); } else { var scan = Scan.Create(DateTime.Now, "Ticket valt buiten de toegestane timeslot", registration); registration.Scans.Add(scan); _registrationRepository.Update(registration); var body = new CheckinBody() { Name = visitor.Name, City = visitor.City, Email = visitor.Email, NumberOfVisitors = registration.NumberOfVisitors, Postcode = visitor.Postcode, TimeSlot = eventItem.TimeRange.ToString() }; var message = new CheckinMessage() { Status = 600, Description = "Ticket valt buiten de toegestane timeslot" }; var response = new CheckinResponse() { Data = body, Message = message }; return(Content(HttpStatusCode.BadRequest, response)); } } catch (Exception) { throw; } }