Beispiel #1
0
        public async Task <OperationDataResult <RentableItemCustomerModel> > ReadCustomer(int id)
        {
            try
            {
                RentableItemCustomerModel rentableItemCustomer = await _customerDbContext.Customers.Select(x => new RentableItemCustomerModel
                {
                    Id              = x.Id,
                    Description     = x.Description,
                    Phone           = x.Phone,
                    CityName        = x.CityName,
                    CustomerNo      = x.CustomerNo,
                    ZipCode         = x.ZipCode,
                    Email           = x.Email,
                    ContactPerson   = x.ContactPerson,
                    CreatedBy       = x.CreatedBy,
                    CompanyAddress  = x.CompanyAddress,
                    CompanyAddress2 = x.CompanyAddress2,
                    CompanyName     = x.CompanyName,
                    CountryCode     = x.CountryCode,
                    EanCode         = x.EanCode,
                    VatNumber       = x.VatNumber
                }).FirstOrDefaultAsync(x => x.Id == id);

                if (rentableItemCustomer == null)
                {
                    return(new OperationDataResult <RentableItemCustomerModel>(false, "Customer not found"));
                }

                return(new OperationDataResult <RentableItemCustomerModel>(true, rentableItemCustomer));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationDataResult <RentableItemCustomerModel>(false, "Error obtaining customer"));
            }
        }
        public async Task <OperationDataResult <ContractInspectionsModel> > Index(ContractInspectionsRequestModel contractInspectionsPnRequestModel)
        {
            try
            {
                ContractInspectionsModel contractInspectionsModel = new ContractInspectionsModel();
                Core _core = await _coreHelper.GetCore();

                IQueryable <ContractInspection> contractInspectionsQuery = _dbContext.ContractInspection.
                                                                           Where(x => x.WorkflowState != Constants.WorkflowStates.Removed).AsQueryable();
                if (!string.IsNullOrEmpty(contractInspectionsPnRequestModel.SortColumnName) &&
                    contractInspectionsPnRequestModel.SortColumnName != "")
                {
                    if (contractInspectionsPnRequestModel.IsSortDsc)
                    {
                        contractInspectionsQuery = contractInspectionsQuery.CustomOrderByDescending(contractInspectionsPnRequestModel.SortColumnName);
                    }
                    else
                    {
                        contractInspectionsQuery = contractInspectionsQuery.CustomOrderBy(contractInspectionsPnRequestModel.SortColumnName);
                    }
                }
                contractInspectionsModel.Total = await contractInspectionsQuery.CountAsync(x => x.WorkflowState != Constants.WorkflowStates.Removed);

                contractInspectionsQuery
                    = contractInspectionsQuery
                      .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
                      .Skip(contractInspectionsPnRequestModel.Offset)
                      .Take(contractInspectionsPnRequestModel.PageSize);
                List <ContractInspection> contractInspections = await contractInspectionsQuery.ToListAsync();

                contractInspections.ForEach(contractInspection =>
                {
                    ContractInspectionItem contractInspectionItem =
                        _dbContext.ContractInspectionItem.FirstOrDefault(x =>
                                                                         x.ContractInspectionId == contractInspection.Id);

                    Contract contract = _dbContext.Contract.Single(x => x.Id == contractInspection.ContractId);

                    Customer customer =
                        _customerDbContext.Customers.Single(x => x.Id == contract.CustomerId);
                    RentableItemCustomerModel rentableItemCustomerModel = new RentableItemCustomerModel
                    {
                        Id              = customer.Id,
                        CustomerNo      = customer.CustomerNo,
                        CompanyName     = customer.CompanyName,
                        ContactPerson   = customer.ContactPerson,
                        CompanyAddress  = customer.CompanyAddress,
                        CompanyAddress2 = customer.CompanyAddress2,
                        CityName        = customer.CityName,
                        ZipCode         = customer.ZipCode,
                        CountryCode     = customer.CountryCode,
                        EanCode         = customer.EanCode,
                        VatNumber       = customer.VatNumber,
                        Email           = customer.Email,
                        Phone           = customer.Phone,
                        Description     = customer.Description
                    };
                    List <RentableItemModel> rentableItemModels = new List <RentableItemModel>();
                    foreach (ContractRentableItem contractRentableItem in _dbContext.ContractRentableItem.Where(x =>
                                                                                                                x.ContractId == contract.Id && x.WorkflowState == Constants.WorkflowStates.Created).ToList())
                    {
                        RentableItem rentableItem           = _dbContext.RentableItem.Single(x => x.Id == contractRentableItem.RentableItemId);
                        RentableItemModel rentableItemModel = new RentableItemModel
                        {
                            Id               = rentableItem.Id,
                            Brand            = rentableItem.Brand,
                            ModelName        = rentableItem.ModelName,
                            PlateNumber      = rentableItem.PlateNumber,
                            VinNumber        = rentableItem.VinNumber,
                            SerialNumber     = rentableItem.SerialNumber,
                            RegistrationDate = rentableItem.RegistrationDate,
                            EFormId          = rentableItem.eFormId
                        };
                        rentableItemModels.Add(rentableItemModel);
                    }

                    using (var dbContext = _core.DbContextHelper.GetDbContext())
                    {
                        if (contractInspectionItem != null)
                        {
                            contractInspectionsModel.ContractInspections.Add(new ContractInspectionModel
                            {
                                SdkCaseApiId = contractInspectionItem.SDKCaseId,
                                SdkCaseId    = dbContext.Cases
                                               .Single(x => x.MicrotingUid == contractInspectionItem.SDKCaseId).Id,
                                eFormId              = rentableItemModels.First().EFormId,
                                ContractId           = contractInspection.ContractId,
                                ContractStart        = contract.ContractStart,
                                ContractEnd          = contract.ContractEnd,
                                DoneAt               = contractInspection.DoneAt,
                                Id                   = contractInspection.Id,
                                Status               = contractInspectionItem.Status,
                                RentableItemCustomer = rentableItemCustomerModel,
                                RentableItems        = rentableItemModels
                            });
                        }
                    }
                });
                return(new OperationDataResult <ContractInspectionsModel>(true, contractInspectionsModel));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationDataResult <ContractInspectionsModel>(false,
                                                                          _rentableItemsLocalizationService.GetString("ErrorObtainingContractInspectionInfo")));
            }
        }
