public List<INVITATION> Search(INVITATION Entity, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, Util.SortDirection SortDirection)
        {
            var result = Context.INVITATION.AsQueryable();
            if (Entity != null)
            {
                if (Entity.ID != 0)
                {
                    result = result.Where(b => b.ID == Entity.ID);
                }

                if (Entity.CustomerID.HasValue)
                {
                    result = result.Where(i => i.CustomerID == Entity.CustomerID);
                }

                if (!String.IsNullOrEmpty(Entity.InvitedMail))
                {
                    result = result.Where(i => i.InvitedMail.Contains(Entity.InvitedMail));
                }

                if (Entity.RegistrationDate != null)
                {
                    result = result.Where(i => i.RegistrationDate == (Entity.RegistrationDate));
                }
            }
            TotalRecords = result.Count();

            GenericSorterCaller<INVITATION> sorter = new GenericSorterCaller<INVITATION>();
            result = sorter.Sort(result, string.IsNullOrEmpty(OrderExp) ? DEFAULT_ORDER_EXP : OrderExp, SortDirection);

            // pagination
            return result.Skip(PageIndex * PageSize).Take(PageSize).ToList();
        }
 private void Update(int numValue)
 {
     var updIntit = new INVITATION { ID = numValue };
     int custId;
     if (Int32.TryParse(hdnCustomerId.Value, out custId))
     {
         updIntit.CustomerID = custId;
         updIntit.InvitedMail = txtInvitedMail.Text;
         updIntit.Registered = chkRegistered.Checked;
         DateTime date;
         if (DateTime.TryParse(txtDate.Text, out date))
             updIntit.RegistrationDate = date;
         ApplicationContext.Current.Invitations.Update(updIntit);
         writeResult("Update successful!", false);
     }
     else
     {
         writeResult("Error successful! No Customer data.", true);
     }
 }
 public void DeleteById(int Id)
 {
     INVITATION obj = new INVITATION() { ID = Id };
     Delete(obj);
 }
 public void Delete(INVITATION delInv)
 {
     Context.INVITATION.Attach(delInv);
     Context.DeleteObject(delInv);
 }
 public void Update(INVITATION upInv)
 {
     Context.INVITATION.Attach(upInv);
     Context.ObjectStateManager.ChangeObjectState(upInv, System.Data.EntityState.Modified);
 }
 public void Insert(INVITATION newInv)
 {
     Context.INVITATION.AddObject(newInv);
 }
        private void Save()
        {
            string[] mails = txtInvitedMail.Text.Split(',');
            int count = 0;
            List<string> alreadyInvitedMails = new List<string>();
            List<string> alreadyRegisteredMails = new List<string>();
            try
            {
                foreach (var mail in mails)
                {
                    var newInvt = new INVITATION();
                    if (this.CurrentCustomer != null)
                    {
                        int idC = CurrentCustomer.Id;
                        newInvt.CustomerID = idC;
                        newInvt.Registered = false;
                        //newInvt.RegistrationDate = DateTime.Now;
                        newInvt.InvitedMail = mail;

                        if (ApplicationContext.Current.Customers.GetByEmail(mail) != null)
                        {
                            alreadyRegisteredMails.Add(mail);
                            continue;
                        }

                        List<INVITATION> invites = ApplicationContext.Current.Invitations.GetAllInvitationOfCustomer(CurrentCustomer.Id);

                        if (invites.Where(i => i.InvitedMail == mail).FirstOrDefault() != null)
                        {
                            alreadyInvitedMails.Add(mail);
                            continue;
                        }

                        ApplicationContext.Current.Invitations.Insert(newInvt);

                        count++;

                        SendInvite(this.CurrentCustomer, newInvt.ID, mail, CurrentCustomer.FullName);
                    }
                }
                StringBuilder builder = new StringBuilder();
                if (count > 0)
                {
                    builder.Append(Lang.InviteSuccessful);
                }
                if (alreadyRegisteredMails.Count > 0)
                {
                    builder.Append( "<br />" + Resources.Lang.AlreadyRegisteredMailLabel + "<br />");

                    foreach (string email in alreadyRegisteredMails)
                    {
                        builder.Append(email + " ");
                    }
                }

                if (alreadyInvitedMails.Count > 0)
                {
                    builder.Append("<br />" + Resources.Lang.EmailAlreadyInvited + "<br />");

                    foreach (string email in alreadyInvitedMails)
                    {
                        builder.Append(email + " ");
                    }
                }

                litError.Text = builder.ToString();
            }
            catch (Exception ex)
            {
                //TODO log
                Log(ex, ex.Message, ex.StackTrace, "Invite");
                litError.Text = Lang.ErrorVerifiedLabel;
            }
        }
 private void Save()
 {
     string[] mails = txtInvitedMail.Text.Split(';');
     int count = 0;
     foreach (var mail in mails)
     {
         var newInvt = new INVITATION();
         if (!string.IsNullOrEmpty(txtCustomer.Text) && !string.IsNullOrWhiteSpace(txtCustomer.Text))
         {
             string[] nameBrday = txtCustomer.Text.Split('-');
             if (nameBrday.Length > 2)
             {
                 int idC;
                 if (Int32.TryParse(nameBrday[2], out idC))
                 {
                     var customer = ApplicationContext.Current.Customers.GetById(idC);
                     if (customer != null)
                     {
                         newInvt.CUSTOMER = customer;
                         newInvt.CustomerID = customer.ID;
                     }
                 }
             }
         }
         newInvt.InvitedMail = mail;
         newInvt.Registered = chkRegistered.Checked;
         DateTime dataReg;
         if (DateTime.TryParse(txtDate.Text, out dataReg))
             newInvt.RegistrationDate = dataReg;
         ApplicationContext.Current.Invitations.Insert(newInvt);
         count++;
     }
     writeResult(count > 1 ? count + " Inserts successful!" : "Insert successful!", false);
 }
 protected void dataBindInvitation(string sortExp, int pageIndex)
 {
     try
     {
         int totalRecords = 0;
         gridInvitation.PageSize = Utils.Configuration.PageSize;
         int id = 0;
         INVITATION invitation = new INVITATION() { CustomerID = this.CustomerID };
         List<INVITATION> list = ApplicationContext.Current.Invitations.Search(invitation, Utils.Configuration.PageSize, pageIndex, out totalRecords, sortExp, gridBonus.SortOrder);
         gridInvitation.DataSource = list;
         gridInvitation.CustomCustomVirtualItemCount = totalRecords;
         gridInvitation.DataBind();
     }
     catch (Exception e)
     {
         writeError(e.Message);
     }
 }
