Пример #1
0
        public Person MapToBLLPerson(DisplayPerson person)
        {
            var mapped = new Person();

            mapped.Gender   = MapToBLLGender(person.Gender);
            mapped.Name     = person.Name;
            mapped.NickName = person.NickName;
            return(mapped);
        }
Пример #2
0
    protected void ButtonSetUnreachable_Click(object sender, EventArgs e)
    {
        lock (cacheLockObject)
        {
            DisplayPersons badAdresses = GetBadAdresses();
            foreach (GridDataItem item in this.GridPeople.MasterTableView.Items)
            {
                int      personId = (int)item.GetDataKeyValue("Identity");
                CheckBox box      = (CheckBox)item["SendSMS"].FindControl("cbSendSMS");
                if (box.Checked)
                {
                    if (badAdresses.ContainsKey(personId))
                    {
                        DisplayPerson person = badAdresses[personId];

                        bool hasActiveMemberships = person.Member != "No";

                        if (hasActiveMemberships)
                        {
                            // Attempt to contact by SMS.
                            if (person.Phone.Trim().Length > 2)
                            {
                                try
                                {
                                    person.SendPhoneMessage("Piratpartiet: den mailadress vi har till dig (" + person.Email + ") studsar. Kontakta [email protected] med ny adress.");
                                    person.ActionResult = "SMS skickat";
                                }
                                catch (Exception)
                                {
                                    person.ActionResult = "Det gick inte att skicka SMS";
                                }
                            }
                        }
                        else
                        {
                            person.ActionResult = "Har inget aktivt medlemsskap";
                        }
                        person.MailUnreachable = true;
                    }
                }
                box = (CheckBox)item["MarkUnreachable"].FindControl("cbMarkUnreachable");
                if (box.Checked)
                {
                    if (badAdresses.ContainsKey(personId))
                    {
                        badAdresses[personId].MailUnreachable = true;
                    }
                }
            }
            Cache.Insert(cacheDataKey, badAdresses, null, DateTime.Now.AddMinutes(5).ToUniversalTime(), System.Web.Caching.Cache.NoSlidingExpiration);
            this.GridPeople.DataSource = badAdresses.Values;
            this.GridPeople.DataBind();
        }
    }
        public ActionResult Details(int id)
        {
            Person person = _peopleRepository.FindById(id);

            if (person == null)
            {
                return(HttpNotFound());
            }
            var data = new DisplayPerson();

            Mapper.Map(person, data);
            return(View(data));
        }
Пример #4
0
 protected void GridPeople_ItemDataBound(object sender, GridItemEventArgs e)
 {
     if (e.Item is GridDataItem)
     {
         GridDataItem  gridDataItem = e.Item as GridDataItem;
         DisplayPerson person       = e.Item.DataItem as DisplayPerson;
         if (person == null)
         {
             return;
         }
         gridDataItem["IsInvalid"].Text     = (person.EMailIsInvalid ? "Yes" : "");
         gridDataItem["IsUnreachable"].Text = (person.MailUnreachable ? "Yes" : "");
     }
 }
Пример #5
0
        /// <summary>
        /// Generates person with the associated latest revision of firm
        /// </summary>
        /// <param name="person"></param>
        /// <param name="firms">List of firms, there should only be one instance of each firm in this list</param>
        /// <returns></returns>
        public DisplayPerson GetDisplayPerson(Person person, string site, Seminar seminar = null)
        {
            Check.Require(person != null, "person is required.");

            var displayPerson = new DisplayPerson()
            {
                Person = person
            };

            var reg = seminar == null?person.GetLatestRegistration(site) : person.SeminarPeople.Where(a => a.Seminar == seminar).FirstOrDefault();

            if (reg == null)
            {
                return(displayPerson);
            }

            displayPerson.Seminar = reg.Seminar;
            displayPerson.Firm    = reg.Firm;
            displayPerson.Title   = reg.Title;

            return(displayPerson);
        }
