private async void DeleteCustomer(Contact contact)
		{
			var contactToDelete = contact;
			var deletedContactId = contactToDelete.MemberId;

			var customerRepository =
				_customerRepositoryFactory.GetRepositoryInstance();

			ShowLoadingAnimation = true;

			var cases = await Task.Run(() => customerRepository.Cases.Where(
				c => c.ContactId == deletedContactId).ToList());

			Parallel.ForEach(cases, c =>
			{
				customerRepository.Attach(c);
				c.Contact = null;
				c.ContactId = null;
			});

			await Task.Run(() =>
			{
				customerRepository.UnitOfWork.Commit();

				customerRepository.Attach(contactToDelete);
				customerRepository.Remove(contactToDelete);
				customerRepository.UnitOfWork.Commit();
			});

			ShowLoadingAnimation = false;

			Refresh();
		}
		public CustomerDetailViewModel(ISecurityService securityService, IViewModelsFactory<IPhoneNumberDialogViewModel> phoneVmFactory, IViewModelsFactory<IEmailDialogViewModel> emailVmFactory, IViewModelsFactory<ICreateUserDialogViewModel> wizardUserVmFactory, IViewModelsFactory<IAddressDialogViewModel> addressVmFactory, ICustomerEntityFactory entityFactory,
			IAuthenticationContext authContext, CustomersDetailViewModel parentViewModel, Contact innerContact,
			ICustomerRepository customerRepository, IRepositoryFactory<ISecurityRepository> securityRepositoryFactory,
			IRepositoryFactory<ICountryRepository> countryRepositoryFactory, IRepositoryFactory<IOrderRepository> orderRepositoryFactory, ILoginViewModel loginViewModel)
		{
			_securityService = securityService;
			_loginViewModel = loginViewModel;
			_parentViewModel = parentViewModel;
			_authContext = authContext;
			_customerRepository = customerRepository;
			_orderRepositoryFactory = orderRepositoryFactory;
			_securityRepositoryFactory = securityRepositoryFactory;
			_countryRepositoryFactory = countryRepositoryFactory;
			_entityFactory = entityFactory;
			_addressVmFactory = addressVmFactory;
			_wizardUserVmFactory = wizardUserVmFactory;
			_emailVmFactory = emailVmFactory;
			_phoneVmFactory = phoneVmFactory;
			_fileDialogService = new FileDialogService();

			InnerItem = innerContact;

			InnerItem.PropertyChanged += _innerContact_PropertyChanged;

			CommandsInit();
			RequestInit();
			CollectionInit();

			HasCurrentContactLoginAndSuspendAccessCheck();
		}
        public CreateCustomerDialogViewModel(Contact item)
        {
            InnerItem = item;
            InnerItem.PropertyChanged += InnerItem_PropertyChanged;

            EmailForUserInput=new Email();
            PhoneForUserInput = new Phone();
        }
        public CustomersDetailViewModel(ICustomerEntityFactory entityFactory, ICustomerRepository repository,
                    NavigationManager navManager, IRepositoryFactory<ICustomerRepository> repositoryFactory,
                    IAuthenticationContext authContext, ICustomersCommonViewModel parentViewModel,
                    Case innerCase, Contact innerContact,
                    CaseActionState caseAction, ContactActionState contactAction,
                    IViewModelsFactory<CaseDetailViewModel> caseDetailVmFactory, IViewModelsFactory<CustomerDetailViewModel> customerDetailVmFactory,
                    IViewModelsFactory<ICreateCustomerDialogViewModel> wizardCustomerVmFactory,
                    IViewModelsFactory<IKnowledgeBaseDialogViewModel> knowledgeBaseGroupVmFactory)
        {
            _entityFactory = entityFactory;
            Repository = repository;
            _authContext = authContext;
            _navManager = navManager;
            _repositoryFactory = repositoryFactory;
            _caseDetailVmFactory = caseDetailVmFactory;
            _customerDetailVmFactory = customerDetailVmFactory;
            _wizardCustomerVmFactory = wizardCustomerVmFactory;
            _knowledgeBaseGroupVmFactory = knowledgeBaseGroupVmFactory;
            _parentViewModel = parentViewModel;

            OriginalItem = innerCase;
            OriginalContact = innerContact;

            InnerItem = innerCase;
            CurrentCustomer = innerContact;

            CaseActionState = caseAction;
            ContactActionState = contactAction;

            InitializeCommands();

            _isItemsInitialized = false;

            ViewTitle = new ViewTitleBase
                {
                    SubTitle = string.Format("Case #{0}".Localize(), InnerItem.Number),
                    Title = "Customer Service"
                };


            _authorId = _authContext.CurrentUserId;
            _authorName = _authContext.CurrentUserName;
        }
