Ejemplo n.º 1
0
        protected override void InitDictionaries()
        {
            base.InitDictionaries();

            this.existingPublicServiceOrgs = PublicServiceOrgRepository.GetAll().Select(x => x.Id).ToList();

            this.publicServiceOrgByContragentIdDict = PublicServiceOrgRepository.GetAll()
                                                      .Select(x => new
            {
                ContragentId = x.Contragent.Id,
                x.Id
            })
                                                      .AsEnumerable()
                                                      .GroupBy(x => x.ContragentId)
                                                      .ToDictionary(x => x.Key, x => x.First().Id);

            // Связь дома и поставщика ресурсов
            this.publicServiceOrgRo = PublicServiceOrgRealtyObjectRepository.GetAll()
                                      .Where(x => x.PublicServiceOrg != null)
                                      .Where(x => x.RealityObject != null)
                                      .Select(x => new { orgId = x.PublicServiceOrg.Id, roId = x.RealityObject.Id })
                                      .AsEnumerable()
                                      .GroupBy(x => x.orgId)
                                      .ToDictionary(x => x.Key, x => x.Select(y => y.roId).ToList());

            // Договор между домом и поставщиком ресурсов
            this.publicServiceOrgRoContract = RealObjPublicServiceOrgRepository.GetAll()
                                              .Where(x => x.PublicServiceOrg != null)
                                              .Where(x => x.RealityObject != null)
                                              .Select(x => new { orgId = x.PublicServiceOrg.Id, roId = x.RealityObject.Id })
                                              .AsEnumerable()
                                              .GroupBy(x => x.orgId)
                                              .ToDictionary(x => x.Key, x => x.Select(y => y.roId).ToList());
        }
Ejemplo n.º 2
0
        protected override void CreateContractIfNotExistAdditional(int organizationId, Record record)
        {
            if (record.OrganizationType != OrgType.ResourceProvider)
            {
                return;
            }

            // 1. Создать связь между домом и организацией
            // 2. Создать договор между домом и организацией

            // 1
            var publicServiceOrgRealtyObject = new PublicServiceOrgRealtyObject
            {
                PublicServiceOrg = new PublicServiceOrg {
                    Id = organizationId
                },
                RealityObject = new RealityObject {
                    Id = record.RealtyObjectId
                }
            };

            if (publicServiceOrgRo.ContainsKey(organizationId))
            {
                var publicServiceOrgRobjects = publicServiceOrgRo[organizationId];

                if (!publicServiceOrgRobjects.Contains(record.RealtyObjectId))
                {
                    PublicServiceOrgRealtyObjectRepository.Save(publicServiceOrgRealtyObject);

                    publicServiceOrgRobjects.Add(record.RealtyObjectId);
                }
            }
            else
            {
                PublicServiceOrgRealtyObjectRepository.Save(publicServiceOrgRealtyObject);

                publicServiceOrgRo[organizationId] = new List <int> {
                    record.RealtyObjectId
                };
            }

            // 2
            var realObjPublicServiceOrg = new RealObjPublicServiceOrg
            {
                RealityObject = new RealityObject {
                    Id = record.RealtyObjectId
                },
                PublicServiceOrg = new PublicServiceOrg {
                    Id = organizationId
                },
                ContractDate   = record.DocumentDate,
                ContractNumber = record.DocumentNumber,
                DateStart      = record.ContractStartDate
            };

            if (publicServiceOrgRoContract.ContainsKey(organizationId))
            {
                var publicServiceOrgRoContracts = publicServiceOrgRoContract[organizationId];

                if (!publicServiceOrgRoContracts.Contains(record.RealtyObjectId))
                {
                    RealObjPublicServiceOrgRepository.Save(realObjPublicServiceOrg);

                    publicServiceOrgRoContracts.Add(record.RealtyObjectId);
                }
            }
            else
            {
                RealObjPublicServiceOrgRepository.Save(realObjPublicServiceOrg);

                publicServiceOrgRoContract[organizationId] = new List <int> {
                    record.RealtyObjectId
                };
            }
        }