Esempio n. 1
0
        public Territory CreateTerritory(TerritoryEntity territoryEntity)
        {
            switch ((TerritoryType)territoryEntity.Type)
            {
            case TerritoryType.Franchisee:
                return(_franchiseeTerritoryMapper.Map(territoryEntity));

            case TerritoryType.HospitalPartner:
                return(_hospitalPartnerTerritoryMapper.Map(territoryEntity));

            case TerritoryType.ReadingPhysician:
                return(_readingPhysicianTerritoryMapper.Map(territoryEntity));

            case TerritoryType.Advertiser:
                return(_advertiserTerritoryMapper.Map(territoryEntity));

            case TerritoryType.SalesRep:
                return(_salesRepTerritoryMapper.Map(territoryEntity));

            case TerritoryType.Pod:
                return(_podTerritoryMapper.Map(territoryEntity));

            default:
                throw new NotSupportedException(string.Format
                                                    ("The persisted territory type {0} is currently unsupported.",
                                                    ((TerritoryType)territoryEntity.Type)));
            }
        }
Esempio n. 2
0
        public void Initialize(TerritoryEntity territory)
        {
            _myTerritoryEntity = territory;

            territory.OnChangeFaithPoint
            .Subscribe(_ => UpdateFaithPoint())
            .AddTo(this);

            territory.OnChangeMoney
            .Subscribe(_ => UpdateMoney())
            .AddTo(this);

            UpdateBuildingTemplate(territory.BuildingTemplates);
            territory.BuildingTemplates
            .ObserveMove()
            .Subscribe(_ => UpdateBuildingTemplate(territory.BuildingTemplates))
            .AddTo(this);

            if (myTerritoryDetailView == null)
            {
                throw new NullReferenceException();
            }
            myTerritoryDetailView.OnCommandToMoney
            .Subscribe(item => CommandFaithToMoney(item.faith, item.money))
            .AddTo(this);
        }
Esempio n. 3
0
        protected EventPodEntity(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            if (SerializationHelper.Optimization != SerializationOptimization.Fast)
            {
                _eventPodRoom = (EntityCollection <EventPodRoomEntity>)info.GetValue("_eventPodRoom", typeof(EntityCollection <EventPodRoomEntity>));

                _events = (EventsEntity)info.GetValue("_events", typeof(EventsEntity));
                if (_events != null)
                {
                    _events.AfterSave += new EventHandler(OnEntityAfterSave);
                }
                _podDetails = (PodDetailsEntity)info.GetValue("_podDetails", typeof(PodDetailsEntity));
                if (_podDetails != null)
                {
                    _podDetails.AfterSave += new EventHandler(OnEntityAfterSave);
                }
                _territory = (TerritoryEntity)info.GetValue("_territory", typeof(TerritoryEntity));
                if (_territory != null)
                {
                    _territory.AfterSave += new EventHandler(OnEntityAfterSave);
                }

                base.FixupDeserialization(FieldInfoProviderSingleton.GetInstance());
            }

            // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
            // __LLBLGENPRO_USER_CODE_REGION_END
        }
Esempio n. 4
0
 private static void SetZipCollectionForTerritoryEntity(TerritoryEntity territoryEntity,
                                                        IEnumerable <ZipEntity> zipEntities)
 {
     territoryEntity.ZipCollectionViaTerritoryZip.IsReadOnly = false;
     territoryEntity.ZipCollectionViaTerritoryZip.Clear();
     territoryEntity.ZipCollectionViaTerritoryZip.AddRange(zipEntities);
 }
    /// <summary>
    /// Handles the RowCommand event of the theGrid control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewCommandEventArgs"/> instance containing the event data.</param>
    protected void theGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
        case "EditExisting":
        case "ViewExisting":
            break;

        default:
            // apparently another command, return
            return;
        }
        int             index          = Convert.ToInt32(e.CommandArgument);
        TerritoryEntity selectedEntity = (TerritoryEntity)_TerritoryDS.EntityCollection[index];

        StringBuilder pkFieldsAndValues = new StringBuilder();

        pkFieldsAndValues.AppendFormat("&TerritoryId={0}", selectedEntity.TerritoryId);
        switch (e.CommandName)
        {
        case "EditExisting":
            Response.Redirect("~/EditExisting.aspx?EntityType=" + (int)EntityType.TerritoryEntity + pkFieldsAndValues.ToString());
            break;

        case "ViewExisting":
            Response.Redirect("~/ViewExisting.aspx?EntityType=" + (int)EntityType.TerritoryEntity + pkFieldsAndValues.ToString());
            break;
        }
    }