Пример #5
0
        private void RaiseOpenItemInteractionRequest()
        {
            var parameters = new List<KeyValuePair<string, object>>();

            var customer = new Contact();
            var caseItem = new Case();
            if (_resultType == SearchResultType.Case)
            {
                caseItem.CaseId = _id;
                if (string.IsNullOrWhiteSpace(CaseContactId))
                {
                    parameters.Add(new KeyValuePair<string, object>("contactAction", ContactActionState.New));
                }
                else
                {
                    customer.MemberId = CaseContactId;
                    parameters.Add(new KeyValuePair<string, object>("contactAction", ContactActionState.Open));
                }

                parameters.Add(new KeyValuePair<string, object>("caseAction", CaseActionState.Open));
                parameters.Add(new KeyValuePair<string, object>("isContactOnlyShow", false));
            }
            else
            {
                customer.MemberId = _id;
                parameters.Add(new KeyValuePair<string, object>("contactAction", ContactActionState.Open));
                parameters.Add(new KeyValuePair<string, object>("caseAction", CaseActionState.None));
                parameters.Add(new KeyValuePair<string, object>("isContactOnlyShow", true));
            }
            parameters.Add(new KeyValuePair<string, object>("parentViewModel", _parentViewModel));
            parameters.Add(new KeyValuePair<string, object>("innerCase", caseItem));
            parameters.Add(new KeyValuePair<string, object>("innerContact", customer));

            var itemVM = _customersDetailVmFactory.GetViewModelInstance(parameters.ToArray());

            var openTracking = (IOpenTracking)itemVM;
            openTracking.OpenItemCommand.Execute();
        }
Пример #6
0
        public virtual Contact NewContact(string memberId = "")
        {
            var contact = new Contact { MemberId = memberId };

            if (String.IsNullOrEmpty(memberId))
            {
                var session = _customerSession.CustomerSession;

                if (session != null && !String.IsNullOrEmpty(session.CustomerId))
                {
                    contact.MemberId = session.CustomerId;
                }
            }

            if (String.IsNullOrEmpty(contact.MemberId))
            {
                throw new ArgumentNullException("memberId");
            }

            _customerRepository.Add(contact);

            return contact;
        }
