Пример #1
0
        /// <summary>
        ///   The sinhronize smo.
        /// </summary>
        private void SinhronizeSmo()
        {
            using (
                var sessionSrz =
                    ObjectFactory.GetInstance <IManagerSessionFactorys>().GetFactoryByName("NHibernateCfgAtl.xml").OpenSession())
            {
                var sessionPvp = ObjectFactory.GetInstance <ISessionFactory>().GetCurrentSession();
                var smoSrzList = sessionSrz.QueryOver <Smo>().List();
                var smoPvpList = sessionPvp.QueryOver <Organisation>().Where(x => x.Oid.Id == Oid.Smo).List();
                var list       = smoPvpList;

                // Перенос СМО из базы srz в базу pvp
                var smoToPvpList = smoSrzList.Where(x => list.All(y => y.Code != x.Code)).ToList();
                var oid          = ObjectFactory.GetInstance <IOidManager>().GetById(Oid.Smo);
                foreach (var smo in smoToPvpList)
                {
                    var bossfio = string.IsNullOrEmpty(smo.Bossname)
                          ? new[] { string.Empty, string.Empty, string.Empty }
                          : smo.Bossname.Split(' ');

                    var tfomsCode = smo.Code.Length >= 2 ? smo.Code.Substring(0, 2) : string.Empty;
                    var smoPvp    = new Organisation
                    {
                        Parent =
                            ObjectFactory.GetInstance <IOrganisationManager>()
                            .GetBy(x => x.Code == tfomsCode && x.Oid.Id == Oid.Tfoms)
                            .FirstOrDefault(),
                        Code                = smo.Code,
                        ShortName           = smo.Caption,
                        FullName            = smo.Fullname,
                        Ogrn                = smo.Ogrn,
                        Phone               = smo.Tel1,
                        DateLastEdit        = smo.Dedit,
                        FirstName           = bossfio.Length >= 1 ? bossfio[0] : string.Empty,
                        LastName            = bossfio.Length >= 2 ? bossfio[1] : string.Empty,
                        MiddleName          = bossfio.Length >= 3 ? bossfio[2] : string.Empty,
                        DateIncludeRegister = smo.Db,
                        DateExcludeRegister = smo.De,
                        Oid = oid
                    };

                    sessionPvp.Save(smoPvp);
                    smoPvpList.Add(smoPvp);
                }

                sessionPvp.Flush();

                // Перенос диапазонов номеров бланков ВС из базы СРЗ в базу ПВП
                var rangeNumbersSrzList = sessionSrz.QueryOver <Vsdiap>().List();
                var addedPvpRangeNumber = new List <RangeNumber>();
                foreach (var rangeNumberSrz in rangeNumbersSrzList)
                {
                    Organisation smo            = null;
                    var          rangeNumberPvp =
                        sessionPvp.QueryOver <RangeNumber>()
                        .JoinAlias(x => x.Smo, () => smo)
                        .Where(
                            x =>
                            x.RangelFrom == rangeNumberSrz.Lo && x.RangelTo == rangeNumberSrz.Hi &&
                            smo.Code == rangeNumberSrz.SMO.Code)
                        .List()
                        .FirstOrDefault();

                    // создаем новую запись
                    if (rangeNumberPvp == null)
                    {
                        rangeNumberPvp     = new RangeNumber();
                        rangeNumberPvp.Smo =
                            sessionPvp.QueryOver <Organisation>().Where(x => x.Code == rangeNumberSrz.SMO.Code).List().FirstOrDefault();
                        rangeNumberPvp.RangelFrom = rangeNumberSrz.Lo.HasValue ? rangeNumberSrz.Lo.Value : 0;
                        rangeNumberPvp.RangelTo   = rangeNumberSrz.Hi.HasValue ? rangeNumberSrz.Hi.Value : 0;
                        addedPvpRangeNumber.Add(rangeNumberPvp);
                        sessionPvp.Save(rangeNumberPvp);
                    }
                }

                sessionPvp.Flush();

                // Перенос СМО из базы ПВП в базу СРЗ
                var smoToSrzList = smoPvpList.Where(x => smoSrzList.All(y => y.Code != x.Code)).ToList();
                foreach (var smo in smoToSrzList)
                {
                    var smoSrz = new Smo
                    {
                        Code     = smo.Code,
                        Caption  = smo.ShortName,
                        Fullname = smo.FullName,
                        Ogrn     = smo.Ogrn,
                        Db       = smo.DateIncludeRegister,
                        De       = smo.DateExcludeRegister,
                        Bossname = string.Format("{0} {1} {2}", smo.FirstName, smo.LastName, smo.MiddleName),
                        Tel1     = smo.Phone,
                    };

                    sessionSrz.Save(smoSrz);
                }

                sessionSrz.Flush();

                // Перенос диапазонов номеров бланков ВС из базы ПВП в базу СРЗ
                var rangeNumbersPvpList = sessionPvp.QueryOver <RangeNumber>().List();
                rangeNumbersPvpList = rangeNumbersPvpList.Where(x => addedPvpRangeNumber.All(y => x.Id != y.Id)).ToList();
                foreach (var rangeNumberPvp in rangeNumbersPvpList)
                {
                    Smo smo       = null;
                    var vsdiapSrz =
                        sessionSrz.QueryOver <Vsdiap>()
                        .JoinAlias(x => x.SMO, () => smo)
                        .Where(
                            x =>
                            x.Lo == rangeNumberPvp.RangelFrom && x.Hi == rangeNumberPvp.RangelTo &&
                            smo.Code == rangeNumberPvp.Smo.Code)
                        .List()
                        .FirstOrDefault();

                    // создаем новую запись
                    if (vsdiapSrz == null)
                    {
                        vsdiapSrz       = new Vsdiap();
                        vsdiapSrz.Dedit = DateTime.Now;
                        vsdiapSrz.SMO   =
                            sessionSrz.QueryOver <Smo>().Where(x => x.Code == rangeNumberPvp.Smo.Code).List().FirstOrDefault();
                        vsdiapSrz.Lo = rangeNumberPvp.RangelFrom;
                        vsdiapSrz.Hi = rangeNumberPvp.RangelTo;
                        sessionSrz.Save(vsdiapSrz);
                    }
                }

                sessionSrz.Flush();

                // закрываем сессию СРЗ
                sessionSrz.Close();
            }
        }
        public async Task GetFinanceManagementUser()
        {
            //Arrange
            var costStageRevision   = new CostStageRevision();
            var northAmericanRegion = new Region();
            var europeanSmo         = new Smo();
            var budgetRegion        = Constants.BudgetRegion.NorthAmerica;
            var role = new Role
            {
                Id            = Guid.NewGuid(),
                BusinessRoles = new List <BusinessRole>
                {
                    new BusinessRole
                    {
                        Key   = Constants.BusinessRole.FinanceManager,
                        Value = Constants.BusinessRole.FinanceManager,
                    }
                }
            };

            var costStageRevisionId = Guid.NewGuid();

            costStageRevision.Id = costStageRevisionId;

            var northAmericanFinanceUserId     = Guid.NewGuid();
            var northAmericanFinanceUserGdamId = "na_finance_gdam_id";
            var europeanFinanceUserId          = Guid.NewGuid();
            var northAmericanRegionId          = Guid.NewGuid();
            var userGroupId              = Guid.NewGuid();
            var europeanSmoId            = Guid.NewGuid();
            var northAmericanFinanceUser = new CostUser
            {
                Id = northAmericanFinanceUserId,
                NotificationBudgetRegion = northAmericanRegion,
                UserBusinessRoles        = new List <UserBusinessRole>
                {
                    new UserBusinessRole
                    {
                        BusinessRole = new BusinessRole
                        {
                            Key   = Constants.BusinessRole.FinanceManager,
                            Value = Constants.BusinessRole.FinanceManager,
                            Role  = role
                        },
                        ObjectType = core.Constants.AccessObjectType.Client
                    }
                },
                UserUserGroups = new List <UserUserGroup>
                {
                    new UserUserGroup
                    {
                        UserGroup = new UserGroup
                        {
                            Id   = userGroupId,
                            Role = role
                        },
                        UserGroupId = userGroupId,
                        UserId      = northAmericanFinanceUserId
                    }
                },
                GdamUserId = northAmericanFinanceUserGdamId
            };
            var europeanFinanceUser = new CostUser
            {
                UserBusinessRoles = new List <UserBusinessRole>
                {
                    new UserBusinessRole
                    {
                        BusinessRole = new BusinessRole
                        {
                            Key   = Constants.BusinessRole.FinanceManager,
                            Value = Constants.BusinessRole.FinanceManager
                        },
                        ObjectId   = europeanSmoId,
                        ObjectType = core.Constants.AccessObjectType.Smo
                    }
                },
                Id = europeanFinanceUserId
            };

            northAmericanRegion.Id  = northAmericanRegionId;
            northAmericanRegion.Key = Constants.Region.NorthAmericanArea;
            europeanSmo.Id          = europeanSmoId;
            europeanSmo.Key         = Constants.Smo.WesternEurope;

            var costUsers = new List <CostUser> {
                northAmericanFinanceUser, europeanFinanceUser
            };

            _efContext.Region.Add(northAmericanRegion);
            _efContext.Smo.Add(europeanSmo);

            _efContext.AddRange(costUsers);
            _efContext.SaveChanges();

            var costUserGroups = new[] { userGroupId.ToString() };

            //Act
            var result = await _costUserService.GetFinanceManagementUsers(costUserGroups, budgetRegion);

            //Assert
            result.Should().NotBeNull();

            var resultArr = result as string[] ?? result.ToArray();

            resultArr.Should().HaveCount(1);
            resultArr.First().Should().Be(northAmericanFinanceUserGdamId);
        }