Esempio n. 6
0
        protected override void MapUniqueTerritoryFields(TerritoryEntity territoryEntity,
                                                         PodTerritory territoryToMapTo)
        {
            List <long> packageIds = territoryEntity.TerritoryPackage.Select(tp => tp.PackageId).ToList();

            territoryToMapTo.PackageIds = packageIds;
        }
Esempio n. 7
0
        public static TerritoryEntity FromDto(this Territory dto)
        {
            OnBeforeDtoToEntity(dto);
            var entity = new TerritoryEntity();

            // Map entity properties
            entity.TerritoryId          = dto.TerritoryId;
            entity.TerritoryDescription = dto.TerritoryDescription;
            entity.RegionId             = dto.RegionId;


            // Map entity associations
            // 1:n EmployeeTerritories association
            if (dto.EmployeeTerritories != null && dto.EmployeeTerritories.Any())
            {
                foreach (var relatedDto in dto.EmployeeTerritories)
                {
                    entity.EmployeeTerritories.Add(relatedDto.FromDto());
                }
            }
            // n:1 Region association
            if (dto.Region != null)
            {
                entity.Region = dto.Region.FromDto();
            }

            OnAfterDtoToEntity(dto, entity);
            return(entity);
        }
        public void MapMapsEntityHospitalPartnerOwnerIdsToHospitalPartnerTerritoryOwnerIds()
        {
            const long territoryId = 23;
            var        expectedHospitalPartnerOwnerIds = new List <long> {
                29, 645, 97
            };
            var territoryEntity = new TerritoryEntity(territoryId)
            {
                Type = (byte)TerritoryType.HospitalPartner
            };
            var hospitalPartnerTerritoryEntities = new List <HospitalPartnerTerritoryEntity>
            {
                new HospitalPartnerTerritoryEntity(expectedHospitalPartnerOwnerIds[0], territoryId),
                new HospitalPartnerTerritoryEntity(expectedHospitalPartnerOwnerIds[1], territoryId),
                new HospitalPartnerTerritoryEntity(expectedHospitalPartnerOwnerIds[2], territoryId)
            };

            territoryEntity.HospitalPartnerTerritory.AddRange(hospitalPartnerTerritoryEntities);

            Territory territory = _mapper.Map(territoryEntity);

            Assert.AreEqual(expectedHospitalPartnerOwnerIds,
                            ((HospitalPartnerTerritory)territory).HospitalPartnerOwnerIds,
                            "Hospital Partner Owner Ids were not mapped correctly.");
        }
Esempio n. 9
0
        /// <summary>Creates a new, empty TerritoryEntity object.</summary>
        /// <returns>A new, empty TerritoryEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new TerritoryEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewTerritory
            // __LLBLGENPRO_USER_CODE_REGION_END
            return(toReturn);
        }
        protected override void MapUniqueTerritoryFields(TerritoryEntity territoryEntity,
                                                         HospitalPartnerTerritory territoryToMapTo)
        {
            List <long> hospitalPartnerIds = territoryEntity.HospitalPartnerTerritory.
                                             Select(hpt => hpt.HospitalPartnerId).ToList();

            territoryToMapTo.HospitalPartnerOwnerIds = hospitalPartnerIds;
        }
Esempio n. 11
0
        public void MapSetsParentTerritoryToNullWhenEntityParentTerritoryIdIsNull()
        {
            var territoryEntity = new TerritoryEntity();

            Territory territory = _territoryFactory.Map(territoryEntity);

            Assert.IsNull(territory.ParentTerritoryId, "Parent Territory set to non-null value.");
        }
Esempio n. 12
0
        protected override void MapUniqueTerritoryFields(TerritoryEntity territoryEntity,
                                                         FranchiseeTerritory territoryToMapTo)
        {
            long franchiseeOwnerId = territoryEntity.FranchiseeTerritory != null ?
                                     territoryEntity.FranchiseeTerritory.OrganizationId : 0;

            territoryToMapTo.FranchiseeOwnerId = franchiseeOwnerId;
        }