Пример #7
0
		public CustomerViewModel(Contact item, IRepositoryFactory<ICustomerRepository> customerRepositoryFactory, ICustomerEntityFactory customerEntityFactory, IRepositoryFactory<ICountryRepository> countryRepositoryFactory, IViewModelsFactory<IAddressDialogViewModel> addressVmFactory)
        {
            _entityFactory = customerEntityFactory;
			_customerRepositoryFactory = customerRepositoryFactory;
			_addressVmFactory = addressVmFactory;
            _innerContact = item;

            _innerContact.PropertyChanged += _innerContact_PropertyChanged;

            CommandsInit();
            RequestInit();
            CollectionInit();

            //Get All Countries
            Action getAllCountiesAction = () =>
            {
				using (var repository = countryRepositoryFactory.GetRepositoryInstance())
                {
                    var countries = repository.Countries.Expand(c => c.Regions).OrderBy(c => c.Name).ToArray();
                    OnUIThread(() => { _allCountries = countries; });
                }
            };
            getAllCountiesAction.BeginInvoke(null, null);
        }
        public void Can_create_contact()
        {
            var client = GetRepository();

            var contactToDb = new Contact();
	        contactToDb.FullName = "name_for_test_contact";

            client.Add(contactToDb);
            client.UnitOfWork.Commit();

            client = GetRepository();

            var contactFromDb =
                client.Members.Where(m => m.MemberId == contactToDb.MemberId).OfType<Contact>().SingleOrDefault();

            Assert.NotNull(contactFromDb);
        }
        public void Can_edit_Phone_in_Contact()
        {
            var client = GetRepository();

			var contactWithNewPhone = new Contact();
			contactWithNewPhone.FullName = "test";

            //create new phone
            var phoneToAdd = new Phone();
            phoneToAdd.Number = "228810";

			contactWithNewPhone.Phones.Add(phoneToAdd);

			client.Add(contactWithNewPhone);
            client.UnitOfWork.Commit();


            client = GetRepository();

            var contactForCheck = client.Members.OfType<Contact>().
                                         Expand(c => c.Phones).FirstOrDefault();

            client.Attach(contactForCheck);

            Assert.NotNull(contactForCheck);

            //get phone for update
            var phoneForCheck = contactForCheck.Phones.Where(p => p.PhoneId == phoneToAdd.PhoneId).SingleOrDefault();
            Assert.NotNull(phoneForCheck);

            phoneForCheck.Number = "666";

            client.UnitOfWork.Commit();


            client = GetRepository();

            contactForCheck = client.Members.OfType<Contact>().
                                     Expand(c => c.Phones).FirstOrDefault();
			Assert.NotNull(contactForCheck);

            phoneForCheck = contactForCheck.Phones.Where(p => p.PhoneId == phoneToAdd.PhoneId).SingleOrDefault();
            Assert.NotNull(phoneForCheck);
            Assert.True(phoneForCheck.Number == "666");
        }
        public void Can_create_Notes_in_Contact()
        {
            var client = GetRepository();


	        var contactWithNewNote = new Contact();
	        contactWithNewNote.FullName = "test";

            var noteForContact = new Note();
            noteForContact.Body = "noteForCase";


			contactWithNewNote.Notes.Add(noteForContact);
			client.Add(contactWithNewNote);

            client.UnitOfWork.Commit();

            client = GetRepository();


			var contactForCheck = client.Members.Where(m => m.MemberId == contactWithNewNote.MemberId).OfType<Contact>()
                                        .Expand(c => c.Notes).SingleOrDefault();

            Assert.NotNull(contactForCheck);
            Assert.True(contactForCheck.Notes.Count >= 1);
        }
	    public void Can_create_Email_in_Contact()
	    {
		    var client = GetRepository();

		    var contactWithNewEmail = new Contact();
		    contactWithNewEmail.FullName = "test";

		    var emailToAdd = new Email();
		    emailToAdd.Address = "*****@*****.**";
		    emailToAdd.Type = "Primary";

		    contactWithNewEmail.Emails.Add(emailToAdd);

		    client.Add(contactWithNewEmail);
		    client.UnitOfWork.Commit();


		    client = GetRepository();

		    var contactFromDb =
			    client.Members.OfType<Contact>()
				    .Where(c => c.MemberId == contactWithNewEmail.MemberId)
				    .Expand(c => c.Emails)
				    .SingleOrDefault();

		    Assert.NotNull(contactFromDb);
		    Assert.True(contactFromDb.Emails.Count == 1);
	    }
        public void Can_edit_Address_in_Contact()
        {
            var client = GetRepository();

			var contactWithNewAddress = new Contact();
			contactWithNewAddress.FullName = "test";


            var address1 = new Address();
	        address1.Name = "testName1";
            address1.City = "testCity1";
            address1.CountryCode = "testCountryCode1";
            address1.CountryName = "testCountryName1";
            address1.Line1 = "testLine1_1";
            address1.Line2 = "testLine2_1";
            address1.PostalCode = "testPostalCode1";
            address1.RegionName = "testResgion1";
            address1.StateProvince = "testState1";
            address1.Type = "Primary";

            var address2 = new Address();
			address2.Name = "testName2";
            address2.City = "testCity2";
            address2.CountryCode = "testCountryCode2";
            address2.CountryName = "testCountryName2";
            address2.Line1 = "testLine1_2";
            address2.Line2 = "testLine2_2";
            address2.PostalCode = "testPostalCode2";
            address2.RegionName = "testResgion2";
            address2.StateProvince = "testState2";
            address2.Type = "Primary";

            //add 2 addresses to contact
			contactWithNewAddress.Addresses.Add(address1);
			contactWithNewAddress.Addresses.Add(address2);

			Assert.True(contactWithNewAddress.Addresses.Count != 0);

            //save contact
			client.Add(contactWithNewAddress);
            client.UnitOfWork.Commit();


            client = GetRepository();

			var contactForCheck = client.Members.Where(m => m.MemberId == contactWithNewAddress.MemberId).OfType<Contact>().
                                         Expand(c => c.Addresses).SingleOrDefault();

            client.Attach(contactForCheck);

            Assert.NotNull(contactForCheck);
            Assert.NotNull(contactForCheck.Addresses);
            Assert.True(contactForCheck.Addresses.Count == 2);

            //edit address 1
            var address1ForCheck =
                contactForCheck.Addresses.Where(a => a.AddressId == address1.AddressId).SingleOrDefault();
            address1ForCheck.Line1 = "updated line 1_1";
            address1ForCheck.Line2 = "updated line 2_1";
            //edit address 2
            var address2ForCheck =
                contactForCheck.Addresses.Where(a => a.AddressId == address2.AddressId).SingleOrDefault();
            address2ForCheck.Line1 = "updated line 1_2";
            address2ForCheck.Line2 = "updated line 2_2";

			
            client.UnitOfWork.Commit();


            client = GetRepository();

            var contactForDelete =
				client.Members.Where(m => m.MemberId == contactWithNewAddress.MemberId).OfType<Contact>().
                       Expand(c => c.Addresses).SingleOrDefault();

            client.Attach(contactForDelete);

            Assert.NotNull(contactForDelete);
            Assert.NotNull(contactForDelete.Addresses);
            Assert.True(contactForDelete.Addresses.Count >= 2);

            var updatedAddress1 =
                contactForDelete.Addresses.Where(a => a.AddressId == address1ForCheck.AddressId).SingleOrDefault();

            Assert.NotNull(updatedAddress1);
            Assert.True(updatedAddress1.Line1 == "updated line 1_1");
            Assert.True(updatedAddress1.Line2 == "updated line 2_1");

            var updatedAddress2 =
                contactForDelete.Addresses.Where(a => a.AddressId == address2ForCheck.AddressId).SingleOrDefault();

            Assert.NotNull(updatedAddress2);
            Assert.True(updatedAddress2.Line1 == "updated line 1_2");
            Assert.True(updatedAddress2.Line2 == "updated line 2_2");


            contactForDelete.Addresses.Clear();
            client.Remove(updatedAddress1);
            client.Remove(updatedAddress2);

            client.UnitOfWork.Commit();


            client = GetRepository();

            var contactWithRemovedAddresses =
				client.Members.Where(m => m.MemberId == contactWithNewAddress.MemberId).OfType<Contact>().
                       Expand(c => c.Addresses).SingleOrDefault();

            Assert.NotNull(contactWithRemovedAddresses);
            Assert.NotNull(contactWithRemovedAddresses.Addresses);
            Assert.True(contactWithRemovedAddresses.Addresses.Count == 0);
        }
