Beispiel #1
0
        /// <summary>
        /// Populates the UpdateProfileModel.
        /// </summary>
        /// <param name="model">The UpdateProfileModel instance </param>
        /// <param name="userEntity">The UserEntity object</param>
        /// <returns>Returns an <see cref="UpdateProfileModel"/> model instance.</returns>
        private UpdateProfileModel BuildUpdateModelMetaData(UpdateProfileModel model, UserEntity userEntity)
        {
            model.CreateLanguageList();

            var facilityRelationship = userEntity.Relationships.FirstOrDefault(r => r.RelationshipTypeKey == EntityRelationshipTypeKeys.DedicatedServiceDeliveryLocation);

            var place = facilityRelationship?.TargetEntity as Place;

            if (facilityRelationship?.TargetEntityKey.HasValue == true && place == null)
            {
                place = this.ImsiClient.Get <Place>(facilityRelationship.TargetEntityKey.Value, null) as Place;
            }

            if (place != null)
            {
                var facility = new List <FacilityModel>
                {
                    new FacilityModel(string.Join(" ", place.Names.SelectMany(n => n.Component).Select(c => c.Value)), place.Key?.ToString())
                };

                model.FacilityList.AddRange(facility.Select(f => new SelectListItem {
                    Text = f.Name, Value = f.Id, Selected = f.Id == place.Key?.ToString()
                }));
                model.Facility = place.Key?.ToString();
            }

            var phoneTypes = this.GetPhoneTypeConceptSet().Concepts.ToList();

            Guid phoneType;

            model.PhoneTypeList = this.IsValidId(model.PhoneType) && Guid.TryParse(model.PhoneType, out phoneType) ? phoneTypes.ToSelectList(this.HttpContext.GetCurrentLanguage(), p => p.Key == phoneType).ToList() : phoneTypes.ToSelectList(this.HttpContext.GetCurrentLanguage()).ToList();

            if (userEntity.Telecoms.Any())
            {
                //can have more than one contact - default to show mobile
                if (userEntity.Telecoms.Any(t => t.AddressUseKey == TelecomAddressUseKeys.MobileContact))
                {
                    model.PhoneNumber = userEntity.Telecoms.First(t => t.AddressUseKey == TelecomAddressUseKeys.MobileContact).Value;
                    model.PhoneType   = TelecomAddressUseKeys.MobileContact.ToString();
                }
                else
                {
                    model.PhoneNumber = userEntity.Telecoms.FirstOrDefault()?.Value;
                    model.PhoneType   = userEntity.Telecoms.FirstOrDefault()?.AddressUseKey?.ToString();
                }
            }
            else
            {
                //Default to Mobile - requirement
                model.PhoneType = TelecomAddressUseKeys.MobileContact.ToString();
            }

            return(model);
        }