Ejemplo n.º 1
0
        private List <TaskInfo> GetFilledTaskInfoList(List <IDayAssign> dayAssignList, List <IJob> jobList, List <IJobStatusLogModel> jobLogList, IDictionary <Guid, ICategoryModel> categoryDictionary, bool onlyWithTime = false)
        {
            var result = new List <TaskInfo>();

            IEnumerable <Guid>         creatorIds   = jobList.Select(x => x.CreatorId).Distinct();
            IDictionary <Guid, string> creatorNames = memberService.GetMemberNames(creatorIds);

            foreach (var dayAssign in dayAssignList)
            {
                IJob job = jobList.First(x => x.Id == dayAssign.JobId);
                IJobStatusLogModel      log       = jobLogList.FirstOrDefault(x => x.DayAssignId == dayAssign.Id);
                IJobStatusLogModel      cancelLog = jobLogList.FirstOrDefault(x => x.DayAssignId == dayAssign.Id && x.StatusId == JobStatus.Canceled);
                IHousingDepartmentModel assignedHousingDepartment = managementDepartmentService.GetHousingDepartment(dayAssign.DepartmentId);
                string categoryPath = job.CategoryId != Guid.Empty ?
                                      categoryService.GetFullPathString(categoryDictionary[job.CategoryId], Constants.Common.CategoryPathDelimeter, categoryDictionary)
                    : string.Empty;
                string address = job.AddressList.Any(x => x.HousingDepartmentId == dayAssign.DepartmentId)
                    ? job.AddressList.Last(x => x.HousingDepartmentId == dayAssign.DepartmentId).Address
                    : string.Empty;

                JobStatus status = log?.StatusId ?? JobStatus.Pending;

                result.Add(new TaskInfo
                {
                    Id                    = job.Id,
                    CategoryName          = categoryPath,
                    Title                 = job.Title,
                    CompletitionDate      = log != null ? GetLogDate(log.StatusId, JobStatus.Completed, log) : string.Empty,
                    CancelingDate         = log != null ? GetLogDate(log.StatusId, JobStatus.Canceled, log) : string.Empty,
                    CancelingReason       = cancelLog != null ? cancelLog.CancelingReason : string.Empty,
                    StatusName            = status.GetStatusLabel(translationService),
                    SpentTime             = log?.TotalSpentTime ?? default(decimal),
                    CreatorName           = creatorNames[job.CreatorId],
                    TenantType            = dayAssign.TenantType.HasValue ? GetTenantTaskTypeTranslationsKey(dayAssign.TenantType.Value) : string.Empty,
                    TenantTypeEnum        = dayAssign.TenantType,
                    TaskType              = job.JobTypeId.GetTaskTypeLabel(translationService),
                    HousingDepartmentName = $"{assignedHousingDepartment.SyncDepartmentId} {assignedHousingDepartment.Name}",
                    Address               = address,
                    OriginalTaskId        = job.ParentId
                });
            }

            return(result);
        }
Ejemplo n.º 2
0
        private ICancelingReasonDataModel GetCancelingReasonDataModel(IDayAssign dayAssign, IEnumerable <IJobStatusLogModel> jobStatusLogs, IEnumerable <IJob> jobs,
                                                                      Dictionary <Guid, string> creatorNames, IEnumerable <IHousingDepartmentModel> housingDepartments)
        {
            List <IJobStatusLogModel> jobStatusLogList = jobStatusLogs.Where(x => x.DayAssignId == dayAssign.Id).ToList();

            IJobStatusLogModel unassignedLog = jobStatusLogList
                                               .OrderByDescending(log => log.Date)
                                               .FirstOrDefault(x => x.StatusId == JobStatus.Rejected);

            if (unassignedLog == null)
            {
                return(null);
            }

            IJob job = jobs.First(x => x.Id == dayAssign.JobId);
            IHousingDepartmentModel housingDepartment = housingDepartments.First(x => x.Id == dayAssign.DepartmentId);

            decimal    totalTimeSpent         = (decimal)jobStatusLogList.SelectMany(x => x.TimeLogList).Sum(y => y.SpentTime.TotalHours);
            Guid       managementDepartmentId = managementDepartmentService.GetParentManagementId(dayAssign.DepartmentId);
            JobAddress addressModel           = job.AddressList.FirstOrDefault(x => x.HousingDepartmentId == dayAssign.DepartmentId);

            return(new CancelingReasonDataModel
            {
                HousingDepartmentId = dayAssign.DepartmentId,
                DayAssignId = dayAssign.Id,
                ReasonId = unassignedLog.CancelingId ?? Guid.Empty,
                ManagementDepartmentId = managementDepartmentId,
                RejectionDate = unassignedLog.Date.ToString(Constants.DateTime.CsvDateFormat),
                Reason = unassignedLog.CancelingReason,
                SpentTime = totalTimeSpent,
                JobId = job.Id,
                Title = job.Title,
                HousingDepartmentName = housingDepartment.DisplayName,
                Address = addressModel?.Address,
                CreatorName = creatorNames[job.CreatorId],
                TenantType = dayAssign.TenantType.HasValue ? dayAssign.TenantType.Value.GetTenantTypeTaskLabel(translationService) : string.Empty,
                StatusName = dayAssign.StatusId.GetStatusLabel(translationService)
            });
        }