Пример #13
0
	    /// <summary>
	    /// Registers the specified user.
	    /// </summary>
	    /// <param name="model">The registration model.</param>
	    /// <param name="errorMessage">The error message that occured during regustration.</param>
	    /// <param name="requireConfirmation">if set to <c>true</c> [require confirmation].</param>
	    /// <param name="token">Confirmation token</param>
	    /// <returns>
	    /// true when user is registered and logged in
	    /// </returns>
	    public static bool Register(RegisterModel model, bool requireConfirmation, out string errorMessage, out string token)
        {
            errorMessage = string.Empty;
            token = string.Empty;

            try
            {
                var id = Guid.NewGuid().ToString();

                token = UserSecurity.CreateUserAndAccount(model.Email, model.Password, new
                {
                    MemberId = id,
                    CustomerSession.StoreId,
                    RegisterType = RegisterType.GuestUser.GetHashCode(),
                    AccountState = requireConfirmation ? AccountState.PendingApproval.GetHashCode() : AccountState.Approved.GetHashCode(),
                    Discriminator = "Account"
                }, requireConfirmation);

                var contact = new Contact
                {
                    MemberId = id,
                    FullName = String.Format("{0} {1}", model.FirstName, model.LastName)
                };
                contact.Emails.Add(new Email { Address = model.Email, MemberId = id, Type = EmailType.Primary.ToString() });
                foreach (var addr in model.Addresses)
                {
                    contact.Addresses.Add(addr);
                }

                UserClient.CreateContact(contact);

                return requireConfirmation || UserSecurity.Login(model.Email, model.Password);
            }
            catch (MembershipCreateUserException e)
            {
                errorMessage = ErrorCodeToString(e.StatusCode);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            return false;
        }
	    public void Can_create_labels_to_case_and_contact()
		{

			var client = GetRepository();

			var contactToDb = new Contact();
			contactToDb.FullName = "test";

			var caseToDb = new Case();

			contactToDb.Cases.Add(caseToDb);

			var labelForContact = new Label(){Name = "testName", Description = "testDescription"};

			var labelForCase = new Label() { Name = "testName", Description = "testDescription"};

			caseToDb.Labels.Add(labelForCase);
			
			contactToDb.Labels.Add(labelForContact);

			client.Add(contactToDb);
			client.UnitOfWork.Commit();


			client = GetRepository();

			var contactFromDB =
				client.Members.OfType<Contact>()
					.Where(c => c.MemberId == contactToDb.MemberId)
					.Expand(c => c.Cases)
					.Expand(c => c.Labels).SingleOrDefault();

			Assert.NotNull(contactFromDB);
			Assert.NotNull(contactFromDB.Cases);
			Assert.True(contactFromDB.Labels.Count==1);



			var caseFromDb =
				client.Cases.Where(c => c.CaseId == caseToDb.CaseId).Expand(c => c.Labels).SingleOrDefault();

			Assert.NotNull(caseFromDb);
			Assert.True(caseFromDb.Labels.Count == 1);

		}
		private Contact CreateContact(string firstName, string lastName, DateTime birthDate, string photoUrl)
		{
			Contact cont = new Contact();


			cont.FullName = firstName+" "+lastName;
			cont.BirthDate = birthDate;

			return cont;

		}
Пример #16
0
		/// <summary>
		/// Creates the contact.
		/// </summary>
		/// <param name="contact">The contact.</param>
        public virtual void CreateContact(Contact contact)
        {
            _customerRepository.Add(contact);
            SaveCustomerChanges();
        }
		public void CreateContactTest()
		{
			var client = GetRepository();

			Member contactToDb = new Contact();
			//client.Attach(contactToDb);
			client.Add(contactToDb);
			client.UnitOfWork.Commit();

			client = GetRepository();

			var contactFromDb = client.Members.Where(m => m.MemberId == contactToDb.MemberId).OfType<Contact>().SingleOrDefault();

			Assert.IsNotNull(contactFromDb);
		}
        public async void InitializeForOpen()
        {
            if (!_isItemsInitialized)
            {
                ShowLoadingAnimation = true;

                Repository = _repositoryFactory.GetRepositoryInstance();

                await Task.Run(() =>
                    {
                        //loading or creating contact
                        switch (ContactActionState)
                        {
                            case ContactActionState.New:
                                CurrentCustomer = new Contact();
                                break;

                            case ContactActionState.Open:
                                _originalContact =
                                    Repository.Members.Where(m => m.MemberId == _innerContact.MemberId)
                                               .OfType<Contact>()
                                               .Expand(c => c.Addresses)
                                               .Expand(c => c.Emails)
                                               .Expand(c => c.Labels)
                                    /*.Expand(c => c.Notes)*/.Expand(c => c.Phones).SingleOrDefault();

                                var contactNotes = Repository.Notes.Where(n => n.MemberId == CurrentCustomer.MemberId).ToList();
                                OnUIThread(() =>
                                {
                                    CurrentCustomer = _originalContact;
                                    ContactNotes = contactNotes;
                                });


                                if (CaseActionState == CaseActionState.None)
                                {
                                    IsCaseOptionSelected = false;
                                    IsCustomerOptionSelected = true;
                                }
                                break;
                        }

                        //loading or creating case
                        switch (CaseActionState)
                        {
                            case CaseActionState.None:
                                IsCaseOptionSelected = false;
                                IsCustomerOptionSelected = true;
                                break;

                            case CaseActionState.New:
                                InnerItem = new Case();
                                InnerItem.Status = CaseStatus.Open.ToString();
                                InnerItem.Number = UniqueNumberGenerator.GetUniqueNumber();

                                IsCaseOptionSelected = true;
                                IsCustomerOptionSelected = false;

                                break;

                            case CaseActionState.Open:

                                _originalItem =
                                    Repository.Cases.Where(c => c.CaseId == _originalItem.CaseId)
                                    /*.Expand(c => c.Notes)*/
                                                .Expand(c => c.Labels)
                                               .Expand(c => c.CaseCc).SingleOrDefault();



                                InnerItem = _originalItem.DeepClone(_entityFactory as IKnownSerializationTypes);

                                CaseCommunicationItems = Repository.CommunicationItems.Where(ci => ci.CaseId == InnerItem.CaseId).ToList();
                                CaseNotes = Repository.Notes.Where(n => n.CaseId == InnerItem.CaseId).ToList();

                                _oldCasePropertyValues =
                                    Repository.CasePropertyValues.Where(x => x.CaseId == InnerItem.CaseId)
                                               .ToList();

                                IsCaseOptionSelected = true;
                                IsCustomerOptionSelected = false;
                                break;
                        }
                    });

                await Task.Run(() =>
                    {
                        InitializeViewModels();
                        InitCommunicationControl();
                    });

                OnPropertyChanged("CaseCommunications");
                OnPropertyChanged("CustomerNotes");

                if (CaseCommunications != null && !CaseCommunications.IsInitialized)
                {
                    RefreshCaseCommunicationItems();
                }
                if (CustomerNotes != null && !CustomerNotes.IsInitialized)
                {
                    RefreshCustomerNotesItems();
                }


                SaveChangesCommand.RaiseCanExecuteChanged();
                ResolveAndSaveCommand.RaiseCanExecuteChanged();
                ProcessAndSaveCommand.RaiseCanExecuteChanged();

                _isItemsInitialized = true;
                IsModified = false;

                OnPropertyChanged("IsValidForSave");
                OnPropertyChanged("IsValid");
                OnPropertyChanged("InnerItem");
                OnPropertyChanged("CurrentCustomer");


                ShowLoadingAnimation = false;

                OnCaseOrContactStateChanged();
            }
        }
        private async Task DoSaveChanges()
        {
            try
            {
                ShowLoadingAnimation = true;
                await Task.Run(() =>
                    {
                        DoSaveChangesAsync();
                        Repository.UnitOfWork.Commit();
                        UpdateCaseAndContactCommunicationItems();
                        UpdateCaseAndContactLabels();
                    });

                _originalContact = CurrentCustomer;
                _originalItem = InnerItem;

                _oldCasePropertyValues =
                                    Repository.CasePropertyValues.Where(x => x.CaseId == InnerItem.CaseId)
                                               .ToList();

                if (CaseActionState != CaseActionState.None)
                {
                    CaseActionState = CaseActionState.Open;
                }

                ContactActionState = ContactActionState.Open;

                OnUIThread(() =>
                    {
                        OnPropertyChanged("OriginalItem");
                        OnPropertyChanged("OriginalContact");
                        OnPropertyChanged("Status");
                        IsModified = false;
                        if (CaseActionState != CaseActionState.None)
                        {
                            _parentViewModel.Refresh();
                        }
                    });
            }
            catch (Exception ex)
            {
                ShowErrorDialog(ex, string.Format("An error occurred when trying to save changes: {0}".Localize(null, LocalizationScope.DefaultCategory), ex.InnerException.Message));
            }
            finally
            {
                ShowLoadingAnimation = false;
            }

        }
Пример #20
0
        /// <summary>
        /// Registers the specified user.
        /// </summary>
        /// <param name="model">The registration model.</param>
        /// <param name="requireConfirmation">if set to <c>true</c> [require confirmation].</param>
        /// <returns>
        /// true when user is registered and logged in
        /// </returns>
        public static async Task<RegistrationResult> RegisterAsync(RegisterModel model, bool requireConfirmation)
	    {
	        var retVal = new RegistrationResult();

            try
            {
                var id = Guid.NewGuid().ToString();

                retVal.ConfirmationToken = await UserSecurity.CreateUserAndAccountAsync(model.Email, model.Password, new
                {
                    MemberId = id,
                    CustomerSession.StoreId,
                    RegisterType = RegisterType.GuestUser.GetHashCode(),
                    AccountState = requireConfirmation ? AccountState.PendingApproval.GetHashCode() : AccountState.Approved.GetHashCode(),
                    Discriminator = "Account"
                }, requireConfirmation);

                var contact = new Contact
                {
                    MemberId = id,
                    FullName = String.Format("{0} {1}", model.FirstName, model.LastName)
                };
                contact.Emails.Add(new Email { Address = model.Email, MemberId = id, Type = EmailType.Primary.ToString() });
                foreach (var addr in model.Addresses)
                {
                    contact.Addresses.Add(addr);
                }

                UserClient.CreateContact(contact);

                retVal.IsSuccess = requireConfirmation || await UserSecurity.LoginAsync(model.Email, model.Password) == SignInStatus.Success;

                return retVal;
            }
            catch (MembershipCreateUserException e)
            {
                retVal.ErrorMessage = ErrorCodeToString(e.StatusCode);
            }
            catch (Exception ex)
            {
                retVal.ErrorMessage = ex.Message;
            }

            return retVal;
        }
        private void LstItems_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (SelectedItemFromPopup != null)
            {

                string contactName = SelectedItemFromPopup.FullName;
                txtInput.TextChanged -= txtInput_TextChanged;
                txtInput.Text = contactName;
                popupSearch.IsOpen = false;
                SelectedItemFromPopup = null;
                txtInput.TextChanged += txtInput_TextChanged;
            }
        }
		public void CreateNewContactWithNewCaseTest()
		{
			//ICustomerRepository client = new EFCustomersRepository(new CustomerEntityFactory());
			var client = GetRepository();


			Contact contactToDb = new Contact();
			contactToDb.BirthDate = new DateTime(1970, 8, 15);
			contactToDb.FullName = "dataServiceFullnameTest";

			Case caseToDb = new Case();
			caseToDb.Description = "dataServiceDescriptionTest";
			caseToDb.Number = "qweqweas";
			caseToDb.Priority = 1;
			caseToDb.Status = CaseStatus.Open.ToString();
			caseToDb.Title = "dataServiceTitleTest";



			contactToDb.Addresses.Add(CreateAddress("Верхнеозерная", "25/8", "Калининград", "RUS", "Russianfederation", string.Empty, "238210", "Primary"));
			contactToDb.Addresses.Add(CreateAddress("пл. Победы", "1", "Калининград", "RUS", "Russianfederation", string.Empty, "666259", "Shipping"));

            contactToDb.Emails.Add(new Email { Address = "*****@*****.**", Type = "Primary" });
            contactToDb.Emails.Add(new Email { Address = "*****@*****.**", Type = "Secondary" });

			contactToDb.Phones.Add(new Phone { Number = "12346578912", Type = "Primary" });


			//add labels

			var labels = client.Labels.ToList();

			foreach (var lb in labels)
			{
				client.Attach(lb);
			}

			var label1 = labels[0];
			var label2 = labels[1];

			contactToDb.Labels.Add(label1);

			caseToDb.Labels.Add(label1);
			caseToDb.Labels.Add(label2);


			//save new contact in db
			caseToDb.ContactId = contactToDb.MemberId;
			client.Add(caseToDb);
			client.Add(contactToDb);



			client.UnitOfWork.Commit();

			string contactId = contactToDb.MemberId;

			client = new DSCustomerClient(service.ServiceUri, new CustomerEntityFactory(), null);

			Contact contactFromDb = client.Members.Where(m => (m as Contact).MemberId == contactId).OfType<Contact>()
				.Expand(c => c.Addresses).Expand(c => c.Cases).Expand(c => c.Emails)
				.Expand(c => c.Labels).Expand(c => c.Notes).Expand(c => c.Phones).SingleOrDefault();


			//contact is saved correctly
			Assert.IsNotNull(contactFromDb);
			//cases count>0
			Assert.IsTrue(contactFromDb.Cases.Count > 0);
			//addresses count>0
			Assert.IsTrue(contactFromDb.Addresses.Count > 0);
			//phones count > 0
			Assert.IsTrue(contactFromDb.Phones.Count > 0);
			//emails count > 0
			Assert.IsTrue(contactFromDb.Emails.Count > 0);

			Assert.IsTrue(contactToDb.Labels.Count == 1);

		}
		protected void CreateNewCommerceManagerCase(Contact contact, ContactActionState contactAction,
												  CaseActionState caseAction)
		{
			var parameters = new List<KeyValuePair<string, object>>()
				{
					new KeyValuePair<string, object>("parentViewModel", this),
					new KeyValuePair<string, object>("innerCase", new Case()),
					new KeyValuePair<string, object>("innerContact", contact),
					new KeyValuePair<string, object>("caseAction", caseAction),
					new KeyValuePair<string, object>("contactAction", contactAction)
				}.ToArray();
			var itemVm = _customersDetailVmFactory.GetViewModelInstance(parameters);
			((IOpenTracking)itemVm).OpenItemCommand.Execute();
		}
