Exemplo n.º 1
0
        public async Task <OperationDataResult <Paged <InstallationModel> > > Index(InstallationsRequestModel requestModel)
        {
            try
            {
                var core = await _coreHelper.GetCore();

                var options   = _options.Value;
                var listModel = new Paged <InstallationModel>();

                var listQuery = _installationCheckingContext.Installations
                                .AsNoTracking()
                                .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed);

                if (requestModel.State != null)
                {
                    listQuery = listQuery.Where(x => x.State == requestModel.State);
                }

                if (requestModel.Type != null)
                {
                    listQuery = listQuery.Where(x => x.Type == requestModel.Type);
                }

                if (!string.IsNullOrWhiteSpace(requestModel.NameFilter))
                {
                    listQuery = listQuery.Where(x => x.CompanyName.Contains(requestModel.NameFilter));
                }

                listQuery = QueryHelper.AddSortToQuery(listQuery, requestModel.Sort, requestModel.IsSortDsc);

                listModel.Total = await listQuery.Select(x => x.Id).CountAsync();

                listQuery = listQuery
                            .Skip(requestModel.Offset)
                            .Take(requestModel.PageSize);


                var list = await AddSelectToQuery(listQuery).ToListAsync();

                foreach (var item in list.Where(x => x.InstallationEmployeeId != null))
                {
                    item.InstallationFormId = int.Parse(options.InstallationFormId);
                    if (item.Type == InstallationType.Installation)
                    {
                        var site = await core.SiteRead(item.InstallationEmployeeId.GetValueOrDefault());

                        item.AssignedTo = site.FirstName + " " + site.LastName;
                        if (item.InstallationSdkCaseId != null)
                        {
                            var sdkCaseId  = (int)item.InstallationSdkCaseId;
                            var caseLookup = await core.CaseLookupMUId(sdkCaseId);

                            if (caseLookup?.CheckUId != null && caseLookup.CheckUId != 0)
                            {
                                item.InstallationSdkCaseDbId = await core.CaseIdLookup(sdkCaseId, (int)caseLookup.CheckUId);
                            }
                        }
                    }
                }
                foreach (var item in list.Where(x => x.RemovalEmployeeId != null))
                {
                    item.InstallationFormId = int.Parse(options.InstallationFormId);
                    if (item.Type == InstallationType.Removal)
                    {
                        var site = await core.SiteRead(item.RemovalEmployeeId.GetValueOrDefault());

                        item.AssignedTo = site.FirstName + " " + site.LastName;
                        if (item.RemovalSdkCaseId != null)
                        {
                            var sdkCaseId  = (int)item.RemovalSdkCaseId;
                            var caseLookup = await core.CaseLookupMUId(sdkCaseId);

                            if (caseLookup?.CheckUId != null && caseLookup?.CheckUId != 0)
                            {
                                item.RemovalSdkCaseDbId = await core.CaseIdLookup(sdkCaseId, (int)caseLookup.CheckUId);
                            }
                        }
                        if (item.InstallationSdkCaseId != null)
                        {
                            var sdkCaseId  = (int)item.InstallationSdkCaseId;
                            var caseLookup = await core.CaseLookupMUId(sdkCaseId);

                            if (caseLookup?.CheckUId != null && caseLookup?.CheckUId != 0)
                            {
                                item.InstallationSdkCaseDbId = await core.CaseIdLookup(sdkCaseId, (int)caseLookup.CheckUId);
                            }
                        }
                    }
                }

                listModel.Entities = list;

                return(new OperationDataResult <Paged <InstallationModel> >(true, listModel));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                return(new OperationDataResult <Paged <InstallationModel> >(false, _localizationService.GetString("ErrorGettingInstallationsList")));
            }
        }
 public async Task <OperationDataResult <Paged <InstallationModel> > > Index([FromBody] InstallationsRequestModel requestModel)
 {
     return(await _installationsService.Index(requestModel));
 }
        public async Task <OperationDataResult <InstallationsListModel> > Index(InstallationsRequestModel requestModel)
        {
            try
            {
                var core = await _coreHelper.GetCore();

                var options = _options.Value;

                var listQuery = _installationCheckingContext.Installations.AsNoTracking()
                                .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed);

                if (requestModel.State != null)
                {
                    listQuery = listQuery.Where(x => x.State == requestModel.State);
                }

                if (requestModel.Type != null)
                {
                    listQuery = listQuery.Where(x => x.Type == requestModel.Type);
                }

                if (!string.IsNullOrWhiteSpace(requestModel.SearchString))
                {
                    listQuery = listQuery.Where(x => x.CompanyName.Contains(requestModel.SearchString));
                }

                if (!string.IsNullOrEmpty(requestModel.Sort))
                {
                    if (requestModel.IsSortDsc)
                    {
                        listQuery = listQuery.OrderByDescending(requestModel.Sort);
                    }
                    else
                    {
                        listQuery = listQuery.OrderBy(requestModel.Sort);
                    }
                }
                else
                {
                    listQuery = listQuery.OrderBy(x => x.Id);
                }

                var list = await listQuery
                           .Skip(requestModel.Offset)
                           .Take(requestModel.PageSize)
                           .Select(x => new InstallationModel()
                {
                    Id                     = x.Id,
                    CompanyName            = x.CompanyName,
                    CompanyAddress         = x.CompanyAddress,
                    CompanyAddress2        = x.CompanyAddress2,
                    CityName               = x.CityName,
                    CountryCode            = x.CountryCode,
                    ZipCode                = x.ZipCode,
                    State                  = x.State,
                    Type                   = x.Type,
                    DateInstall            = x.DateInstall,
                    DateRemove             = x.DateRemove,
                    DateActRemove          = x.DateActRemove,
                    InstallationEmployeeId = x.InstallationEmployeeId,
                    RemovalEmployeeId      = x.RemovalEmployeeId,
                    CustomerId             = x.CustomerId,
                    InstallationSdkCaseId  = x.InstallationSdkCaseId,
                    RemovalSdkCaseId       = x.RemovalSdkCaseId,
                    RemovalFormId          = x.RemovalFormId
                }
                                   ).ToListAsync();

                foreach (var item in list.Where(x => x.InstallationEmployeeId != null))
                {
                    item.InstallationFormId = int.Parse(options.InstallationFormId);
                    if (item.Type == InstallationType.Installation)
                    {
                        var site = await core.SiteRead(item.InstallationEmployeeId.GetValueOrDefault());

                        item.AssignedTo = site.FirstName + " " + site.LastName;
                        if (item.InstallationSdkCaseId != null)
                        {
                            var sdkCaseId  = (int)item.InstallationSdkCaseId;
                            var caseLookup = await core.CaseLookupMUId(sdkCaseId);

                            if (caseLookup?.CheckUId != null && caseLookup.CheckUId != 0)
                            {
                                item.InstallationSdkCaseDbId = await core.CaseIdLookup(sdkCaseId, (int)caseLookup.CheckUId);
                            }
                        }
                    }
                }
                foreach (var item in list.Where(x => x.RemovalEmployeeId != null))
                {
                    item.InstallationFormId = int.Parse(options.InstallationFormId);
                    if (item.Type == InstallationType.Removal)
                    {
                        var site = await core.SiteRead(item.RemovalEmployeeId.GetValueOrDefault());

                        item.AssignedTo = site.FirstName + " " + site.LastName;
                        if (item.RemovalSdkCaseId != null)
                        {
                            var sdkCaseId  = (int)item.RemovalSdkCaseId;
                            var caseLookup = await core.CaseLookupMUId(sdkCaseId);

                            if (caseLookup?.CheckUId != null && caseLookup?.CheckUId != 0)
                            {
                                item.RemovalSdkCaseDbId = await core.CaseIdLookup(sdkCaseId, (int)caseLookup.CheckUId);
                            }
                        }
                        if (item.InstallationSdkCaseId != null)
                        {
                            var sdkCaseId  = (int)item.InstallationSdkCaseId;
                            var caseLookup = await core.CaseLookupMUId(sdkCaseId);

                            if (caseLookup?.CheckUId != null && caseLookup?.CheckUId != 0)
                            {
                                item.InstallationSdkCaseDbId = await core.CaseIdLookup(sdkCaseId, (int)caseLookup.CheckUId);
                            }
                        }
                    }
                }

                var listModel = new InstallationsListModel {
                    Total = list.Count(), Installations = list
                };

                return(new OperationDataResult <InstallationsListModel>(true, listModel));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                return(new OperationDataResult <InstallationsListModel>(false, _localizationService.GetString("ErrorGettingInstallationsList")));
            }
        }
Exemplo n.º 4
0
 public async Task <OperationDataResult <InstallationsListModel> > Index(InstallationsRequestModel requestModel)
 {
     return(await _installationsService.Index(requestModel));
 }