Пример #3
0
        private void InitData(string fileName, string approvalBandString, decimal approvalLimit, out List <CostUser> users, out ApprovalBand approvalBand, out Smo smo, out UserLoginEvent userLoginEventObject)
        {
            var stringJson = GetJsonString(fileName).Result;

            userLoginEventObject = JsonConvert.DeserializeObject <UserLoginEvent>(stringJson);
            users = new List <CostUser>
            {
                new CostUser
                {
                    Id = Guid.NewGuid(),
                    UserBusinessRoles = new List <UserBusinessRole>
                    {
                        new UserBusinessRole
                        {
                            BusinessRole = new BusinessRole
                            {
                                Key   = Constants.BusinessRole.BrandManager,
                                Value = Constants.BusinessRole.BrandManager
                            }
                        }
                    },
                    GdamUserId = "58adcba90c885409f1f47c57"
                },
                new CostUser
                {
                    Id                = Guid.NewGuid(),
                    Email             = ApprovalMemberModel.BrandApprovalUserEmail,
                    UserBusinessRoles = new List <UserBusinessRole>
                    {
                        new UserBusinessRole
                        {
                            BusinessRole = new BusinessRole
                            {
                                Key   = Constants.BusinessRole.BrandManager,
                                Value = Constants.BusinessRole.BrandManager
                            }
                        }
                    },
                    GdamUserId = "4ef31ce1766ec96769b399c0"
                }
            };

            approvalBand = new ApprovalBand
            {
                ApprovalLimit = approvalLimit,
                BusinessRole  = users.First(a => a.GdamUserId == "58adcba90c885409f1f47c57").UserBusinessRoles.First().BusinessRole,
                Id            = Guid.NewGuid(),
                Band          = -1,
                StringBand    = approvalBandString
            };
            smo = new Smo
            {
                Countries = new List <Country>
                {
                    new Country
                    {
                        Cities = new List <City>(),
                        Iso    = [email protected],
                        Name   = "POLAND"
                    }
                },
                Key   = Constants.Smo.WesternEurope,
                Value = Constants.Smo.WesternEurope
            };
        }
        public async Task GetInsuranceUser_WesternEuropeAgency()
        {
            //Arrange
            var agency              = new Agency();
            var england             = new Country();
            var northAmericanRegion = new Region();
            var europeanSmo         = new Smo();

            var countryId = Guid.NewGuid();
            var northAmericanInsuranceUserId = Guid.NewGuid();
            var europeanInsuranceUserId      = Guid.NewGuid();
            var northAmericanRegionId        = Guid.NewGuid();
            var europeanSmoId           = Guid.NewGuid();
            var northAmericanGdamUserId = "ABC";
            var europeGdamUserId        = "DEF";

            var northAmericanInsuranceUser = new CostUser
            {
                GdamUserId        = northAmericanGdamUserId,
                UserBusinessRoles = new List <UserBusinessRole>
                {
                    new UserBusinessRole
                    {
                        BusinessRole = new BusinessRole
                        {
                            Key   = Constants.BusinessRole.InsuranceUser,
                            Value = Constants.BusinessRole.InsuranceUser
                        },
                        ObjectType = core.Constants.AccessObjectType.Region,
                        ObjectId   = northAmericanRegionId
                    }
                }
            };
            var europeanInsuranceUser = new CostUser
            {
                GdamUserId        = europeGdamUserId,
                UserBusinessRoles = new List <UserBusinessRole>
                {
                    new UserBusinessRole
                    {
                        BusinessRole = new BusinessRole
                        {
                            Key   = Constants.BusinessRole.InsuranceUser,
                            Value = Constants.BusinessRole.InsuranceUser
                        },
                        ObjectType = core.Constants.AccessObjectType.Smo,
                        ObjectId   = europeanSmoId
                    }
                }
            };

            agency.CountryId    = countryId;
            agency.Country      = england;
            england.Id          = countryId;
            england.GeoRegionId = europeanSmoId;

            var europeanRegion = new RegionModel
            {
                Name = Constants.AgencyRegion.Europe
            };

            _regionsService.Setup(r => r.GetAsync(It.IsAny <Guid>())).Returns(Task.FromResult(europeanRegion));

            northAmericanInsuranceUser.Id = northAmericanInsuranceUserId;
            europeanInsuranceUser.Id      = europeanInsuranceUserId;

            northAmericanRegion.Id  = northAmericanRegionId;
            northAmericanRegion.Key = Constants.Region.NorthAmericanArea;
            europeanSmo.Id          = europeanSmoId;
            europeanSmo.Key         = Constants.Smo.WesternEurope;

            var costUsers = new List <CostUser> {
                northAmericanInsuranceUser, europeanInsuranceUser
            };
            //needed otherwise tests fail when run all together!
            var existingUsers = _efContext.CostUser.ToList();

            _efContext.CostUser.RemoveRange(existingUsers);

            _efContext.AddRange(costUsers);
            _efContext.Region.Add(northAmericanRegion);
            _efContext.Smo.Add(europeanSmo);
            _efContext.SaveChanges();

            _regionsService.Setup(a => a.GetGeoRegion(It.IsAny <Guid>())).ReturnsAsync(new RegionModel
            {
                Id   = Guid.NewGuid(),
                Key  = Constants.AgencyRegion.Europe,
                Name = Constants.AgencyRegion.Europe
            });
            //Act
            var result = await _costUserService.GetInsuranceUsers(agency);

            //Assert
            result.Should().NotBeNull();
            result.First().Should().Be(europeGdamUserId);
        }