public List<ChecklistIndexViewModel> QueryUsingQueryObject(string clientAccountNumber, string checklistCreatedBy,
            string visitDate, string status, bool includeDeleted)
        {
            try
            {
                DateTime validVisitDate;
                DateTime? nullableValidVisitDate = null;
                if (!string.IsNullOrEmpty(visitDate) && DateTime.TryParse(visitDate, out validVisitDate))
                {
                    nullableValidVisitDate = validVisitDate;
                }


                var clientDetail = _clientDetailsService.GetByClientAccountNumber(clientAccountNumber);
                var clientDetailId = (clientDetail != null && clientDetail.Id != -1) ? (int?) clientDetail.Id : null;
                var checklists = _getChecklistsQuery.Execute(clientDetailId, checklistCreatedBy, nullableValidVisitDate,
                    status, null);


                if (checklists != null)
                {

                    //store the site details and customer details retrieved from the Client Details Service so that we don't have to make multiple requests for the same ids
                    var visitSites = new List<SiteAddressResponse>();
                    var clientDetails = new List<CompanyDetails>();

                    return checklists.Select(x =>
                    {
                        var can = GetClientAccountNumber(clientDetails, x.ClientId);
                        var visitSite = GetVisitSiteAddress(visitSites, x.ClientId, x.SiteId);
                        var qaAdvisor = (x.QaAdvisorId.HasValue) ? _qaAdvisorRepository.GetById(x.QaAdvisorId.Value) : null;

                        var checklistViewModel = new ChecklistIndexViewModel()
                        {
                            Id = x.Id,
                            Title = "Title",
                            VisitDate = x.VisitDate,
                            VisitBy = x.VisitBy,
                            CreatedOn = x.CreatedOn,
                            CreatedBy = x.CreatedBy,
                            Site = new SiteViewModel() {Id = x.SiteId.HasValue ? x.SiteId.Value : -1},
                            Status = x.Status,
                            CAN = can
                            ,
                            Deleted = x.Deleted
                            ,
                            HasQaComments = x.HasQaComments
                            ,
                            QaAdvisor = qaAdvisor != null
                                ? new QaAdvisorViewModel()
                                {
                                    Id = qaAdvisor.Id,
                                    Forename = qaAdvisor.Forename,
                                    Email = qaAdvisor.Email,
                                    Fullname = qaAdvisor.Forename + ' ' + qaAdvisor.Surname,
                                    Initials = qaAdvisor.Forename + ' ' + qaAdvisor.Surname.Substring(0, 1)
                                }
                                : null
                            ,
                            ClientName = ""
                        };
                        checklistViewModel.Site.Id = visitSite != null ? (int) visitSite.Id : -1;
                        checklistViewModel.Site.Postcode = visitSite != null ? visitSite.Postcode : "";
                        checklistViewModel.Site.SiteName = visitSite != null ? visitSite.SiteName : "";
                        checklistViewModel.Site.Address1 = visitSite != null ? visitSite.Address1 : "";
                        checklistViewModel.Site.Address2 = visitSite != null ? visitSite.Address2 : "";
                        checklistViewModel.Site.Address3 = visitSite != null ? visitSite.Address3 : "";
                        checklistViewModel.Site.Address4 = visitSite != null ? visitSite.Address4 : "";

                        return checklistViewModel;
                    }).ToList();
                }

                return new List<ChecklistIndexViewModel>();
            }
            catch (Exception ex)
            {
                LogManager.GetLogger(typeof (ChecklistController)).Error(ex);
                throw;
            }
        }