Esempio n. 13
0
 /// <summary> setups the sync logic for member _territory</summary>
 /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
 private void SetupSyncTerritory(IEntity2 relatedEntity)
 {
     if (_territory != relatedEntity)
     {
         DesetupSyncTerritory(true, true);
         _territory = (TerritoryEntity)relatedEntity;
         base.PerformSetupSyncRelatedEntity(_territory, new PropertyChangedEventHandler(OnTerritoryPropertyChanged), "Territory", TerritoryPackageEntity.Relations.TerritoryEntityUsingTerritoryId, true, new string[] {  });
     }
 }
Esempio n. 14
0
        public void CreateTerritoryEntitySetsIsActiveToTrue()
        {
            var territory = new FranchiseeTerritory();

            TerritoryEntity territoryEntity = _territoryFactory.CreateTerritoryEntity(territory,
                                                                                      DateTime.Now, DateTime.Now);

            Assert.IsTrue(territoryEntity.IsActive, "TerritoryEntity IsActive not set to true.");
        }
Esempio n. 15
0
        public long SaveTerritory(Territory territoryToSave)
        {
            TerritoryEntity territoryEntity = GetTerritoryEntity(territoryToSave);

            SaveTerritoryEntity(territoryEntity);
            UpdateTerritoryOwnerMappings(territoryEntity.TerritoryId, territoryToSave);
            UpdateTerritoryZipMappings(territoryEntity.TerritoryId, territoryToSave.ZipCodes);
            return(territoryEntity.TerritoryId);
        }
Esempio n. 16
0
        public void MapMapsEntityIdToTerritoryId()
        {
            const long expectedTerritoryId = 3;
            var        territoryEntity     = new TerritoryEntity(expectedTerritoryId);

            Territory territory = _territoryFactory.Map(territoryEntity);

            Assert.AreEqual(expectedTerritoryId, territory.Id, "Territory ID was not mapped correctly.");
        }
Esempio n. 17
0
        public void MapCreatesEmptyZipCodeListWhenEntityZipCollectionIsEmpty()
        {
            var territoryEntity = new TerritoryEntity();

            Territory territory = _territoryFactory.Map(territoryEntity);

            Assert.IsNotNull(territory.ZipCodes, "Null zip code collection returned.");
            Assert.IsEmpty(territory.ZipCodes, "Non-empty zip code collection returned.");
        }
        /// <summary> Initializes the class members</summary>
        protected virtual void InitClassMembers()
        {
            _organization = null;
            _territory    = null;
            PerformDependencyInjection();

            // __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers
            // __LLBLGENPRO_USER_CODE_REGION_END
            OnInitClassMembersComplete();
        }
Esempio n. 19
0
        public void MapSetsGivenTerritoryIdToEntityTerritoryId()
        {
            const long expectedTerritoryId = 3;
            var        fakeTerritory       = new FakeTerritory(expectedTerritoryId);

            TerritoryEntity territoryEntity = _territoryFactory.Map(fakeTerritory);

            Assert.AreEqual(expectedTerritoryId, territoryEntity.TerritoryId,
                            "Territory ID was not mapped to entity correctly.");
        }
Esempio n. 20
0
        public void MapSetsParentTerritoryIdToNullWhenNullEntityParentTerritoryIdGiven()
        {
            var territoryEntity = new TerritoryEntity {
                ParentTerritoryId = null
            };

            Territory territory = _territoryFactory.Map(territoryEntity);

            Assert.IsNull(territory.ParentTerritoryId, "Non-null Parent Territory ID mapped.");
        }
Esempio n. 21
0
        public void CreateTerritoryEntitySetsDateCreatedToGivenDateCreated()
        {
            var expectedDateCreated = new DateTime(2003, 2, 3);
            var territory           = new FranchiseeTerritory();

            TerritoryEntity territoryEntity = _territoryFactory.CreateTerritoryEntity(territory, expectedDateCreated, DateTime.Now);

            Assert.AreEqual(expectedDateCreated, territoryEntity.DateCreated,
                            "DateCreated was not set on the entity correctly.");
        }
Esempio n. 22
0
        public void CreateTerritoryCreatesFranchiseeTerritoryWhenEntityTypeIsFranchiseeTerritory()
        {
            var territoryEntity = new TerritoryEntity {
                Type = (byte)TerritoryType.Franchisee
            };

            Territory territory = _territoryFactory.CreateTerritory(territoryEntity);

            Assert.IsInstanceOf <FranchiseeTerritory>(territory);
        }
