Example #1
0
        private void LoadAccount(string parameter)
        {
            // Really, we need to add validation that the code doesn't already exist for the account and do something else if it does.
            if (parameter != null && parameter != _account_code_holder && parameter != "")
            {
                string acct_code = parameter;
                var    curr_co   = CurrentCompany as Company;

                ExecuteFaultHandledOperation(() =>
                {
                    IAccountService account_service = service_factory.CreateClient <IAccountService>();
                    using (account_service)
                    {
                        Client.Entities.Account _account = account_service.GetAccountByCode(acct_code, curr_co.CompanyCode);

                        if (_account != null)
                        {
                            MapAccount(_account);
                        }
                    }

                    GetAttributeList();
                });
            }
        }
        private void GetOrder(int order_key)
        {
            ExecuteFaultHandledOperation(() =>
            {
                IOrderService order_service = service_factory.CreateClient <IOrderService>();
                using (order_service)
                {
                    Order           = new OrderWrapper(order_service.GetOrder(order_key));
                    AccountContacts = new ObservableCollection <AccountPerson>(Order.Account.Model.Employees.Where(item =>
                                                                                                                   item.CompanyRoleType == QIQOPersonType.AccountContact).ToList());
                    Order.PropertyChanged += Context_PropertyChanged;
                    Order.AcceptChanges();
                    _currentAccount = Order.Account.Model;
                }

                DefaultBillingAddress  = Order.OrderItems[0].OrderItemBillToAddress;
                DefaultShippingAddress = Order.OrderItems[0].OrderItemShipToAddress;
                ViewTitle     = Order.OrderNumber;
                GridIsEnabled = Order.OrderStatus != QIQOOrderStatus.Complete ? true : false;
                //AccountContacts = new ObservableCollection<AccountPerson>(Order.Account.Model.Employees.Where(item =>
                //                                                            item.CompanyRoleType == QIQOPersonType.AccountContact).ToList());
                event_aggregator.GetEvent <GeneralMessageEvent>().Publish($"Order {Order.OrderNumber} loaded successfully");
                event_aggregator.GetEvent <OrderLoadedEvent>().Publish(Order.OrderNumber);
            });
        }
 private BusinessItem Map(Client.Entities.Account account)
 {
     return(new BusinessItem
     {
         ItemType = account.AccountType.ToString(),
         ItemCode = account.AccountCode,
         ItemName = account.AccountName,
         ItemEntryDate = account.AccountStartDate,
         BusinessObject = account
     });
 }
Example #4
0
        private void ChooseAccount()
        {
            Client.Entities.Account sel_acct = SelectedAccount as Client.Entities.Account;
            if (sel_acct != null)
            {
                if (notification != null)
                {
                    notification.SelectedItem = sel_acct;
                    notification.Confirmed    = true;
                }

                FinishInteraction();
            }
        }
