public async Task <OperationDataResult <FieldsUpdateModel> > GetFields() { try { List <FieldUpdateModel> fields = await _dbContext.CustomerFields .Include("Field").OrderBy(x => x.DisplayIndex) .Select(x => new FieldUpdateModel() { FieldStatus = x.FieldStatus, Id = x.FieldId, Name = x.Field.Name, }).ToListAsync().ConfigureAwait(false); // Mode Id field to top //fields.Reverse(); // int index = fields.FindIndex(x => x.Name == "Id"); // FieldUpdateModel item = fields[index]; // fields[index] = fields[0]; // fields[0] = item; FieldsUpdateModel result = new FieldsUpdateModel() { Fields = fields, }; return(new OperationDataResult <FieldsUpdateModel>(true, result)); } catch (Exception e) { Trace.TraceError(e.Message); _logger.LogError(e.Message); return(new OperationDataResult <FieldsUpdateModel>(false, _localizationService.GetString("ErrorWhileObtainingFieldsInfo"))); } }
public async Task <OperationDataResult <CustomerSettingsModel> > GetSettings() { try { var result = new CustomerSettingsModel(); var customerSettings = _options.Value; if (customerSettings?.RelatedEntityGroupId != null) { result.RelatedEntityId = (int)customerSettings.RelatedEntityGroupId; var core = _coreHelper.GetCore(); var entityGroup = await core.Result.EntityGroupRead(customerSettings.RelatedEntityGroupId.ToString()); if (entityGroup == null) { return(new OperationDataResult <CustomerSettingsModel>(false, "Entity group not found")); } result.RelatedEntityName = entityGroup.Name; } return(new OperationDataResult <CustomerSettingsModel>(true, result)); } catch (Exception e) { Trace.TraceError(e.Message); _logger.LogError(e.Message); return(new OperationDataResult <CustomerSettingsModel>(false, _customersLocalizationService.GetString("ErrorObtainingCustomersInfo"))); } }
public async Task <OperationDataResult <CustomersModel> > Index( CustomersRequestModel pnRequestModel) { try { // CustomerModel customerModel = new CustomerModel(); var customersQuery = _dbContext.Customers .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) .AsQueryable(); customersQuery = QueryHelper.AddSortToQuery(customersQuery, pnRequestModel.SortColumnName, pnRequestModel.IsSortDsc); if (!string.IsNullOrEmpty(pnRequestModel.Name)) { customersQuery = customersQuery.Where(x => x.CompanyName.ToLower().Contains(pnRequestModel.Name.ToLower()) || x.ContactPerson.ToLower().Contains(pnRequestModel.Name.ToLower()) || x.CompanyAddress.ToLower().Contains(pnRequestModel.Name.ToLower()) || x.CompanyAddress2.ToLower().Contains(pnRequestModel.Name.ToLower()) || x.CityName.ToLower().Contains(pnRequestModel.Name.ToLower()) || x.Phone.Contains(pnRequestModel.Name) || x.VatNumber.Contains(pnRequestModel.Name) || x.EanCode.Contains(pnRequestModel.Name) || x.Email.ToLower().Contains(pnRequestModel.Name.ToLower())); } customersQuery = customersQuery .Skip(pnRequestModel.Offset) .Take(pnRequestModel.PageSize); var customers = await customersQuery.Select(x => new CustomerModel { Id = x.Id, Description = x.Description, Email = x.Email, ContactPerson = x.ContactPerson, CompanyName = x.CompanyName, Phone = x.Phone, CityName = x.CityName, CompanyAddress = x.CompanyAddress, CompanyAddress2 = x.CompanyAddress2, CountryCode = x.CountryCode, CreatedBy = x.CreatedBy, CreatedDate = x.CreatedDate, CustomerNo = x.CustomerNo, EanCode = x.EanCode, VatNumber = x.VatNumber, ZipCode = x.ZipCode, CrmId = x.CrmId, CadastralNumber = x.CadastralNumber, PropertyNumber = x.PropertyNumber, ApartmentNumber = x.ApartmentNumber, CompletionYear = x.CompletionYear, FloorsWithLivingSpace = x.FloorsWithLivingSpace, CreatedAt = x.CreatedAt, UpdateAt = x.UpdatedAt, RelatedEntityId = x.RelatedEntityId, CreatedByUserId = x.CreatedByUserId, UpdatedByUserId = x.UpdatedByUserId, WorkflowState = x.WorkflowState, Version = x.Version, CadastralType = x.CadastralType, FullName = $"{x.CompanyName} - {x.ContactPerson} - {x.CompanyAddress} - {x.CityName} - {x.Phone}" }).ToListAsync(); var customersPnModel = new CustomersModel { Total = await customersQuery.Select(x => x.Id).CountAsync(), Customers = customers }; return(new OperationDataResult <CustomersModel>(true, customersPnModel)); } catch (Exception e) { Trace.TraceError(e.Message); _logger.LogError(e.Message); return(new OperationDataResult <CustomersModel>(false, _customersLocalizationService.GetString("ErrorObtainingCustomersInfo") + e.Message)); } }