Пример #6
0
    private DisplayPersons GetBadAdresses()
    {
        lock (cacheLockObject)
        {
            DisplayPersons badAdresses = Cache.Get(cacheDataKey) as DisplayPersons;

            if (badAdresses == null || "" + ViewState["isLoading"] == "1")
            {
                int lastread = int.Parse("0" + ViewState["lastread"]);
                if ("" + ViewState["isLoading"] != "1")
                {
                    lastread = 0;
                }

                People people = Cache.Get(cacheDataKey + "People" + _currentUser.Identity) as People;
                if (people == null)
                {
                    people = People.GetAll();
                    people = Authorization.FilterPeopleToMatchAuthority(people, _authority);
                    Cache.Insert(cacheDataKey + "People" + _currentUser.Identity, people, null, DateTime.Now.AddMinutes(5).ToUniversalTime(), System.Web.Caching.Cache.NoSlidingExpiration);
                }

                if (badAdresses == null)
                {
                    badAdresses = new DisplayPersons();
                }

                ViewState["isLoading"] = "0";

                foreach (Person p in people)
                {
                    if (p.Identity > lastread)
                    {
                        if ((!Formatting.ValidateEmailFormat(p.Email) || p.EMailIsInvalid || p.MailUnreachable) && ((p.MailUnreachable == false && p.Email != "") || CheckBoxUnreachable.Checked) && p.Email != "raderat")
                        {
                            DisplayPerson dp = new DisplayPerson(p);
                            dp.Member = "";
                            Memberships memberships = p.GetMemberships();
                            foreach (Membership membership in memberships)
                            {
                                if (membership.Active)
                                {
                                    dp.Member += membership.Organization.Name + " ";
                                }
                            }
                            if (CheckBoxNonMembers.Checked || dp.Member != "")
                            {
                                badAdresses.Add(p.Identity, dp);
                            }
                            if (dp.Member == "")
                            {
                                dp.Member = "No";
                            }
                        }
                        lastread = p.Identity;
                    }
                    if (DateTime.Now > stopTime)
                    {
                        ViewState["isLoading"] = "1";
                        break;
                    }
                }
                ViewState["lastread"] = lastread.ToString();

                Cache.Insert(cacheDataKey, badAdresses, null, DateTime.Now.AddMinutes(5).ToUniversalTime(), System.Web.Caching.Cache.NoSlidingExpiration);
            }
            return(badAdresses);
        }
    }
        // GET api/People
        public async Task <DisplayPersons> Get()
        {
            DisplayPersons dps = new DisplayPersons();

            try
            {
                List <Person> persons = _cache.Get("persons") as List <Person>;
                if (persons is null)
                {
                    persons = new List <Person>();

                    HttpClient client = new HttpClient();
                    //string path = @"https://www.willowtreeapps.com/api/v1.0/profiles";  //TBD move value to config file
                    string path = ConfigurationManager.AppSettings["WillowTreeAPI"];

                    HttpResponseMessage response = await client.GetAsync(path);

                    if (response.IsSuccessStatusCode)
                    {
                        persons = await response.Content.ReadAsAsync <List <Person> >();
                    }

                    _cache.Add("persons", persons, DateTime.Now.AddMinutes(10));
                }

                if (persons.Count > 0)
                {
                    List <DisplayPerson> displayPersons = new List <DisplayPerson>();
                    int numberToGet = int.Parse(ConfigurationManager.AppSettings["imagesToShow"]);
                    int enough      = persons.Count < numberToGet ? persons.Count : numberToGet;
                    //int enough = persons.Count < 6 ? persons.Count : 6; //TBD make the 6 a value in config file

                    List <int> indices  = new List <int>();
                    string     findName = string.Empty;

                    while (indices.Count < enough)
                    {
                        Random rnd   = new Random();
                        int    index = rnd.Next(1, persons.Count);
                        if (!indices.Contains(index))
                        {
                            indices.Add(index);
                            Person        selectedPerson = persons.ToArray()[index];
                            DisplayPerson displayPerson  = new DisplayPerson();
                            displayPerson.id       = selectedPerson.id;
                            displayPerson.jobTitle = selectedPerson.jobTitle;
                            displayPerson.Name     = selectedPerson.firstName + ' ' + selectedPerson.lastName;
                            displayPerson.slug     = selectedPerson.slug;
                            displayPerson.url      = selectedPerson.headshot.url;
                            displayPerson.alt      = selectedPerson.headshot.alt;
                            displayPerson.height   = selectedPerson.headshot.height;
                            displayPerson.width    = selectedPerson.headshot.width;
                            displayPersons.Add(displayPerson);
                            //here's a mundane way to "randomly pick" one of the six persons being returned as the one to identify.
                            if (findName.GetHashCode() > displayPerson.Name.GetHashCode())
                            {
                                findName = displayPerson.Name;
                            }
                            dps.displayPersons.Add(displayPerson);
                        }
                    }
                    dps.nameToId = findName;
                }
                return(dps);
            }
            catch (Exception ex)
            {
                //log exception
                return(dps);
            }
        }