Example #5
0
        private void MapAccount(Client.Entities.Account _account)
        {
            if (_account != null)
            {
                _account_code_holder = _account.AccountCode;

                Account = new AccountWrapper(_account);

                AddressWrapper ship_addy = Account.Addresses.Where(type => type.AddressType == QIQOAddressType.Shipping).FirstOrDefault();
                if (ship_addy != null)
                {
                    DefaultShippingAddress = ship_addy; // new AddressWrapper(ship_addy);
                }
                else
                {
                    DefaultShippingAddress = new AddressWrapper(new Address()
                    {
                        AddressType = QIQOAddressType.Shipping
                    });
                }

                AddressWrapper bill_addy = Account.Addresses.Where(type => type.AddressType == QIQOAddressType.Billing).FirstOrDefault();
                if (bill_addy != null)
                {
                    DefaultBillingAddress = bill_addy; // new AddressWrapper(bill_addy);
                }
                else
                {
                    DefaultBillingAddress = new AddressWrapper(new Address()
                    {
                        AddressType = QIQOAddressType.Billing
                    });
                }

                AddressWrapper mail_addy = Account.Addresses.Where(type => type.AddressType == QIQOAddressType.Mailing).FirstOrDefault();
                if (mail_addy != null)
                {
                    DefaultMailingAddress = mail_addy; // new AddressWrapper(mail_addy);
                }
                else
                {
                    DefaultMailingAddress = new AddressWrapper(new Address()
                    {
                        AddressType = QIQOAddressType.Mailing
                    });
                }
            }
        }
        private void GetAccount(string accountCode)
        {
            //throw new NotImplementedException();
            ExecuteFaultHandledOperation(() =>
            {
                var accountService = _serviceFactory.CreateClient <IAccountService>();
                var comp           = CurrentCompany as Company;

                using (accountService)
                {
                    var account = accountService.GetAccountByCode(accountCode, comp.CompanyCode);
                    if (account != null)
                    {
                        if (account.Employees != null)
                        {
                            AccountContacts = new ObservableCollection <AccountPerson>(account.Employees.Where(item => item.CompanyRoleType == QIQOPersonType.AccountContact).ToList());
                        }
                        // Get the accounts main contact key
                        var contact = account.Employees.Where(item => item.CompanyRoleType == QIQOPersonType.AccountContact).FirstOrDefault();
                        int cnt_key = contact != null ? contact.EntityPersonKey : 1;

                        Invoice.Account.AccountKey  = account.AccountKey;
                        Invoice.Account.AccountName = account.AccountName;
                        Invoice.Account.AccountCode = account.AccountCode;
                        Invoice.Account.AccountDBA  = account.AccountDBA;
                        Invoice.Account.AccountDesc = account.AccountDesc;
                        Invoice.AccountKey          = account.AccountKey;
                        Invoice.Account.AccountType = account.AccountType;
                        Invoice.AccountContactKey   = cnt_key; // account.Employees[0].EntityPersonKey;
                        Invoice.InvoiceAccountContact.PersonFullNameFML = contact != null ? contact.PersonFullNameFML : "N/A";
                        //Invoice.AccountRepKey = AccountRepList[0].EntityPersonKey;
                        //Invoice.SalesRepKey = SalesRepList[0].EntityPersonKey;
                        DefaultBillingAddress  = new AddressWrapper(account.Addresses.Where(item => item.AddressType == QIQOAddressType.Billing).FirstOrDefault());
                        DefaultShippingAddress = new AddressWrapper(account.Addresses.Where(item => item.AddressType == QIQOAddressType.Shipping).FirstOrDefault());
                        FeeScheduleList        = new ObservableCollection <FeeSchedule>(account.FeeSchedules);
                        _currentAccount        = account;
                        RaisePropertyChanged(nameof(Invoice));
                        GridIsEnabled = true;
                    }
                    else
                    {
                        DisplayErrorMessage($"Account with code '{accountCode}' not found");
                    }
                }
            });
            _eventAggregator.GetEvent <NavigationEvent>().Publish(ViewNames.InvoiceHomeView);
        }
        private void FindAccount()
        {
            ItemSelectionNotification notification = new ItemSelectionNotification();

            notification.Title = ApplicationStrings.NotificationFindAccount;
            FindAccountRequest.Raise(notification,
                                     r => {
                if (r != null && r.Confirmed && r.SelectedItem != null)
                {
                    Client.Entities.Account found_account = r.SelectedItem as Client.Entities.Account;
                    if (found_account != null)
                    {
                        GetAccount(found_account.AccountCode);
                    }
                }
            });
        }
        private void GetAccount(int account_key)
        {
            ExecuteFaultHandledOperation(() =>
            {
                IAccountService account_service = service_factory.CreateClient <IAccountService>();
                using (account_service)
                {
                    Client.Entities.Account _account = account_service.GetAccountByID(account_key, true);

                    if (_account != null)
                    {
                        MapAccount(_account);
                    }

                    GetAttributeList();
                }
            });
        }
        private AccountWrapper LoadAccount(string account_no)
        {
            if (account_no != null & account_no != "")
            {
                var curr_co = CurrentCompany as Company;

                var account_service = service_factory.CreateClient <IAccountService>();
                using (account_service)
                {
                    Client.Entities.Account _account = account_service.GetAccountByCode(account_no, curr_co.CompanyCode);

                    if (_account != null)
                    {
                        return(new AccountWrapper(_account));
                    }
                }
            }
            return(null);
        }
Example #10
0
        /// <summary>
        /// Demo of how to create and use AccountIDManager
        /// Used for getting parentaccountid when creating Contact
        /// </summary>
        /// <returns></returns>
        private async Task DemoAccountIDManager()
        {
            Client.Entities.Account     account  = new Client.Entities.Account(_crmClient);
            List <Client.Types.Account> accounts = await account.List();

            foreach (var acc in accounts)
            {
                Console.WriteLine("{0} {1} {2}", acc.ID, acc.Name, acc.ParentAccountID);
            }
            Dictionary <string, string> accountDict = Utils.FromListToDict(accounts, "Name", "ID");

            Console.WriteLine("Total count = {0}", accountDict.Count);
            foreach (var key in accountDict.Keys)
            {
                Console.WriteLine("{0} {1}", key, accountDict[key]);
            }
            Client.AccountIDManager manager = new AccountIDManager(accounts);
            Console.WriteLine(manager.GetAccountID("University of Adelaide", "School of Agriculture, Food & Wine"));
        }
        private void GetInvoice(int invoiceKey)
        {
            ExecuteFaultHandledOperation(() =>
            {
                var invoiceService = _serviceFactory.CreateClient <IInvoiceService>();
                using (invoiceService)
                {
                    Invoice         = new InvoiceWrapper(invoiceService.GetInvoice(invoiceKey));
                    AccountContacts = new ObservableCollection <AccountPerson>(Invoice.Account.Model.Employees.Where(item =>
                                                                                                                     item.CompanyRoleType == QIQOPersonType.AccountContact).ToList());
                    Invoice.PropertyChanged += Context_PropertyChanged;
                    Invoice.AcceptChanges();
                    _currentAccount = Invoice.Account.Model;
                }

                DefaultBillingAddress  = Invoice.InvoiceItems[0].OrderItemBillToAddress;
                DefaultShippingAddress = Invoice.InvoiceItems[0].OrderItemShipToAddress;
                ViewTitle     = Invoice.InvoiceNumber;
                GridIsEnabled = Invoice.InvoiceStatus != QIQOInvoiceStatus.Complete ? true : false;
                _eventAggregator.GetEvent <GeneralMessageEvent>().Publish($"Invoice {Invoice.InvoiceNumber} loaded successfully");
                _eventAggregator.GetEvent <InvoiceLoadedEvent>().Publish(Invoice.InvoiceNumber);
                _eventAggregator.GetEvent <NavigationEvent>().Publish(ViewNames.InvoiceHomeView);
            });
        }
