Ejemplo n.º 1
0
        public EditProfileVM GetEditProfileVM()
        {
            var user   = AuthService.CurrentUser;
            var result =
                new EditProfileVM
            {
                User = AuthService.CurrentUser,
            };

            SetDictionaries(result);

            if (result.User != null)
            {
                var contactsVM = result.Contacts;
                if (user.IsCompany)
                {
                    contactsVM.Phone = GetContact(user.Company.UserContacts,
                                                  ContactTypes.Phone);
                    contactsVM.Mobile =
                        GetContact(user.Company.UserContacts, ContactTypes.Mobile);
                    contactsVM.WorkPhone =
                        GetContact(user.Company.UserContacts, ContactTypes.WorkPhone);
                    result.UserAddress = user.Company.UserAddresses.FirstOrDefault();
                }
                else
                {
                    result.UserAddress = user.UserAddresses.FirstOrDefault();

                    contactsVM.Socials = GetSocials(user.UserContacts);

                    InitPhones(user, contactsVM);
                }
            }
            else
            {
                result.User = new User();
            }

            if (result.UserAddress == null)
            {
                result.UserAddress = new UserAddress();
            }
            if (result.Company == null)
            {
                result.Company = new Company();
            }
            result.ContactTypes = UserContractTypeService.GetAll()
                                  .Where(uct => ContactTypes.ForProfile().Contains(uct.ContactTypeID))
                                  .ToList();


            return(result);
        }
Ejemplo n.º 2
0
        private List <UserContact> GetSocials(EntitySet <UserContact> contacts)
        {
            var allSocials      = ContactTypes.GetAllSocialServices();
            var currentContacts = contacts
                                  .Where(x => allSocials.Contains(x.ContactTypeID));
            var forAdd = allSocials.Where(x =>
                                          currentContacts.All(y => y.ContactTypeID != x));

            if (forAdd.Any())
            {
                var userContacts = UserContractTypeService.GetByPK(forAdd.Cast <object>())
                                   .ToList()
                                   .Select(x => new UserContact {
                    ContactTypeID   = x.ContactTypeID,
                    UserContactType = x
                });
                currentContacts = currentContacts.Union(userContacts).ToList();
            }
            return(currentContacts.OrderBy(x => allSocials.IndexOf(x.ContactTypeID)).ToList());
        }