Esempio n. 23
0
 protected sealed override void MapDomainFields(TerritoryEntity entity,
                                                T domainObjectToMapTo)
 {
     domainObjectToMapTo.Id          = entity.TerritoryId;
     domainObjectToMapTo.Name        = entity.Name;
     domainObjectToMapTo.Description = entity.Description;
     domainObjectToMapTo.ZipCodes    = _zipCodeMapper.
                                       MapMultiple(entity.ZipCollectionViaTerritoryZip).ToList();
     domainObjectToMapTo.ParentTerritoryId = entity.ParentTerritoryId;
     MapUniqueTerritoryFields(entity, domainObjectToMapTo);
 }
Esempio n. 24
0
        public void CreateTerritoryCreatesAdvertiserTerritoryWhenEntityIsAdvertiser()
        {
            var territoryEntity = new TerritoryEntity {
                Type = (byte)TerritoryType.Advertiser
            };

            Territory territory = _territoryFactory.CreateTerritory(territoryEntity);

            Assert.IsInstanceOf <AdvertiserTerritory>(territory,
                                                      "Incorrect type of Territory created.");
        }
Esempio n. 25
0
        public void MapSetsParentTerritoryIdToNullIfParentTerritoryIsNull()
        {
            var fakeTerritory = new FakeTerritory {
                ParentTerritoryId = null
            };

            TerritoryEntity territoryEntity = _territoryFactory.Map(fakeTerritory);

            Assert.IsNull(territoryEntity.ParentTerritoryId,
                          "Parent Territory ID of entity set to non-null value.");
        }
Esempio n. 26
0
 private void SaveTerritoryEntity(TerritoryEntity territoryEntity)
 {
     using (var myAdapter = PersistenceLayer.GetDataAccessAdapter())
     {
         if (!myAdapter.SaveEntity(territoryEntity))
         {
             throw new PersistenceFailureException
                       ("The territory could not be saved to the database.");
         }
     }
 }
Esempio n. 27
0
        public void CreateTerritoryCreatesHospitalPartnerTerritoryWhenEntityIsHospitalPartner()
        {
            var territoryEntity = new TerritoryEntity
            {
                Type = (byte)TerritoryType.HospitalPartner
            };

            Territory territory = _territoryFactory.CreateTerritory(territoryEntity);

            Assert.IsInstanceOf <HospitalPartnerTerritory>(territory);
        }
Esempio n. 28
0
        public void MapMapsEntityNameToTerritoryName()
        {
            const string expectedName    = "Bob's Territory";
            var          territoryEntity = new TerritoryEntity {
                Name = expectedName
            };

            Territory territory = _territoryFactory.Map(territoryEntity);

            Assert.AreEqual(expectedName, territory.Name, "Territory Name was not mapped correctly.");
        }
Esempio n. 29
0
        public void MapMapsParentTerritoryIdToEntityParentTerritoryId()
        {
            const long expectedParentTerritoryId = 3;
            var        fakeTerritory             = new FakeTerritory {
                ParentTerritoryId = expectedParentTerritoryId
            };

            TerritoryEntity territoryEntity = _territoryFactory.Map(fakeTerritory);

            Assert.AreEqual(expectedParentTerritoryId, territoryEntity.ParentTerritoryId,
                            "Parent Territory ID not mapped to entity correctly.");
        }
Esempio n. 30
0
        public void MapMapsTerritoryTypeToEntityTerritoryType()
        {
            const TerritoryType expectedTerritoryType = TerritoryType.Pod;
            var fakeTerritory = new FakeTerritory {
                FakeTerritoryType = expectedTerritoryType
            };

            TerritoryEntity territoryEntity = _territoryFactory.Map(fakeTerritory);

            Assert.AreEqual((byte)expectedTerritoryType, territoryEntity.Type,
                            "Territory Type was not mapped to entity correctly.");
        }
Esempio n. 31
0
        public void Add(Territory territory)
        {
            var entity = new TerritoryEntity
            {
                Description = territory.Description,
                IsActive = true,
            };

            _context.Territories.AddObject(entity);
            _context.SaveChanges();

            territory.Id = entity.Id;
        }