Exemple #1
0
        public ActionResult SearchDonors(string email, string account, string org, string name, string zip)
        {
            try
            {
                if (!Request.IsAuthenticated)
                {
                    return RedirectToAction("LogOn", "Account");
                }
                else if (email == null || account == null || org == null || name == null || zip == null)
                {
                    return RedirectToAction("Search", "Home");
                }

                SearchCondition condition = new SearchCondition()
                {
                    Email = email.Trim(),
                    AccountNumber = account.Trim(),
                    Organization = org.Trim(),
                    Name = name.Trim(),
                    Zip = zip.Trim()
                };
                List<account> list = Service.Search(condition);

                CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
                //Create TextInfo object.
                TextInfo textInfo = cultureInfo.TextInfo;

                foreach (account acc in list)
                {
                    acc.lastName = textInfo.ToTitleCase(acc.lastName.Trim());
                    acc.firstName = textInfo.ToTitleCase(acc.firstName.Trim());
                }

                IEnumerable<account> accounts;

                if (org.Length > 0)
                {
                    accounts = from a in list where a.isOrganization == true orderby a.lastName, a.firstName select a;
                }
                else
                {
                    accounts = from l in list orderby l.lastName, l.firstName select l;
                }
                //list = list.OrderBy(l => l.lastName).ThenBy(l => l.lastName).ToList();
                //list = list.OrderBy(l => l.accountId).ToList();

                SortedDictionary<string, List<account>> dic = new SortedDictionary<string, List<account>>();
                char letter = 'A';

                foreach (account acc in accounts)
                {
                    if (acc.lastName != "")
                    {
                        letter = acc.lastName[0];

                        if (dic.ContainsKey(letter.ToString().ToUpper()))
                        {
                            dic[letter.ToString().ToUpper()].Add(acc);
                        }
                        else
                        {
                            List<account> accs = new List<account>();
                            accs.Add(acc);
                            dic.Add(letter.ToString().ToUpper(), accs);
                        }
                    }
                }

                if (Request.IsAjaxRequest())
                {
                    return View("_SearchDonors", dic);
                }
                return View(dic);
            }
            catch (Exception ex)
            {
                ErrorLog(Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ERRORPATH"]), ex.Message);
                return View("Error");
            }
        }
Exemple #2
0
        /// <summary>
        /// Search will return all the list of donors and save it on cache
        /// it has been implemented to make the less possible calls to the Wip service 
        /// </summary>
        /// <returns> The cache result(getAccountsResponse) </returns>
        public List<account> Search(SearchCondition condition)
        {
            var port = Models.Util.Port();
            getAccountsRequest acreq = new getAccountsRequest();

            StringBuilder strAction = new StringBuilder();
            strAction.Append(Util.Actions.SearchFor.ToString());

            if (condition.Email.Length > 0)
            {
                acreq.emailAddress = condition.Email;
                strAction.Append("Email:" + condition.Email);
            }
            if (condition.Zip.Length > 0)
            {
                acreq.zipCode = condition.Zip;
                strAction.Append("Zip:" + condition.Zip);
            }
            if (condition.Organization.Length > 0)
            {
                acreq.organization = condition.Organization;
                strAction.Append("Organization:" + condition.Organization);
            }
            if (condition.AccountNumber.Length > 0)
            {
                acreq.accountIdRangeStart = Convert.ToInt64(condition.AccountNumber);
                acreq.accountIdRangeEnd = Convert.ToInt64(condition.AccountNumber);
                strAction.Append("AccountNumber:" + condition.AccountNumber);
            }

            if (condition.Name.Length > 0)
            {
                strAction.Append("Name:" + condition.Name);
            }

            Models.Util.SaveAction(strAction.ToString());

            if (condition.Name.Length == 0)
            {
                return port.getAccounts(acreq).accounts.ToList();
            }
            else if (condition.Name.Contains(" "))
            {
                var names = condition.Name.Split(' ');
                acreq.firstName = names[0];
                acreq.lastName = names[1];
                return port.getAccounts(acreq).accounts.ToList();
            }
            else
            {
                acreq.firstName = condition.Name;
                var first = port.getAccounts(acreq).accounts;

                acreq.firstName = null;
                acreq.lastName = condition.Name;
                var last = port.getAccounts(acreq).accounts.ToList();

                foreach (account a in first)
                {
                    var have = from acc in last where acc.accountId == a.accountId select acc;

                    if (have.Count() == 0)
                    {
                        last.Add(a);
                    }
                }

                return last;
            }
        }