public async Task <IDataResult <GroupedTaskDto> > GetAsMonthly(GetByDateDto getByDateDto) { if (!getByDateDto.EndDate.HasValue) { return(new ErrorDataResult <GroupedTaskDto>(Messages.InvalidEndDate)); } var list = _userTaskDal.GetList(x => (x.StartDate.Date >= getByDateDto.StartDate.Date && x.StartDate <= getByDateDto.EndDate.Value.Date) || (x.EndDate.Date >= getByDateDto.StartDate.Date && x.EndDate.Date <= getByDateDto.EndDate.Value.Date), t => t.TaskType); var minStartMonth = getByDateDto.StartDate.Month; var minStartYear = getByDateDto.StartDate.Year; var maxEndMonth = getByDateDto.EndDate.Value.Month; var maxEndYear = getByDateDto.EndDate.Value.Year; var groupedTask = new GroupedTaskDto(TaskScheduleType.Monthly); for (int month = minStartMonth; month <= maxEndMonth; month++) { var value = _mapper.Map <IList <UserTaskDto> >(list.Where(x => (x.StartDate.Month == month && x.StartDate.Year == minStartYear) || (x.EndDate.Month == month && x.EndDate.Year == minStartYear))); var key = minStartYear + " " + month.ToString(); AddOrUpdateToDictionary(groupedTask.UserTasks, key, value); if (month == maxEndMonth && minStartYear != maxEndYear) { minStartYear++; month = 0; } } return(new SuccessDataResult <GroupedTaskDto>(groupedTask)); }
public async Task <IDataResult <IList <UserTaskDto> > > GetByDate(GetByDateDto getByDateDto) { var list = getByDateDto.EndDate.HasValue ? _userTaskDal.GetList(x => x.StartDate >= getByDateDto.StartDate && x.EndDate <= getByDateDto.EndDate.Value, t => t.TaskType) : _userTaskDal.GetList(x => (x.StartDate.Year == getByDateDto.StartDate.Year && x.StartDate.Month == getByDateDto.StartDate.Month && x.StartDate.Day == getByDateDto.StartDate.Day) && (x.EndDate.Year == getByDateDto.StartDate.Year && x.EndDate.Month == getByDateDto.StartDate.Month && x.EndDate.Day == getByDateDto.StartDate.Day), t => t.TaskType); var listDto = _mapper.Map <IList <UserTaskDto> >(list.Distinct()); return(new SuccessDataResult <IList <UserTaskDto> >(listDto)); }
public async Task <IActionResult> GetAsMonthly([FromBody] GetByDateDto getByDateDto) { try { var result = await _userTaskService.GetAsMonthly(getByDateDto); if (result.Success) { return(StatusCode(StatusCodes.Status200OK, result.Data)); } return(StatusCode(StatusCodes.Status400BadRequest, result.Message)); } catch (Exception ex) { _logger.LogError(ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public async Task <IDataResult <GroupedTaskDto> > GetAsDaily(GetByDateDto getByDateDto) { if (!getByDateDto.EndDate.HasValue) { return(new ErrorDataResult <GroupedTaskDto>(Messages.InvalidEndDate)); } var list = _userTaskDal.GetList(x => (x.StartDate.Date >= getByDateDto.StartDate.Date && x.StartDate.Date <= getByDateDto.EndDate.Value.Date) || (x.EndDate.Date >= getByDateDto.StartDate && x.EndDate.Date <= getByDateDto.EndDate.Value.Date), t => t.TaskType); var groupedTask = new GroupedTaskDto(TaskScheduleType.Daily); DateTime day = getByDateDto.StartDate.Date; while (day <= getByDateDto.EndDate.Value) { var value = _mapper.Map <IList <UserTaskDto> >(list.Where(x => x.StartDate.Date >= day || x.EndDate <= day)); var key = day.ToShortDateString(); AddOrUpdateToDictionary(groupedTask.UserTasks, key, value); day = day.AddDays(1); } return(new SuccessDataResult <GroupedTaskDto>(groupedTask)); }