public async Task <RegixCompanyModel> AddRegixCompanyAsync(RegixCompanyModel model)
        {
            if (model == null)
            {
                throw new NullReferenceException("RegixCompanyModel is null");
            }

            RegixCompanyModel existing = await _context.RegixCompany
                                         .Where(x =>
                                                x.Uic == model.Uic &&
                                                String.Equals(x.Name, model.Name) &&
                                                String.Equals(x.LegalFormAbbr, model.LegalFormAbbr) &&
                                                String.Equals(x.LegalFormName, model.LegalFormName))
                                         .Select(x => x.ToModel())
                                         .FirstOrDefaultAsync();

            if (existing != null)
            {
                return(existing);
            }

            var company = model.ToEntity();

            await _context.RegixCompany.AddAsync(company);

            await _context.SaveChangesAsync();

            model.Id = company.Id;
            return(model);
        }
        public async Task <RegixCompanyModel> GetCompanyFromRegixAsync(string identifier)
        {
            CompanySearchResultModel result = await _integrationService.GetCompanyFromRegiXAsync(identifier);

            RegixCompanyModel company = GetCompanyViewModelFromResponse(result, identifier);

            company = await SetCompanyStatusInModel(company);

            return(company);
        }
        private async Task <RegixCompanyModel> SetCompanyStatusInModel(RegixCompanyModel company)
        {
            RegixCompanyStatus status = await _context.RegixCompanyStatus
                                        .Where(x => x.Code == company.StatusCode)
                                        .FirstOrDefaultAsync();

            if (status != null)
            {
                company.StatusName   = status.Name;
                company.StatusNameEn = status.NameEn;
            }

            return(company);
        }
Beispiel #4
0
        public static RegixCompanyModel ToViewModel(this RegiX.Client.ResponseModels.ValidUICResponse model)
        {
            if (model == null)
            {
                return(null);
            }

            Shared.Enums.RegixCompanyStatus status = model.StatusSpecified ? GetCompanyStatus(model.Status) : Shared.Enums.RegixCompanyStatus.UNKNOWN;
            RegixCompanyModel viewModel            = new RegixCompanyModel
            {
                Id            = -1,
                Name          = model.Company,
                LegalFormAbbr = model.LegalForm.LegalFormAbbr,
                LegalFormName = model.LegalForm.LegalFormName,
                StatusCode    = status.ToString(),
            };

            return(viewModel);
        }
Beispiel #5
0
        public static RegixCompany ToEntity(this RegixCompanyModel model)
        {
            if (model == null)
            {
                return(null);
            }

            RegixCompany entity = new RegixCompany
            {
                Uic           = model.Uic,
                Name          = model.Name,
                LegalFormAbbr = model.LegalFormAbbr,
                LegalFormName = model.LegalFormName,
                StatusCode    = model.StatusCode,
                RequestId     = model.RequestId,
                UpdatedAt     = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
            };

            return(entity);
        }
        private RegixCompanyModel GetCompanyViewModelFromResponse(CompanySearchResultModel result, string searchIdentifier)
        {
            if (result == null || result.ResponseObject == null)
            {
                return(null);
            }

            ValidUICResponse companyResponse = result.ResponseObject as ValidUICResponse;

            if (companyResponse == null)
            {
                throw new Exception("Could not convert response to ValidUICResponse");
            }

            RegixCompanyModel model = companyResponse.ToViewModel();

            model.RequestId = result.RequestId;
            model.Uic       = searchIdentifier;

            return(model);
        }