Beispiel #3
0
        public async Task <OperationDataResult <ContractsModel> > Index(ContractsRequestModel contractsPnRequestModel)
        {
            try
            {
                ContractsModel        contractsModel = new ContractsModel();
                IQueryable <Contract> contractsQuery = _dbContext.Contract.
                                                       Where(x => x.WorkflowState != Constants.WorkflowStates.Removed).AsQueryable();
                if (!string.IsNullOrEmpty(contractsPnRequestModel.SortColumnName))
                {
                    if (contractsPnRequestModel.IsSortDsc)
                    {
                        contractsQuery = contractsQuery.CustomOrderByDescending(contractsPnRequestModel.SortColumnName);
                    }
                    else
                    {
                        contractsQuery = contractsQuery.CustomOrderBy(contractsPnRequestModel.SortColumnName);
                    }
                }
                contractsModel.Total = contractsQuery.Count();
                contractsQuery
                    = contractsQuery
                      .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
                      .Skip(contractsPnRequestModel.Offset)
                      .Take(contractsPnRequestModel.PageSize);
                List <Contract> contracts = await contractsQuery.ToListAsync();

                contracts.ForEach(contract =>
                {
                    var customer =
                        _customerDbContext.Customers.Single(x => x.Id == contract.CustomerId);
                    RentableItemCustomerModel rentableItemCustomerModel = new RentableItemCustomerModel
                    {
                        Id              = customer.Id,
                        CustomerNo      = customer.CustomerNo,
                        CompanyName     = customer.CompanyName,
                        ContactPerson   = customer.ContactPerson,
                        CompanyAddress  = customer.CompanyAddress,
                        CompanyAddress2 = customer.CompanyAddress2,
                        CityName        = customer.CityName,
                        ZipCode         = customer.ZipCode,
                        CountryCode     = customer.CountryCode,
                        EanCode         = customer.EanCode,
                        VatNumber       = customer.VatNumber,
                        Email           = customer.Email,
                        Phone           = customer.Phone,
                        Description     = customer.Description
                    };

                    List <RentableItemModel> rentableItemModels = new List <RentableItemModel>();
                    foreach (ContractRentableItem contractRentableItem in _dbContext.ContractRentableItem.Where(x => x.ContractId == contract.Id && x.WorkflowState == Constants.WorkflowStates.Created).ToList())
                    {
                        RentableItem rentableItem           = _dbContext.RentableItem.Single(x => x.Id == contractRentableItem.RentableItemId);
                        RentableItemModel rentableItemModel = new RentableItemModel
                        {
                            Id               = rentableItem.Id,
                            Brand            = rentableItem.Brand,
                            ModelName        = rentableItem.ModelName,
                            PlateNumber      = rentableItem.PlateNumber,
                            VinNumber        = rentableItem.VinNumber,
                            SerialNumber     = rentableItem.SerialNumber,
                            RegistrationDate = rentableItem.RegistrationDate
                        };
                        rentableItemModels.Add(rentableItemModel);
                    }

                    contractsModel.Contracts.Add(new ContractModel
                    {
                        ContractEnd          = contract.ContractEnd,
                        ContractNr           = contract.ContractNr,
                        ContractStart        = contract.ContractStart,
                        CustomerId           = contract.CustomerId,
                        RentableItemCustomer = rentableItemCustomerModel,
                        RentableItems        = rentableItemModels,
                        Id = contract.Id,
                    });
                });
                return(new OperationDataResult <ContractsModel>(true, contractsModel));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationDataResult <ContractsModel>(false,
                                                                _rentableItemsLocalizationService.GetString("ErrorObtainingContracts")));
            }
        }