Пример #2
0
        public List<ChecklistIndexViewModel> Query(string clientAccountNumber, string checklistCreatedBy,
            string visitDate, string status, bool includeDeleted,
            bool excludeSubmitted, string statusFromDate,
            string statusToDate)
        {
            try
            {
                DateTime validVisitDate;
                DateTime? nullableValidVisitDate = null;
                if (!string.IsNullOrEmpty(visitDate) && DateTime.TryParse(visitDate, out validVisitDate))
                {
                    nullableValidVisitDate = validVisitDate;
                }

                DateTime validFromDate;
                DateTime? nullablevalidFromDate = null;
                if (!string.IsNullOrEmpty(statusFromDate) && DateTime.TryParse(statusFromDate, out validFromDate))
                {
                    nullablevalidFromDate = validFromDate;
                }

                DateTime validToDate;
                DateTime? nullablevalidToDate = null;
                if (!string.IsNullOrEmpty(statusToDate) && DateTime.TryParse(statusToDate, out validToDate))
                {
                    nullablevalidToDate = validToDate;
                }

                int? clientDetailId = null;
                if (!string.IsNullOrEmpty(clientAccountNumber))
                {
                    //if client not found then return empty list
                    var clientDetail = _clientDetailsService.GetByClientAccountNumber(clientAccountNumber);

                    if (clientDetail == null || clientDetail.Id == -1)
                    {
                        return new List<ChecklistIndexViewModel>();
                    }

                    clientDetailId = (int?) clientDetail.Id;
                }

                QaAdvisor qaAdvisorToSearchFor = null;
                if (checklistCreatedBy != null)
                {
                    qaAdvisorToSearchFor = _qaAdvisorRepository.GetByFullname(checklistCreatedBy);
                }

                BuildQuery(checklistCreatedBy, status, includeDeleted, excludeSubmitted, nullablevalidFromDate,
                    nullablevalidToDate, nullableValidVisitDate, clientDetailId, checklistCreatedBy, qaAdvisorToSearchFor);

                var checklists = _getChecklistsQuery.Execute();

                if (checklists != null)
                {
                    //store the site details and customer details retrieved from the Client Details Service so that we don't have to make multiple requests for the same ids
                    var visitSites = new List<SiteAddressResponse>();
                    var clientDetails = new List<CompanyDetails>();

                    var checklistIndexViewModelList = checklists.Select(x =>
                    {
                        var can = GetClientAccountNumber(clientDetails, x.ClientId);
                        var visitSite = GetVisitSiteAddress(visitSites, x.ClientId, x.SiteId);

                        var checklistViewModel = new ChecklistIndexViewModel()
                        {
                            Id = x.Id,
                            Title = "Title",
                            VisitDate = x.VisitDate.ToUniversalTime(),
                            VisitBy = x.VisitBy,
                            CreatedOn = x.CreatedOn.ToUniversalTime(),
                            CreatedBy = x.CreatedBy,
                            Site = new SiteViewModel() {Id = x.SiteId.HasValue ? x.SiteId.Value : -1},
                            Status = x.Deleted ? "Deleted" : x.Status,
                            CAN = can,
                            Deleted = x.Deleted,
                            HasQaComments = x.HasQaComments,
                            HasUnresolvedQaComments = !x.HasResolvedQaComments,
                            QaAdvisor = x.QaAdvisorId.HasValue
                                ? new QaAdvisorViewModel()
                                {
                                    Id = x.QaAdvisorId.Value,
                                    Initials = "" //x.QaAdvisorInitials,
                                }
                                : null,
                            ClientName = "",
                            ExecutiveSummaryDocumentLibraryId = x.ExecutiveSummaryDocumentLibraryId,
                            CompletedOn = x.CompletedDate.ToUniversalTime(),
                            SubmittedOn = x.SubmittedDate.ToUniversalTime(),
                            UpdatedOn = x.UpdatedOn.ToUniversalTime(),
                            QaAdvisorAssignedOn = x.QaAdvisorAssignedOn.ToUniversalTime(),
                            ExecutiveSummaryUpdateRequired = x.ExecutiveSummaryUpdateRequired,
                            ExecutiveSummaryQACommentsResolved = x.ExecutiveSummaryQACommentsResolved,
                            TemplateName = x.TemplateName,
                            QACommentStatus = x.QACommentStatus()

                        };

                        checklistViewModel.Site.Id = visitSite != null ? (int) visitSite.Id : -1;
                        checklistViewModel.Site.Postcode = visitSite != null ? visitSite.Postcode : "";
                        checklistViewModel.Site.SiteName = visitSite != null ? visitSite.SiteName : "";
                        checklistViewModel.Site.Address1 = visitSite != null ? visitSite.Address1 : "";
                        checklistViewModel.Site.Address2 = visitSite != null ? visitSite.Address2 : "";
                        checklistViewModel.Site.Address3 = visitSite != null ? visitSite.Address3 : "";
                        checklistViewModel.Site.Address4 = visitSite != null ? visitSite.Address4 : "";

                        checklistViewModel.Favourite = checklistViewModel.Deleted == false ? GetFavouriteChecklist(x.Id) : null;

                        return checklistViewModel;
                    }).ToList();

                    return checklistIndexViewModelList;
                }

                return new List<ChecklistIndexViewModel>();
            }
            catch (Exception ex)
            {
                LogManager.GetLogger(typeof (ChecklistController)).Error(ex);
                throw;
            }
        }