Beispiel #7
0
        public static RegixCompanyModel ToModel(this RegixCompany entity)
        {
            if (entity == null)
            {
                return(null);
            }

            RegixCompanyModel model = new RegixCompanyModel
            {
                Id            = entity.Id,
                Uic           = entity.Uic,
                Name          = entity.Name,
                LegalFormAbbr = entity.LegalFormAbbr,
                LegalFormName = entity.LegalFormName,
                StatusCode    = entity.StatusCode,
                StatusName    = entity.StatusCodeNavigation?.Name,
                StatusNameEn  = entity.StatusCodeNavigation?.NameEn,
                RequestId     = entity.RequestId,
                UpdatedAt     = entity.UpdatedAt.HasValue == true?DateTime.SpecifyKind(entity.UpdatedAt.Value, DateTimeKind.Utc) : default(DateTime?),
            };

            return(model);
        }
        public async Task <DistraintCreateModel> AddAsync(DistraintCreateModel model)
        {
            if (model == null)
            {
                throw new NullReferenceException("DistraintCreateModel is null");
            }

            using (var tran = _context.Database.BeginTransaction())
            {
                try
                {
                    var distraint = model.ToEntity();

                    if (model.IsNewProperty)
                    {
                        OtherPropertyModel newProperty = await _propertyService.AddOtherPropertyAsync(model.NewOtherProperty);

                        distraint.PropertyIdOtherProperty = newProperty?.Id;
                    }
                    else if (model.PropertyIdVehicle == -1 && !String.IsNullOrEmpty(model.VehicleProperty.RegistrationNumber))
                    {
                        Vehicle vehicle = await _propertyService.AddOrUpdateVehicleAsync(model.VehicleProperty);

                        distraint.PropertyIdVehicle = vehicle.Id;
                    }
                    else if (model.PropertyIdAircraft == -1 && !String.IsNullOrEmpty(model.AircraftProperty.MsnserialNumber))
                    {
                        Aircraft aircraft = await _propertyService.AddOrUpdateAircraftAsync(model.AircraftProperty);

                        distraint.PropertyIdAircraft = aircraft.Id;
                    }
                    else if (model.PropertyIdVessel == -1 && !String.IsNullOrEmpty(model.VesselProperty.RegistrationData?.RegistrationNumber))
                    {
                        Vessel vessel = await _propertyService.AddOrUpdateVesselAsync(model.VesselProperty);

                        distraint.PropertyIdVessel = vessel.Id;
                    }

                    if (distraint.IsInFavourOfPerson)
                    {
                        if (model.InFavourOfPerson != null && !String.IsNullOrWhiteSpace(model.InFavourOfPerson.Identifier))
                        {
                            RegixPersonModel person = await _personService.AddRegixPersonAsync(model.InFavourOfPerson);

                            distraint.InFavourOfPersonId  = person.Id;
                            distraint.InFavourOfCompany   = null;
                            distraint.InFavourOfCompanyId = null;
                        }
                        else
                        {
                            throw new Exception("In favour of person missing data!");
                        }
                    }
                    else
                    {
                        if (model.InFavourOfCompany != null && !String.IsNullOrWhiteSpace(model.InFavourOfCompany.Uic))
                        {
                            RegixCompanyModel company = await _companyService.AddRegixCompanyAsync(model.InFavourOfCompany);

                            distraint.InFavourOfCompanyId = company.Id;
                            distraint.InFavourOfPerson    = null;
                            distraint.InFavourOfPersonId  = null;
                        }
                        else
                        {
                            throw new Exception("In favour of company missing data!");
                        }
                    }

                    if (distraint.IsDebtorPerson)
                    {
                        if (model.DebtorPerson != null && !String.IsNullOrWhiteSpace(model.DebtorPerson.Identifier))
                        {
                            RegixPersonModel person = await _personService.AddRegixPersonAsync(model.DebtorPerson);

                            distraint.DebtorPersonId  = person.Id;
                            distraint.DebtorCompany   = null;
                            distraint.DebtorCompanyId = null;
                        }
                        else
                        {
                            throw new Exception("Debtor person missing data!");
                        }
                    }
                    else
                    {
                        if (model.DebtorCompany != null && !String.IsNullOrWhiteSpace(model.DebtorCompany.Uic))
                        {
                            RegixCompanyModel company = await _companyService.AddRegixCompanyAsync(model.DebtorCompany);

                            distraint.DebtorCompanyId = company.Id;
                            distraint.DebtorPerson    = null;
                            distraint.DebtorPersonId  = null;
                        }
                        else
                        {
                            throw new Exception("Debtor company missing data!");
                        }
                    }


                    await _context.Distraint.AddAsync(distraint);

                    await _context.SaveChangesAsync();

                    tran.Commit();

                    model.Id = distraint.Id;
                    return(model);
                }
                catch (Exception e)
                {
                    tran.Rollback();
                    throw e;
                }
            }
        }