public MembershipCreationStatus Create(Customer customer)
        {
            try
            {
                string decriptedPassword = customer.Password;
                Customer newCustomer = hopeLingerieEntities.Customers.SingleOrDefault(x => x.Email == customer.Email && x.Active);

                if (newCustomer != null)
                    return MembershipCreationStatus.DuplicateEmail;

                customer.Password = EncryptionService.Encrypt(customer.Password, KeyString);
                customer.IsAdmin = false;
                customer.AddedDate = DateTime.Now;
                hopeLingerieEntities.Customers.AddObject(customer);

                if (customer.NewsLetter)
                {
                    NewsLetter newsLetter = new NewsLetter();
                    newsLetter.AddedDate = DateTime.Now;
                    newsLetter.Email = customer.Email;
                    newsLetter.Name = customer.LastName + ", " + customer.FirstName;
                    hopeLingerieEntities.NewsLetters.AddObject(newsLetter);
                }

                hopeLingerieEntities.SaveChanges();

                Mail mail = hopeLingerieEntities.Mails.SingleOrDefault(a => a.Code == "NEWUSER");

                if (mail != null)
                    MailService.Send(mail.From, customer.Email, mail.Subject, String.Format(mail.Body, customer.FirstName + " " + customer.LastName, customer.Email, EncryptionService.Decrypt(customer.Password, KeyString)));

                return MembershipCreationStatus.Success;
            }
            catch
            {
                return MembershipCreationStatus.Fail;
            }
        }
Beispiel #2
0
        public virtual ActionResult ContactUs(FormCollection formCollection)
        {
            var contact = new Contact();

            TryUpdateModel(contact, formCollection);

            contact.NewsLetter = (formCollection["NewsLetter"] != "N");
            contact.Description = formCollection["Descript"];
            contact.AddedDate = DateTime.Now;
            hopeLingerieEntities.Contacts.AddObject(contact);

            if (contact.NewsLetter)
            {
                var newsLetter = new NewsLetter();
                newsLetter.Email = contact.EMail;
                newsLetter.Name = contact.Name;
                newsLetter.AddedDate = DateTime.Now;
                hopeLingerieEntities.NewsLetters.AddObject(newsLetter);
            }

            hopeLingerieEntities.SaveChanges();

            return View("../Home/Index");
        }
        public virtual ActionResult Edit(Customer customer)
        {
            var emailExists = hopeLingerieEntities.Customers.SingleOrDefault(a => a.CustomerId != customer.CustomerId && a.Email == customer.Email && a.Active);

            if (emailExists != null)
            {
                TempData["Message"] = "El Email ingresado ya existe en nuestra base de datos!";
                TempData["ActionType"] = ActionType.Back;

                return Redirect("/Account/Information");
            }

            var newCustomer = hopeLingerieEntities.Customers.SingleOrDefault(a => a.CustomerId == customer.CustomerId && a.Active);
            newCustomer.BirthDate = customer.BirthDate;
            newCustomer.Cellular = customer.Cellular;
            newCustomer.City = customer.City;
            newCustomer.DNI = customer.DNI;
            newCustomer.Fax = customer.Fax;
            newCustomer.FirstName = customer.FirstName;
            newCustomer.LastName = customer.LastName;
            newCustomer.NewsLetter = customer.NewsLetter;
            newCustomer.Number = customer.Number;
            newCustomer.StateId = customer.StateId;
            newCustomer.Telephone1 = customer.Telephone1;
            newCustomer.Telephone2 = customer.Telephone2;
            newCustomer.Telephone3 = customer.Telephone3;
            newCustomer.ZipCode = customer.ZipCode;
            newCustomer.Gender = customer.Gender;
            newCustomer.Address = customer.Address;

            if (!customer.NewsLetter)
            {
                var newsLetter = hopeLingerieEntities.NewsLetters.SingleOrDefault(x => x.Email == newCustomer.Email);
                hopeLingerieEntities.NewsLetters.DeleteObject(newsLetter);
            }
            else
            {
                var newsLetter = hopeLingerieEntities.NewsLetters.SingleOrDefault(x => x.Email == newCustomer.Email);

                if (newsLetter != null)
                {
                    newsLetter.Email = customer.Email;
                    newsLetter.Name = customer.LastName + ", " + customer.FirstName;
                }
                else
                {
                    newsLetter = new NewsLetter();
                    newsLetter.Email = customer.Email;
                    newsLetter.Name = customer.LastName + ", " + customer.FirstName;
                    newsLetter.AddedDate = DateTime.Now;
                    hopeLingerieEntities.NewsLetters.AddObject(newsLetter);
                }
            }

            // Si hay cambio de mail lo desloguea.
            if (newCustomer.Email != customer.Email)
            {
                newCustomer.Email = customer.Email;
                hopeLingerieEntities.SaveChanges();
                FormsService.SignOut();

                TempData["Message"] = "Tu cuenta ha sido modificada con éxito! Al modificar el Email deberás ingresar nuevamente al sitio";
                TempData["ActionType"] = ActionType.Catalogue;
                return Redirect("/Account/Information");
            }

            hopeLingerieEntities.SaveChanges();
            TempData["Message"] = "Tu cuenta ha sido modificada con éxito!";
            TempData["ActionType"] = ActionType.Catalogue;
            return Redirect("/Account/Information");
        }
        public virtual string RegisterNewsletter(string name, string email)
        {
            var newsLetter = hopeLingerieEntities.NewsLetters.SingleOrDefault(x => x.Email == email);
            if (newsLetter == null)
            {
                NewsLetter nl = new NewsLetter();
                nl.Active = true;
                nl.AddedDate = DateTime.Now;
                nl.Email = email;
                nl.Name = name;
                hopeLingerieEntities.NewsLetters.AddObject(nl);
                hopeLingerieEntities.SaveChanges();
            }

            return "";
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the NewsLetters EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToNewsLetters(NewsLetter newsLetter)
 {
     base.AddObject("NewsLetters", newsLetter);
 }
 /// <summary>
 /// Create a new NewsLetter object.
 /// </summary>
 /// <param name="newsLetterId">Initial value of the NewsLetterId property.</param>
 /// <param name="email">Initial value of the Email property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="addedDate">Initial value of the AddedDate property.</param>
 public static NewsLetter CreateNewsLetter(global::System.Int32 newsLetterId, global::System.String email, global::System.String name, global::System.DateTime addedDate)
 {
     NewsLetter newsLetter = new NewsLetter();
     newsLetter.NewsLetterId = newsLetterId;
     newsLetter.Email = email;
     newsLetter.Name = name;
     newsLetter.AddedDate = addedDate;
     return newsLetter;
 }