public async Task <IActionResult> GetEventDetails(int eventId) { var attendanceEvent = await _dbContext.Events.FindAsync(eventId); var personEvents = _dbContext.PersonEvents.Where(x => x.Event.Id == eventId).ToList(); var timeIns = personEvents.Select(x => x.TimeIn).OrderByDescending(x => x); var timeOuts = personEvents.Select(x => x.TimeOut).OrderByDescending(x => x); DateTime?averageTimeIn = null, averageTimeOut = null; if (timeIns.Count() > 0) { var timeInFirst = timeIns.First(); averageTimeIn = timeInFirst.AddSeconds(timeIns.Average(d => (d - timeInFirst).TotalSeconds)); } if (timeOuts.Count() > 0) { var timeOutFirst = timeOuts.First(); averageTimeOut = timeOutFirst.AddSeconds(timeOuts.Average(d => (d - timeOutFirst).TotalSeconds)); } var eventDetails = new EventDetailsDTO { EventName = attendanceEvent.Name, StartTime = attendanceEvent.Start, EndTime = attendanceEvent.End, MeanArrivalTime = averageTimeIn, MeanDepartureTime = averageTimeOut, TotalAttendeesCount = personEvents.Count }; return(Ok(eventDetails)); }
/// <summary> /// This method signs up a new employee to an event. /// </summary> /// <param name="eventDetailsDTO">The details about the event and the employee that is signing up</param> /// <returns>The result of the Sign Up operation as well as an error message</returns> public EventDetailsResponseDTO GetDetailsIfEmployeeSignedUp(EventDetailsDTO eventDetailsDTO) { if (eventDetailsDTO == null || eventDetailsDTO.eventId == 0) { return(null); } if (string.IsNullOrEmpty(eventDetailsDTO.emailAddress)) { return(GetEventDetailsResponseObject(false, _localizer["NotAuthorized"].Value)); } //Is Employee registered in system var employee = _employeeService.GetEmployee(eventDetailsDTO.emailAddress); if (employee == null) { return(GetEventDetailsResponseObject(false, _localizer["NotAuthorized"].Value)); } //Is Employee registered for the Event var signUpsForEvent = GetSignUpsForEvent(eventDetailsDTO.eventId); if (signUpsForEvent.Any(x => x.Employee.Id == employee.Id)) { return(GetEventDetailsResponseObject(true, string.Empty, _mapper.Map <List <EmployeeDTO> >(signUpsForEvent.Select(x => x.Employee)))); } return(GetEventDetailsResponseObject(false, _localizer["NotAuthorized"].Value)); }
public IActionResult GetEmployeesForEvent(EventDetailsDTO eventDetails) { if (eventDetails == null) { return(new BadRequestResult()); } var signUpDetails = _eventsService.GetDetailsIfEmployeeSignedUp(eventDetails); if (signUpDetails == null) { return(new EmptyResult()); } return(new JsonResult(signUpDetails)); }