Exemplo n.º 1
0
 protected void MailGrid_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e)
 {
     if (e.Column.FieldName == "Subject" && (bool)e.GetFieldValue("IsReply"))
     {
         e.DisplayText = "Re: " + HttpUtility.HtmlEncode(e.Value);
     }
     if (e.Column.FieldName == "To")
     {
         var list = new List <string>();
         foreach (var item in e.Value.ToString().Split(','))
         {
             var        email    = item.Trim();
             ContactsBL bl       = new ContactsBL();
             var        Contacts = bl.GetAllContacts(User.Identity.Name);
             var        contact  = Contacts.FirstOrDefault(c => c.Email == email);
             list.Add(contact != null ? contact.Name : email);
         }
         e.DisplayText = string.Join(", ", list);
     }
     if (e.Column.FieldName == "From")
     {
         var        from     = e.Value.ToString();
         ContactsBL bl       = new ContactsBL();
         var        Contacts = bl.GetAllContacts(User.Identity.Name);
         var        contact  = Contacts.FirstOrDefault(c => c.Email == from);
         e.DisplayText = contact != null ? contact.Name : from;
     }
     if (!string.IsNullOrEmpty(SearchText) && (e.Column.FieldName == "From" || e.Column.FieldName == "To" || e.Column.FieldName == "Subject"))
     {
         string text = string.IsNullOrEmpty(e.DisplayText) ? e.Value.ToString() : e.DisplayText;
         e.DisplayText = new Regex(SearchText, RegexOptions.IgnoreCase).Replace(text, "<span class='hgl'>$0</span>");
     }
 }
Exemplo n.º 2
0
    protected void CallbackControl_Callback(object sender, CallbackEventArgs e)
    {
        var args = e.Parameter.Split('|');

        if (args[0] == "Edit" && args.Length == 2)
        {
            int id;
            if (!int.TryParse(args[1], out id))
            {
                e.Result = "NotFound";
                return;
            }
            ContactsBL bl       = new ContactsBL();
            var        Contacts = bl.GetAllContacts("");
            var        contact  = Contacts.FirstOrDefault(c => c.ID == id);
            if (contact == null)
            {
                e.Result = "NotFound";
                return;
            }
            var dict = new Dictionary <string, object>();
            dict["Name"]     = contact.Name;
            dict["Email"]    = contact.Email;
            dict["Address"]  = contact.Address;
            dict["City"]     = contact.City;
            dict["Country"]  = contact.Country;
            dict["Phone"]    = contact.Phone;
            dict["ImageUrl"] = Utils.GetContactPhotoUrl(contact.PhotoUrl);

            CallbackControl.JSProperties["cpContact"] = dict;
            e.Result = "Edit";
        }
    }
Exemplo n.º 3
0
    protected IEnumerable GetContacts()
    {
        ContactsBL bl       = new ContactsBL();
        var        contacts = bl.GetAllContacts("").AsEnumerable();

        if (!ShowAllContacts)
        {
            var showOnlyPersonal = ShowOnlyPersonalAddresses;
            contacts = contacts.Where(c => !object.Equals(c.Collected, showOnlyPersonal));
        }
        return(contacts.Select(c => new {
            PhotoUrl = "~/" + Utils.GetContactPhotoUrl(c.PhotoUrl),
            Name = c.Name,
            Email = c.Email,
            Address = Utils.GetAddressString(c),
            Phone = c.Phone
        }));
    }
Exemplo n.º 4
0
    List <Contact> SelectContacts()
    {
        ContactsBL bl       = new ContactsBL();
        var        Contacts = bl.GetAllContacts("");
        var        result   = Contacts.AsQueryable();
        var        showCollectedAdresses = Convert.ToInt32(FindAddressBookList().Value) == 1;

        result = result.Where(c => object.Equals(c.Collected, showCollectedAdresses));

        if (!string.IsNullOrEmpty(SearchText))
        {
            var text = SearchText.ToLower();
            result = result.Where(c => c.Name.ToLower().Contains(text) || Utils.GetAddressString(c).ToLower().Contains(text));
        }
        var sortedFieldName = FindSortByCombo().Value.ToString();
        var isDescending    = Convert.ToInt32(FindSortDirectionCombo().Value) == 1;

        result = Utils.MakeContactsOrderBy(result, sortedFieldName, isDescending);
        return(result.ToList());
    }
Exemplo n.º 5
0
    protected void Page_Load(object s, EventArgs e)
    {
        if (ShouldBindGrid())
        {
            BindGrid();
        }
        if (MailFormPanel.IsCallback || IsPostBack && !IsCallback)
        {
            ContactsBL bl       = new ContactsBL();
            var        Contacts = bl.GetAllContacts(User.Identity.Name);
            AddressesList.DataSource = Contacts.Select(c => new {
                Text     = c.Name,
                Value    = c.Email,
                ImageUrl = Utils.GetContactPhotoUrl(c.PhotoUrl)
            });
            AddressesList.DataBind();
        }

        MailGrid.DataColumns["To"].Visible   = ShowToColumn();
        MailGrid.DataColumns["From"].Visible = !ShowToColumn();
    }