Пример #24
0
		/// <summary>
		/// Creates customer model from contact.
		/// </summary>
		/// <param name="contact">The contact.</param>
		/// <returns>CustomerModel.</returns>
        public static CustomerModel GetCustomerModel(Contact contact)
        {
            if (contact == null)
            {
                contact = new Contact();
            }

            var model = new CustomerModel();

            model.InjectFrom(contact);
            var email = contact.Emails.FirstOrDefault(e => e.Type == EmailType.Primary.ToString());
            if (email != null)
            {
                model.Email = email.Address;
            }

            return model;
        }
Пример #25
0
		/// <summary>
		/// Creates OrderAddressModel from given Contact
		/// </summary>
		/// <param name="user">The contact</param>
		/// <returns>OrderAddressModel.</returns>
        public static OrderAddressModel GetShippingBillingForCustomer(Contact user)
        {
            var retVal = new OrderAddressModel {CurrentUser = GetCustomerModel(user)};

            if (user != null && user.Addresses.Count > 0)
            {
                retVal.BillingAddress = user.Addresses.FirstOrDefault(x => x.Name.Contains(DefaultBilling));
                retVal.ShippingAddress = user.Addresses.FirstOrDefault(x => x.Name.Contains(DefaultShipping));
            }

            retVal.OthersAddresses = new Address[] {};
            var allOthers = new List<Address>();
            if (user != null)
            {
                allOthers.AddRange(
                    user.Addresses.Where(
                        addr => !addr.Name.Contains(DefaultShipping) && !addr.Name.Contains(DefaultBilling)));
            }

            retVal.OthersAddresses = allOthers.ToArray();
            return retVal;
        }
Пример #26
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CompanyNewUserModel"/> class.
		/// </summary>
		/// <param name="u">The u.</param>
        public CompanyNewUserModel(Contact u)
        {
            //this.FirstName = u.FirstName;
            //this.LastName = u.LastName;
            //this.EMail = u.Email;
            UserId = u.MemberId;
            CurrentUser = u;
        }
		private void CreateNewCommerceManagerCaseForCurrentContact(Contact contact)
		{
			CreateNewCommerceManagerCase(contact, ContactActionState.Open, CaseActionState.New);
		}