/// <summary> /// The business logic to process the API export /// </summary> /// <returns>An instance of ActivityApiResponse</returns> public override async Task <ActivityApiResponse> Export() { var response = new ActivityApiResponse(); var cnxFilter = await Task.FromResult(_mapperService.GetQueryParams <CNX1Filter>()); if (!(cnxFilter.AgentIds.Any() && cnxFilter.StartDate <= cnxFilter.EndDate && cnxFilter.StartDate != DateTime.MinValue & cnxFilter.EndDate != DateTime.MinValue)) { response.Message = Messages.InvalidQueryParamsCNX1; return(response); } ScheduleFilter filter = new ScheduleFilter() { AgentIds = cnxFilter.AgentIds.Select(x => { return(x.Trim()); }).ToList(), StartDate = cnxFilter.StartDate, EndDate = cnxFilter.EndDate }; var agents = await _agentRepository.GetAgents(filter.AgentIds); List <AgentActivitySchedule> agentActivitySchedulesList = filter.AgentIds.Where(ag => !agents.Select(x => x.Ssn).Contains(ag)) .Select(x => new AgentActivitySchedule() { AgentId = x, Message = Messages.AgentNotFound }) .ToList(); filter.AgentIds.RemoveAll(x => agentActivitySchedulesList.Select(y => y.AgentId).Contains(x)); if (filter.AgentIds.Any()) { List <CalendarChart> calenderCharts = await _scheduleService.GetCalendarChartsUsingIds(filter); var schedules = _scheduleService.GenerateActivityAgentSchedules(calenderCharts); var missingSchedules = filter.AgentIds .Where(x => !schedules.Select(y => y.AgentId).Contains(x)) .Select(z => new AgentActivitySchedule { AgentId = z, Message = string.Format(Messages.NoSchedulesPresent, filter.StartDate.ToString("yyyy-MM-dd"), filter.EndDate.ToString("yyyy-MM-dd")) }) .ToList(); agentActivitySchedulesList.AddRange(schedules); agentActivitySchedulesList.AddRange(missingSchedules); } response.Data = agentActivitySchedulesList.OrderBy(x => x.AgentId).ToList(); return(response); }
/// <summary> /// The method which has the general workflow for all API import processings /// </summary> /// <param name="dataFeeds"></param> /// <returns></returns> public async Task <ActivityApiResponse> Process(List <DataFeed> dataFeeds) { var respObject = new List <ActivityApiData>(); ActivityApiResponse response = new ActivityApiResponse() { Data = respObject, StatusCode = HttpStatusCode.OK }; foreach (var feed in dataFeeds) { respObject.Add(await Import(feed)); } response.StatusCode = respObject.All(x => x.Status == ProcessStatus.Success.ToString()) ? HttpStatusCode.OK : respObject.All(x => x.Status == ProcessStatus.Failed.ToString()) ? HttpStatusCode.UnprocessableEntity : HttpStatusCode.PartialContent; return(response); }