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; } }
public virtual ActionResult Create(Customer customer) { MembershipCreationStatus membershipCreationStatus = MembershipService.Create(customer); if (membershipCreationStatus == MembershipCreationStatus.Success) { // Si no está logueado if (String.IsNullOrEmpty(User.Identity.Name)) { FormsService.SignIn(customer.Email, false); TempData["Message"] = "Tu cuenta ha sido creada con éxito, ya podés comenzar a operar con Hope!"; } else // Si ya está logueado { FormsService.SignOut(); TempData["Message"] = "Tu cuenta ha sido creada con éxito, ingesá al sitio y comenzá a operar con Hope!"; } TempData["ActionType"] = ActionType.Catalogue; } if (membershipCreationStatus == MembershipCreationStatus.DuplicateEmail) { TempData["Message"] = "Ya existe una cuenta con el E-mail ingresado!"; TempData["ActionType"] = ActionType.Back; } if (membershipCreationStatus == MembershipCreationStatus.Fail) { TempData["Message"] = "Ha ocurrido un error al crear su usuario!"; TempData["ActionType"] = ActionType.Back; } return RedirectToAction("Information"); }
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 ActionResult CreateFromLogOn(FormCollection formCollection) { var email = formCollection["Email2"]; var emailExists = hopeLingerieEntities.Customers.SingleOrDefault(a => a.Email == email && a.Active) != null; if (emailExists) { TempData["Message"] = "El Email ingresado ya existe en nuestra base de datos!"; TempData["ActionType"] = ActionType.Back; return Redirect("/Account/Information"); } Customer customer = new Customer(); customer.Email = formCollection["Email2"]; customer.BirthDate = DateTime.Now; ViewData["States"] = hopeLingerieEntities.States; return View("Account", customer); }
public virtual ActionResult OperatorUpdate(int Id, FormCollection formCollection) { var Operator = hopeLingerieEntities.Customers.SingleOrDefault(a => a.CustomerId == Id && a.Active); if (Operator == null) { Operator = new Customer(); Operator.Active = true; Operator.IsAdmin = true; Operator.AddedDate = DateTime.Now; Operator.StateId = 1; Operator.DNI = "-1"; Operator.Address = "-1"; Operator.ZipCode = "-1"; Operator.City = "-1"; Operator.Number = "-1"; hopeLingerieEntities.Customers.AddObject(Operator); } TryUpdateModel(Operator, formCollection); Operator.IsAdmin = true; Operator.Gender = formCollection["Gender"] == "Femenino" ? false : true; Operator.Password = EncryptionService.Encrypt(Operator.Password, "Gv7L3V15jCdb9P5XGKiPnhHZ7JlKcmU="); hopeLingerieEntities.SaveChanges(); return RedirectToAction("Operators"); }
public virtual ActionResult OrderUpdate(int Id) { ViewData["OrderStatus"] = hopeLingerieEntities.OrderStatus1.OrderBy(x => x.Description).Where(x => x.Active).ToList(); ViewData["Products"] = hopeLingerieEntities.Products.OrderBy(x => x.ProductId).ToList(); var nullProduct = new Product(); nullProduct.Code = "-- Seleccionar --"; nullProduct.ProductId = 0; ((List<Product>)ViewData["Products"]).Insert(0, nullProduct); if (Id > 0) { var order = hopeLingerieEntities.Orders.SingleOrDefault(a => a.OrderId == Id && a.Active); Session["OrderID"] = order.OrderId; if (order.CouponId.HasValue) { var coupon = hopeLingerieEntities.Coupons.SingleOrDefault(x => x.CouponId == order.CouponId); ViewData["Coupon"] = coupon.Code; } else ViewData["Coupon"] = string.Empty; ViewData["Discount"] = Convert.ToDecimal(order.Discount) / 100; return View(order); } var newCustomer = new Customer(); var newOrder = new Order(); newOrder.OrderStatusId = 1; newOrder.Customer = newCustomer; return View(newOrder); }
public virtual ActionResult OperatorUpdate(int Id) { if (Id > 0) { var Operator = hopeLingerieEntities.Customers.SingleOrDefault(a => a.CustomerId == Id && a.Active && a.IsAdmin); Operator.Password = EncryptionService.Decrypt(Operator.Password, "Gv7L3V15jCdb9P5XGKiPnhHZ7JlKcmU="); return View(Operator); } var newOperator = new Customer(); return View(newOperator); }
public virtual ActionResult CustomerUpdate(int Id, FormCollection formCollection) { var customer = hopeLingerieEntities.Customers.SingleOrDefault(a => a.CustomerId == Id && a.Active && !a.IsAdmin); if (customer == null) { customer = new Customer(); customer.Active = true; customer.AddedDate = DateTime.Now; hopeLingerieEntities.Customers.AddObject(customer); } TryUpdateModel(customer, formCollection); customer.IsAdmin = false; customer.NewsLetter = formCollection["NewsLetter"] == "U" ? false : true; customer.Gender = formCollection["Gender"] == "Femenino"?false: true; customer.Password = EncryptionService.Encrypt(customer.Password, "Gv7L3V15jCdb9P5XGKiPnhHZ7JlKcmU="); var newsLetter = hopeLingerieEntities.NewsLetters.SingleOrDefault(x=>x.Email == customer.Email); if (!customer.NewsLetter) { // Si existe y está deschequeado entonces lo borro. if (newsLetter != null) hopeLingerieEntities.NewsLetters.DeleteObject(newsLetter); } else { // Si no existe y está chequeado entonces lo agrego. if (newsLetter == null) { hopeLingerieEntities.NewsLetters.AddObject(new NewsLetter { Email = customer.Email, Name = customer.LastName + " " + customer.FirstName, AddedDate = DateTime.Now }); } } hopeLingerieEntities.SaveChanges(); return RedirectToAction("Customers"); }
public virtual ActionResult CustomerUpdate(int Id) { ViewData["States"] = hopeLingerieEntities.States.OrderBy(x => x.Description).ToList(); if (Id > 0) { var customer = hopeLingerieEntities.Customers.Include("Orders").SingleOrDefault(a => a.CustomerId == Id && a.Active && !a.IsAdmin); ViewData["Orders"] = hopeLingerieEntities.Orders.OrderByDescending(a => a.AddedDate).Where(x => x.CustomerId == Id && x.Active).Select(x => new { OrderID = x.OrderId, DeliveryDate = x.DeliveryDate, DeliveryAddress = x.DeliveryAddress, AddedDate = x.AddedDate, Discount = x.Discount, OrderStatus = x.OrderStatus.Description, Cellular = x.Customer.Cellular, Telephone = x.Customer.Telephone1, LastName = x.Customer.LastName, FirstName = x.Customer.FirstName, Email = x.Customer.Email }).ToList(); customer.Password = EncryptionService.Decrypt(customer.Password, "Gv7L3V15jCdb9P5XGKiPnhHZ7JlKcmU="); return View(customer); } var newCustomer = new Customer(); return View(newCustomer); }
/// <summary> /// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCustomers(Customer customer) { base.AddObject("Customers", customer); }
/// <summary> /// Create a new Customer object. /// </summary> /// <param name="customerId">Initial value of the CustomerId property.</param> /// <param name="firstName">Initial value of the FirstName property.</param> /// <param name="lastName">Initial value of the LastName property.</param> /// <param name="dNI">Initial value of the DNI property.</param> /// <param name="gender">Initial value of the Gender property.</param> /// <param name="stateId">Initial value of the StateId property.</param> /// <param name="city">Initial value of the City property.</param> /// <param name="address">Initial value of the Address property.</param> /// <param name="number">Initial value of the Number property.</param> /// <param name="zipCode">Initial value of the ZipCode property.</param> /// <param name="email">Initial value of the Email property.</param> /// <param name="password">Initial value of the Password property.</param> /// <param name="active">Initial value of the Active property.</param> /// <param name="addedDate">Initial value of the AddedDate property.</param> /// <param name="isAdmin">Initial value of the IsAdmin property.</param> /// <param name="newsLetter">Initial value of the NewsLetter property.</param> public static Customer CreateCustomer(global::System.Int32 customerId, global::System.String firstName, global::System.String lastName, global::System.String dNI, global::System.Boolean gender, global::System.Int32 stateId, global::System.String city, global::System.String address, global::System.String number, global::System.String zipCode, global::System.String email, global::System.String password, global::System.Boolean active, global::System.DateTime addedDate, global::System.Boolean isAdmin, global::System.Boolean newsLetter) { Customer customer = new Customer(); customer.CustomerId = customerId; customer.FirstName = firstName; customer.LastName = lastName; customer.DNI = dNI; customer.Gender = gender; customer.StateId = stateId; customer.City = city; customer.Address = address; customer.Number = number; customer.ZipCode = zipCode; customer.Email = email; customer.Password = password; customer.Active = active; customer.AddedDate = addedDate; customer.IsAdmin = isAdmin; customer.NewsLetter = newsLetter; return customer; }