Example #12
0
        /// <summary>
        /// Check AD user from a list if they exist in CRM as Contact, then try to create if they don't or update username if it is incorrect.
        /// </summary>
        /// <param name="newUsers"></param>
        /// <returns></returns>
        private async Task <(List <string>, List <string>, List <Dictionary <string, string> >)> CheckUserInCRM(List <User> newUsers)
        {
            Client.Entities.Account account = new Client.Entities.Account(_crmClient);
            Client.Entities.Contact contact = new Client.Entities.Contact(_crmClient);

            AccountIDManager manager = await account.GetAccountIDManager();

            List <string> createdUsers = new List <string>();
            List <string> unabledUsers = new List <string>();
            List <Dictionary <string, string> > exceptionUsers = new List <Dictionary <string, string> >();

            JsonObject ConvertADUserToJson(User user, string attachToAccountID)
            {
                return(Client.Types.ContactBase.Create(user.FirstName, user.LastName, user.Email, user.AccountName, user.Department, attachToAccountID));
            }

            // Check the existence of a user by email address
            async Task CheckAndPrint(User user)
            {
                PrintUser(user);  // FIXME: this may not work well in parallel by just print user details
                Client.Types.Contact result = await contact.GetByEmail(user.Email);

                if (result != null)
                {
                    // Contact exists
                    Console.WriteLine($"Found and the contact id = {result.ID}");
                    Log.Information($"{user.DistinguishedName}: found in CRM and the contact id = {result.ID}");
                    string contactID = result.ID;
                    result = await contact.Get(new Guid(contactID));

                    // No username, need to set
                    if (string.IsNullOrEmpty(result.Username))
                    {
                        Log.Debug($"User name needed to be updated for contact {contactID}");
                        await contact.UpdateUsername(contactID, user.AccountName);

                        Log.Information($"The username of Contact with id={contactID} has been set successfully.");
                    }
                    else
                    {
                        // found wrong username
                        if (result.Username == user.AccountName)
                        {
                            Log.Debug($"contact {contactID} has username of {result.Username}");
                        }
                        else
                        {
                            Log.Debug($"Contact {contactID} has username of {result.Username} which is different to samAccountName {user.AccountName}");
                            await contact.UpdateUsername(contactID, user.AccountName);

                            Log.Information($"The username of Contact with id={contactID} has been updated successfully.");
                        }
                    }
                }
                else
                {
                    // Contact does not exist
                    Log.Debug($"{user.DistinguishedName} was not found in CRM");
                    string accountID = manager.GetAccountID(user.Company, user.Department);
                    if (string.IsNullOrEmpty(accountID))
                    {
                        Log.Warning($"Cannot create new Contact because cannot find accountID to attach for {user.DistinguishedName} could because of wrong department.");
                        unabledUsers.Add(string.Format("{0} ({1})", user.DistinguishedName, user.Email));
                    }
                    else
                    {
                        Log.Debug($"New contact will be created for {user.DistinguishedName}");
                        await contact.Create <JsonObject>(ConvertADUserToJson(user, accountID));

                        createdUsers.Add(user.DistinguishedName);
                        Log.Information($"New contact has been created for {user.DistinguishedName}");
                    }
                }
            }

            Task[] taskArray = new Task[newUsers.Count];
            int    i         = 0;

            foreach (var user in newUsers)
            {
                Log.Information("task {0}", i + 1);
                try
                {
                    taskArray[i++] = await Task.Factory.StartNew(() => CheckAndPrint(user));
                } catch (Exception ex)
                {
                    exceptionUsers.Add(new Dictionary <string, string>
                    {
                        { "DistinguishedName", user.DistinguishedName },
                        { "Exception", ex.ToString() }
                    });
                    Log.Error(ex, $"Failed attempt when processing {user.DistinguishedName}.");
                }
            }
            Task.WaitAll(taskArray);

            return(createdUsers, unabledUsers, exceptionUsers);
        }