示例#10
0
        protected void lnkRegister_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                CUSTOMER customer = new CUSTOMER();
                if (String.IsNullOrWhiteSpace(txtEmail.Text) || !valEmail.IsValid)
                {
                    litError.Text = "Email " + Resources.Lang.NotValidLabel + ".";
                    return;
                }

                if (!chkGeneralTerms.Checked)
                {
                    litError.Text = Resources.Lang.PleaseAcceptLabel;
                    return;
                }
                int invCust = 0;
                //Check if have cookie. Yes ? Add id of customer whu invited : nothing
                if (Request.Cookies["InvBy"] != null)
                {
                    if (Request.Cookies["InvBy"]["IdCust"] != null)
                    {
                        if (int.TryParse(Request.Cookies["InvBy"]["IdCust"], out invCust))
                        {
                            customer.InvitedFrom = invCust;
                        }
                    }
                }

                customer.Email = txtEmail.Text;

                try
                {
                    if (ApplicationContext.Current.Customers.GetByEmail(txtEmail.Text) != null)
                    {
                        litError.Text = Resources.Lang.AlreadyRegisteredMailLabel;
                        return;
                    }

                    customer.Name = txtName.Text;
                    customer.Surname = txtSurname.Text;
                    DateTime date = new DateTime();
                    IFormatProvider formatProvider = new CultureInfo("it-IT");

                    if (!String.IsNullOrWhiteSpace(txtBirthday.Text))
                    {
                        DateTime.TryParse(txtBirthday.Text, formatProvider, DateTimeStyles.AdjustToUniversal, out date);

                    }
                    customer.BirthDate = date;
                    customer.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, Configuration.PasswordHashMethod).ToLower();
                    customer.Active = true;
                    customer.RegistrationDate = DateTime.Now;
                    customer.Newsletter = true;
                    customer.Gender = ddlGender.SelectedValue;
                    customer.Telephone = txtPhone.Text;
                    customer.Mobile = txtMobile.Text;

                    //If cookie exist ? delte && set InviteTabele a True : nothing
                    if (Request.Cookies["InvBy"] != null)
                    {
                        if (Request.Cookies["InvBy"]["InvId"] != null)
                        {
                            int idInv;
                            if (int.TryParse(Request.Cookies["InvBy"]["InvId"], out idInv))
                            {
                                var invitation = ApplicationContext.Current.Invitations.GetById(idInv);
                                if (invitation.InvitedMail == txtEmail.Text)
                                {
                                    invitation.Registered = true;
                                    invitation.RegistrationDate = DateTime.Now;
                                    //ApplicationContext.Current.Invitations.Update(invitation);
                                    //No need to do an update (i.e. attach and save context), object already attached
                                }
                                // TODO Check logic
                                // case when invitation id is specified, but user is registering another email
                                else if (invCust != 0)
                                {
                                    INVITATION invt = new INVITATION() { CustomerID = invCust, InvitedMail = txtEmail.Text, Registered = true, RegistrationDate = DateTime.Now, IP = Request.UserHostAddress };
                                    ApplicationContext.Current.Invitations.Insert(invt);
                                }
                            }
                            else
                            {
                                //case when invitation id is not specified, user may be referred in another way
                                INVITATION invt = new INVITATION() { CustomerID = invCust, InvitedMail = txtEmail.Text, Registered = true, RegistrationDate = DateTime.Now, IP = Request.UserHostAddress };
                                ApplicationContext.Current.Invitations.Insert(invt);
                            }
                        }
                        HttpCookie myCookie = new HttpCookie("InvBy");
                        myCookie.Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(myCookie);
                    }

                    ApplicationContext.Current.Customers.Insert(customer);

                    CurrentCustomer = new SessionCustomer(customer);

                    Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
                    FormsAuthentication.SetAuthCookie(customer.Email, false);

                    Response.Redirect("/home");

                }
                catch (System.Threading.ThreadAbortException ex)
                {
                }
                catch (Exception ex)
                {
                    //TODO log ex
                    Log(ex, ex.Message, ex.StackTrace, "Register");
                    litError.Text = Resources.Lang.ErrorVerifiedLabel;
                }
            }
        }
 public void Delete(INVITATION Entity)
 {
     _invititationDAO.Delete(Entity);
     Context.SaveChanges();
 }
 public void Insert(INVITATION Entity)
 {
     _invititationDAO.Insert(Entity);
     Context.SaveChanges();
 }
 public List<INVITATION> Search(INVITATION Entity, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, Util.SortDirection SortDirection)
 {
     return _invititationDAO.Search(Entity, PageSize, PageIndex, out TotalRecords, OrderExp, SortDirection);
 }