protected override void SaveForm() { MembershipUser user = null; if (CurrentAspNetId.HasValue) { user = Membership.GetUser(CurrentAspNetId.Value); } if (user != null) { if (user.IsLockedOut) { OnCancelled(); } else { string newPassword = OrderNumberGenerator.GenerateOrderNumber("?#?#?#?#"); string tempPassword = user.ResetPassword(); bool success = user.ChangePassword(tempPassword, newPassword); // send email Email.EmailController ec = new Email.EmailController(); ec.SendMail_PasswordReset(user.Email, newPassword); OnSaved(new ControlSavedEventArgs(CurrentAspNetId)); } } }
private async Task LoadNumeration() { var numerations = await _repository.GetAllAsync(); var defaultNumeration = numerations.FirstOrDefault(n => n.Name == "default"); if (defaultNumeration != null) { Numeration = new NumerationWrapper(defaultNumeration); } else { var newNumeration = new Business.Numeration(); _repository.Add(newNumeration); Numeration = new NumerationWrapper(newNumeration); } Numeration.PropertyChanged += (o, a) => { if (_rBACManager?.LoggedUser?.FirstName != null && _rBACManager?.LoggedUser?.LastName != null) { var stringBuilder = new StringBuilder(); stringBuilder.Append(_rBACManager?.LoggedUser?.FirstName[0]); stringBuilder.Append(_rBACManager?.LoggedUser?.LastName[0]); var initials = stringBuilder.ToString(); NumerationExample = OrderNumberGenerator.GetNumberFromPattern(Numeration.Pattern, initials); return; } NumerationExample = OrderNumberGenerator.GetNumberFromPattern(Numeration.Pattern); }; }
public string GetOrderNumber(string prefix = "KECORD#") { var orderNumber = string.Empty; do { orderNumber = OrderNumberGenerator.GetOrderNumber(prefix); } while ((Find(p => p.OrderNumber.Equals(orderNumber)).FirstOrDefault() != null)); return(orderNumber); }
void ResetPassword(string emailAddress) { string userName = string.Empty; MembershipUser user = null; bool success = false; string newPassword = string.Empty; userName = Membership.GetUserNameByEmail(emailAddress); if (!string.IsNullOrWhiteSpace(userName)) { user = Membership.GetUser(userName); if (user != null) { string tempPassword = user.ResetPassword(); newPassword = OrderNumberGenerator.GenerateOrderNumber("?#?#?#?#"); success = user.ChangePassword(tempPassword, newPassword); } } if (success) { // send email EmailController ec = new EmailController(); ec.SendMail_PasswordReset(emailAddress, newPassword); lblFeedback.Text = "<span style='color:green;'>Password Reset Successful - Your new password has been sent to the email address: " + emailAddress + "</span><br/><br/><a href='/login.aspx'>Click Here</a> to return to account log in screen.</span>"; divForm.Visible = false; } else { lblFeedback.Text = "<span style='color:red;'>Password Reset Failed. Email address not recognized. " + "Please re-enter your email address or call customer service at 866-575-2433 for assistance.</span>"; } }
public CustomOutput(ArrayList Order1) { TrackingNumberGenerator customShipOrderTracker = TrackingNumberGenerator.Instance; OrderNumberGenerator customOrderTracker = OrderNumberGenerator.Instance; StringBuilder cbody = new StringBuilder(); StringBuilder cfooter = new StringBuilder(); StringBuilder heading = new StringBuilder(); DateTime now = DateTime.Now; foreach (AbstractGadget cgadget in Order1) { if (cgadget.GadgetSize == GadgetSize.Medium) { _cmediumGadgetSubtotal += cgadget.Price; _cmediumGadgetsOrdered++; _cmtotalButtons += cgadget.Buttons; _cmtotalSwitches += cgadget.Switches; _cmtotalLights += cgadget.Lights; if (cgadget.GadgetType == GadgetType.Retail) { _typePrint = "R"; } else { _typePrint = "W"; } if (cgadget.GadgetSize == GadgetSize.Medium) { _sizePrint = "M"; } else { _sizePrint = "L"; } if (cgadget.PowerType == GadgetPower.Battery) { _powerPrint = "B"; } else if (cgadget.PowerType == GadgetPower.Generator) { _powerPrint = "G"; } else { _powerPrint = "S"; } if (cgadget.GadgetColorType == GadgetColor.Painted) { _gadgetColor = "PT"; } else if (cgadget.GadgetColorType == GadgetColor.Plated) { _gadgetColor = "PL"; } else { _gadgetColor = "UP"; } if (cgadget.WidgetColorType == WidgetColor.Painted) { _widgetColor = "PT"; } else if (cgadget.WidgetColorType == WidgetColor.Plated) { _widgetColor = "PL"; } else { _widgetColor = "UP"; } cbody.AppendFormat("*"); cbody.Append(String.Format("{0,12} {1,30} {2,25} {3,16} {4,19}", _sizePrint, _typePrint, cgadget.Buttons, cgadget.Lights, cgadget.Switches)); cbody.Append(String.Format("{0,16} {1,15} {2,24} {3,26}", _gadgetColor, _widgetColor, _powerPrint, cgadget.Price)); cbody.Append(String.Format("{0,18} {1,16}", cgadget.SerialNumber, cgadget.UpcNumber)); cbody.AppendFormat(" "); cbody.AppendFormat("*"); cbody.AppendLine(); if (cgadget.GadgetColorType == GadgetColor.Painted) { _cmtotalPainted++; } else if (cgadget.GadgetColorType == GadgetColor.Plated) { _cmtotalPlated++; } else if (cgadget.GadgetColorType == GadgetColor.Unpainted) { _cmtotalUnpainted++; } if (cgadget.WidgetColorType == WidgetColor.Painted) { _cmtotalWPainted++; } else if (cgadget.WidgetColorType == WidgetColor.Plated) { _cmtotalWPlated++; } else if (cgadget.WidgetColorType == WidgetColor.Unpainted) { _cmtotalWUnpainted++; } if (cgadget.PowerType == GadgetPower.Battery) { _cmtotalBattery++; } else if (cgadget.PowerType == GadgetPower.Generator) { _cmtotalGenerator++; } else if (cgadget.PowerType == GadgetPower.Solar) { _cmtotalSolar++; } } if (cgadget.GadgetSize == GadgetSize.Large) { _clargeGadgetSubtotal += cgadget.Price; _clargeGadgetsOrdered++; _cltotalButtons += cgadget.Buttons; _cltotalSwitches += cgadget.Switches; _cltotalLights += cgadget.Lights; if (cgadget.GadgetType == GadgetType.Retail) { _typePrint = "R"; } else { _typePrint = "W"; } if (cgadget.GadgetSize == GadgetSize.Medium) { _sizePrint = "M"; } else { _sizePrint = "L"; } if (cgadget.PowerType == GadgetPower.Battery) { _powerPrint = "B"; } else if (cgadget.PowerType == GadgetPower.Generator) { _powerPrint = "G"; } else { _powerPrint = "S"; } if (cgadget.GadgetColorType == GadgetColor.Painted) { _gadgetColor = "PT"; } else if (cgadget.GadgetColorType == GadgetColor.Plated) { _gadgetColor = "PL"; } else { _gadgetColor = "UP"; } if (cgadget.WidgetColorType == WidgetColor.Painted) { _widgetColor = "PT"; } else if (cgadget.WidgetColorType == WidgetColor.Plated) { _widgetColor = "PL"; } else { _widgetColor = "UP"; } cbody.AppendFormat("*"); cbody.Append(String.Format("{0,12} {1,30} {2,25} {3,16} {4,19}", _sizePrint, _typePrint, cgadget.Buttons, cgadget.Lights, cgadget.Switches)); cbody.Append(String.Format("{0,16} {1,15} {2,24} {3,26}", _gadgetColor, _widgetColor, _powerPrint, cgadget.Price)); cbody.Append(String.Format("{0,18} {1,16}", cgadget.SerialNumber, cgadget.UpcNumber)); cbody.AppendFormat(" "); cbody.AppendFormat("*"); cbody.AppendLine(); if (cgadget.GadgetColorType == GadgetColor.Painted) { _cltotalPainted++; } else if (cgadget.GadgetColorType == GadgetColor.Plated) { _cltotalPlated++; } else if (cgadget.GadgetColorType == GadgetColor.Unpainted) { _cltotalUnpainted++; } if (cgadget.WidgetColorType == WidgetColor.Painted) { _cltotalWPainted++; } else if (cgadget.WidgetColorType == WidgetColor.Plated) { _cltotalWPlated++; } else if (cgadget.WidgetColorType == WidgetColor.Unpainted) { _cltotalWUnpainted++; } if (cgadget.PowerType == GadgetPower.Battery) { _cltotalBattery++; } else if (cgadget.PowerType == GadgetPower.Generator) { _cltotalGenerator++; } else if (cgadget.PowerType == GadgetPower.Solar) { _cltotalSolar++; } } } _ctotalGadgetsCost = _cmediumGadgetSubtotal + _clargeGadgetSubtotal; _ctotalGadgetsOrdered = _cmediumGadgetsOrdered + _clargeGadgetsOrdered; _ctotalGadgetsPainted = _cmtotalPainted + _cltotalPainted; _ctotalGadgetsUnpainted = _cmtotalUnpainted + _cltotalUnpainted; _ctotalGadgetsPlated = _cmtotalPlated + _cltotalPlated; _ctotalWidgetsSetsPainted = _cmtotalWPainted + _cltotalWPainted; _ctotalWidgetsSetsPlated = _cmtotalWPlated + _cltotalWPlated; _ctotalWidgetsSetsUnpainted = _cmtotalWUnpainted + _cltotalWUnpainted; _ctotalGadgetsGenerator = _cltotalGenerator; _ctotalGadgetsSolar = _cmtotalSolar + _cltotalSolar; _ctotalGadgetsBattery = _cmtotalBattery + _cltotalBattery; _ctotalGadgetsButtons = _cmtotalButtons + _cltotalButtons; _ctotalGadgetsLights = _cmtotalLights + _cltotalLights; _ctotalGadgetsSwitches = _cmtotalSwitches + _cltotalSwitches; heading.AppendLine(); heading.AppendLine(); heading.AppendFormat("*******************************************************************************************************************"); heading.AppendFormat("*******************************************************************************************************************"); heading.AppendLine(); heading.AppendFormat("*"); heading.AppendFormat(" "); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); heading.AppendFormat("*"); heading.AppendFormat(" "); heading.AppendFormat(" WAG CORPORATION"); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); heading.AppendFormat("*"); heading.AppendFormat(" "); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); heading.AppendFormat("*"); heading.AppendFormat(" "); heading.AppendFormat(" Thank you for Ordering from us, we are here to serve you! "); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); heading.AppendFormat("*"); heading.AppendFormat(" "); heading.AppendFormat("Please feel free to fill out the"); heading.AppendFormat(" survey at Http://www.wagcorp.com/survey and let us know your"); heading.AppendFormat(" overall experience with the order process!"); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); heading.AppendFormat("*"); heading.AppendFormat(" "); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); heading.AppendFormat("*"); heading.AppendFormat(" "); heading.AppendFormat(" Date/TIME: {0}", now); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); heading.AppendFormat("*"); heading.AppendFormat(" "); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); heading.AppendFormat("*******************************************************************************************************************"); heading.AppendFormat("*******************************************************************************************************************"); heading.AppendLine(); heading.AppendFormat("* Order Details:"); heading.AppendFormat(" "); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); heading.AppendFormat("*"); heading.AppendFormat(" "); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); heading.AppendFormat("*"); heading.AppendFormat(" "); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); heading.AppendFormat("*"); heading.Append(String.Format("{0,10} {1,30} {2,28} {3,16} {4,20}", " Gadget Size", "Gadget Type", "Gadget Buttons", "Gadget Lights", "Gadget Switches")); heading.Append(String.Format("{0,15} {1,15} {2,26} {3,22}", "Gadget Color", "Widget Color", "Gadget PowerSource", "Gadget Price")); heading.Append(String.Format("{0,10} {1,10}", " Gadget Serial", " Gadget Upc")); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); heading.AppendFormat("*"); heading.Append(String.Format("{0,15} {1,30}", " (S)mall(M)ed(L)arge", "(R)etail(W)arehouse")); heading.Append(String.Format("{0,96}", "(PT)Painted(PL)Plated(UP)Unpainted")); heading.Append(String.Format("{0,10}", " (B)attery(S)olar(G)enerator")); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); heading.AppendFormat("*"); heading.AppendFormat(" "); heading.AppendFormat(" "); heading.AppendFormat("*"); heading.AppendLine(); cfooter.AppendFormat("*"); cfooter.AppendFormat(" "); cfooter.AppendFormat(" "); cfooter.AppendFormat("*"); cfooter.AppendLine(); cfooter.AppendFormat("*******************************************************************************************************************"); cfooter.AppendFormat("*******************************************************************************************************************"); cfooter.AppendLine(); cfooter.AppendFormat("* Order Summary:"); cfooter.AppendLine(); cfooter.AppendFormat("* Total Warehouse Gadget info "); cfooter.AppendLine(); cfooter.AppendFormat("* Total Custom Medium Gadget info "); cfooter.AppendLine(); cfooter.AppendFormat("* Total Medium Gadgets Ordered: {0}", _cmediumGadgetsOrdered); cfooter.AppendLine(); cfooter.AppendFormat("* Buttons: {0} Lights: {1} Switches: {2}", _cmtotalButtons, _cmtotalLights, _cmtotalSwitches); cfooter.AppendLine(); cfooter.AppendFormat("*"); cfooter.AppendFormat(" GadgetsPlated: {0} GadgetsPainted: {1} GadgetsUnpainted: {2}", _cmtotalPlated, _cmtotalPainted, _cmtotalUnpainted); cfooter.AppendFormat(" WPlated: {0} WPainted: {1} WUnpainted: {2}", _cmtotalWPlated, _cmtotalWPainted, _cmtotalWUnpainted); cfooter.AppendFormat(" "); cfooter.AppendFormat(" Battery: {0} Generator: {1} Solar: {2}", _cmtotalBattery, _cmtotalGenerator, _cmtotalSolar); cfooter.AppendLine(); cfooter.AppendFormat("*"); cfooter.AppendFormat(" "); cfooter.AppendFormat(" "); cfooter.AppendFormat(" SubTotal Cost: ${0}", _cmediumGadgetSubtotal); cfooter.AppendLine(); cfooter.AppendFormat("*"); cfooter.AppendLine(); cfooter.AppendFormat("* Total Custom Large Gadget info "); cfooter.AppendLine(); cfooter.AppendFormat("* Total Large Gadgets Ordered: {0}", _clargeGadgetsOrdered); cfooter.AppendLine(); cfooter.AppendFormat("* Buttons: {0} Lights: {1} Switches: {2}", _cltotalButtons, _cltotalLights, _cltotalSwitches); cfooter.AppendLine(); cfooter.AppendFormat("*"); cfooter.AppendFormat(" GadgetsPlated: {0} GadgetsPainted: {1} GadgetsUnpainted: {2}", _cltotalPlated, _cltotalPainted, _cltotalUnpainted); cfooter.AppendFormat(" WPlated: {0} WPainted: {1} WUnpainted: {2}", _cltotalWPlated, _cltotalWPainted, _cltotalWUnpainted); cfooter.AppendFormat(" Battery: {0} Generator: {1} Solar: {2}", _cltotalBattery, _cltotalGenerator, _cltotalSolar); cfooter.AppendLine(); cfooter.AppendFormat("*"); cfooter.AppendFormat(" "); cfooter.AppendFormat(" "); cfooter.AppendFormat(" SubTotal Cost: ${0}", _clargeGadgetSubtotal); cfooter.AppendLine(); cfooter.AppendFormat("* Total Gadgets Ordered: {0}", _ctotalGadgetsOrdered); cfooter.AppendLine(); cfooter.AppendFormat("* Buttons: {0} Lights: {1} Switches: {2}", _ctotalGadgetsButtons, _ctotalGadgetsLights, _ctotalGadgetsSwitches); cfooter.AppendLine(); cfooter.AppendFormat("*"); cfooter.AppendFormat(" GadgetsPlated: {0} GadgetsPainted: {1} GadgetsUnpainted: {2}", _ctotalGadgetsPlated, _ctotalGadgetsPainted, _ctotalGadgetsUnpainted); cfooter.AppendFormat(" WPlated: {0} WPainted: {1} WUnpainted: {2}", _ctotalWidgetsSetsPlated, _ctotalWidgetsSetsPainted, _ctotalWidgetsSetsUnpainted); cfooter.AppendFormat(" Battery: {0} Generator: {1} Solar: {2}", _ctotalGadgetsBattery, _ctotalGadgetsGenerator, _ctotalGadgetsSolar); cfooter.AppendLine(); cfooter.AppendFormat("*"); cfooter.AppendFormat(" "); cfooter.AppendFormat(" "); cfooter.AppendFormat("--------------------------"); cfooter.AppendLine(); cfooter.AppendFormat("*"); cfooter.AppendFormat(" "); cfooter.AppendFormat(" "); cfooter.AppendFormat(" Total Cost: ${0}", _ctotalGadgetsCost); cfooter.AppendLine(); cfooter.AppendFormat("*"); cfooter.AppendLine(); cfooter.AppendFormat("* Please allow 5-7 business days for your shipment"); cfooter.AppendLine(); cfooter.AppendFormat("* Shipment Method: UPS"); cfooter.AppendLine(); cfooter.AppendFormat("* Tracking_number: " + customShipOrderTracker.NextTracking); cfooter.AppendLine(); cfooter.AppendFormat("* Order_number: " + customOrderTracker.NextOrder); cfooter.AppendLine(); cfooter.AppendFormat("*"); cfooter.AppendLine(); cfooter.AppendFormat("*********************************************************************************************************"); cfooter.AppendFormat("*********************************************************************************************************"); cfooter.AppendLine(); Console.WriteLine(heading.ToString() + cbody.ToString() + cfooter.ToString()); // Reset Accumulator Totals since Order has been processed. _ctotalGadgetsPainted = 0; _ctotalGadgetsPlated = 0; _ctotalGadgetsUnpainted = 0; _ctotalWidgetsSetsPainted = 0; _ctotalWidgetsSetsPlated = 0; _ctotalWidgetsSetsUnpainted = 0; _ctotalGadgetsBattery = 0; _ctotalGadgetsGenerator = 0; _ctotalGadgetsSolar = 0; _ctotalGadgetsButtons = 0; _ctotalGadgetsLights = 0; _ctotalGadgetsSwitches = 0; _cmediumGadgetsOrdered = 0; _clargeGadgetsOrdered = 0; _ctotalGadgetsOrdered = 0; _cmtotalButtons = 0; _cmtotalSwitches = 0; _cmtotalLights = 0; _cmtotalBattery = 0; _cmtotalGenerator = 0; _cmtotalSolar = 0; _cmtotalPainted = 0; _cmtotalWPainted = 0; _cmtotalPlated = 0; _cmtotalWPlated = 0; _cmtotalUnpainted = 0; _cmtotalWUnpainted = 0; _cltotalButtons = 0; _cltotalSwitches = 0; _cltotalLights = 0; _cltotalBattery = 0; _cltotalGenerator = 0; _cltotalSolar = 0; _cltotalPainted = 0; _cltotalPlated = 0; _cltotalUnpainted = 0; _cltotalWPainted = 0; _cltotalWPlated = 0; _cltotalWUnpainted = 0; _cmediumGadgetSubtotal = 0m; _ctotalGadgetsCost = 0m; _cmediumGadgetSubtotal = 0m; _clargeGadgetSubtotal = 0; _clargeGadgetsOrdered = 0; }
public static void Import(out int count) { using (StreamWriter writer = new StreamWriter(@"C:\HCCCustomerOutput.txt")) { Console.SetOut(writer); count = 0; List <string> errorReport = new List <string>(); try { List <ImportedCustomer> impCusts = GetAll(); foreach (ImportedCustomer impCust in impCusts) { Console.WriteLine(count + " : "); if (!impCust.IsValid) { impCust.Email = "admin" + count.ToString() + "@healthychefcreations.com"; } else if (impCust.Email.Contains("info@healthychef") || impCust.Email.Contains("thehealthyassistant@earthlink")) { impCust.Email = "admin" + count.ToString() + "@healthychefcreations.com"; } Console.WriteLine(impCust.Email); if (impCust.IsValid) { count++; string userName = impCust.Email.Trim().Split('@')[0] + DateTime.Now.ToString("yyyyMMddHHmmtt"); string password = OrderNumberGenerator.GenerateOrderNumber("?#?#?#?#"); string aspUserName = Membership.GetUserNameByEmail(impCust.Email.Trim()); MembershipUser newUser = null; if (!string.IsNullOrWhiteSpace(aspUserName)) { newUser = Membership.GetUser(aspUserName); } MembershipCreateStatus createResult = MembershipCreateStatus.UserRejected; if (newUser == null) { newUser = Membership.CreateUser(userName, password, impCust.Email.Trim(), "import", "import", true, out createResult); if (newUser != null) { Console.WriteLine(newUser.UserName + "New user."); } } else { Console.WriteLine(newUser.UserName + " Existing user."); createResult = MembershipCreateStatus.Success; } if (newUser != null) { if (createResult == MembershipCreateStatus.Success) { //Assign Customer role to newUser try { if (!Roles.IsUserInRole(newUser.UserName, "Customer")) { Roles.AddUserToRole(newUser.UserName, "Customer"); Console.WriteLine(newUser.UserName + " Role assigned."); } } catch (Exception ex) { Console.WriteLine(newUser.UserName + " =Assign role failed." + ex.Message + ex.StackTrace); } //Send E-mail notification to account user //HealthyChef.Email.EmailController ec = new HealthyChef.Email.EmailController(); //ec.SendMail_NewUserConfirmation(email, password); //Create a Healthy Chef profile for this new user hccUserProfile newProfile = hccUserProfile.GetBy((Guid)newUser.ProviderUserKey).SingleOrDefault(a => !a.ParentProfileID.HasValue); if (newProfile == null) { try { newProfile = new hccUserProfile { MembershipID = (Guid)newUser.ProviderUserKey, CreatedBy = (Membership.GetUser() == null ? Guid.Empty : (Guid)Membership.GetUser().ProviderUserKey), CreatedDate = DateTime.Now, AccountBalance = 0.00m, IsActive = true, FirstName = impCust.FirstName.Trim(), LastName = impCust.LastName.Trim(), ProfileName = impCust.FirstName.Trim() }; //Save all hccProfile information using (var cont = new healthychefEntities()) { System.Data.EntityKey key = cont.CreateEntityKey("hccUserProfiles", newProfile); object oldObj; if (cont.TryGetObjectByKey(key, out oldObj)) { cont.ApplyCurrentValues("hccUserProfiles", newProfile); } else { cont.hccUserProfiles.AddObject(newProfile); } cont.SaveChanges(); } //cont.Refresh(System.Data.Objects.RefreshMode.StoreWins, newProfile); Console.WriteLine(newUser.UserName + " New profile."); } catch (Exception) { Console.WriteLine("=" + newUser.UserName + " Save Profile failed."); } } else { Console.WriteLine(newUser.UserName + " Existing profile."); createResult = MembershipCreateStatus.Success; } if (newProfile != null && newProfile.UserProfileID > 0) { if (impCust.OtherDeliveryInfo != null && !string.IsNullOrWhiteSpace(impCust.OtherDeliveryInfo)) { hccUserProfileNote shipNote = new hccUserProfileNote { DateCreated = DateTime.Now, DisplayToUser = false, UserProfileID = newProfile.UserProfileID, IsActive = true, Note = impCust.OtherDeliveryInfo, NoteTypeID = (int)Enums.UserProfileNoteTypes.ShippingNote }; using (var cont = new healthychefEntities()) { EntityKey key = cont.CreateEntityKey("hccUserProfileNotes", shipNote); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { cont.ApplyCurrentValues(key.EntitySetName, shipNote); } else { cont.hccUserProfileNotes.AddObject(shipNote); } cont.SaveChanges(); } } if (impCust.HowDidYouHear != null && !string.IsNullOrWhiteSpace(impCust.HowDidYouHear)) { hccUserProfileNote hearNote = new hccUserProfileNote { DateCreated = DateTime.Now, DisplayToUser = false, UserProfileID = newProfile.UserProfileID, IsActive = true, Note = impCust.HowDidYouHear, NoteTypeID = (int)Enums.UserProfileNoteTypes.GeneralNote }; using (var cont = new healthychefEntities()) { EntityKey key = cont.CreateEntityKey("hccUserProfileNotes", hearNote); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { cont.ApplyCurrentValues(key.EntitySetName, hearNote); } else { cont.hccUserProfileNotes.AddObject(hearNote); } cont.SaveChanges(); } } try { //save Shipping Address hccAddress shipAddr = null; if (newProfile.ShippingAddressID.HasValue) { shipAddr = hccAddress.GetById(newProfile.ShippingAddressID.Value); } if (shipAddr != null) { try { newProfile.ShippingAddressID = null; //Save all hccProfile information using (var cont = new healthychefEntities()) { System.Data.EntityKey key1 = cont.CreateEntityKey("hccUserProfiles", newProfile); object oldObj1; if (cont.TryGetObjectByKey(key1, out oldObj1)) { cont.ApplyCurrentValues("hccUserProfiles", newProfile); } else { cont.hccUserProfiles.AddObject(newProfile); } cont.SaveChanges(); } //cont.Refresh(System.Data.Objects.RefreshMode.StoreWins, newProfile); using (var cont = new healthychefEntities()) { EntityKey key = cont.CreateEntityKey("hccAddresses", shipAddr); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { cont.AttachTo(shipAddr.EntityKey.EntitySetName, shipAddr); cont.DeleteObject(shipAddr); } cont.SaveChanges(); } shipAddr = null; } catch (Exception ex) { Console.WriteLine(newUser.UserName + " =Delete old shipping address failed." + ex.Message + ex.StackTrace); } } if (shipAddr == null) { shipAddr = new hccAddress(); } if (impCust.ShippingAddress1 != null) { shipAddr.Address1 = (string.IsNullOrWhiteSpace(impCust.ShippingAddress1) ? "" : impCust.ShippingAddress1.Trim()); } else { shipAddr.Address1 = ""; } if (impCust.ShippingAddress2 != null) { shipAddr.Address2 = (string.IsNullOrWhiteSpace(impCust.ShippingAddress2) ? "" : impCust.ShippingAddress2.Trim()); } else { shipAddr.Address2 = ""; } if (impCust.ShippingAddress3 != null) { shipAddr.Address2 += " " + (string.IsNullOrWhiteSpace(impCust.ShippingAddress3) ? "" : impCust.ShippingAddress3.Trim()); } shipAddr.AddressTypeID = (int)Enums.AddressType.Shipping; if (impCust.ShippingCity != null) { shipAddr.City = (string.IsNullOrWhiteSpace(impCust.ShippingCity) ? "" : impCust.ShippingCity.Trim()); } else { shipAddr.City = ""; } shipAddr.Country = "US"; if (impCust.FirstName != null) { shipAddr.FirstName = (string.IsNullOrWhiteSpace(impCust.FirstName) ? "" : impCust.FirstName.Trim()); } else { shipAddr.FirstName = ""; } shipAddr.IsBusiness = false; if (impCust.LastName != null) { shipAddr.LastName = (string.IsNullOrWhiteSpace(impCust.LastName) ? "" : impCust.LastName.Trim()); } else { shipAddr.LastName = ""; } if (impCust.Phone1 != null) { shipAddr.Phone = (string.IsNullOrWhiteSpace(impCust.Phone1) ? "" : impCust.Phone1.Trim()); } else { shipAddr.Phone = ""; } if (impCust.Phone1Ext != null) { shipAddr.Phone += (string.IsNullOrWhiteSpace(impCust.Phone1Ext.Trim()) ? "" : " x" + impCust.Phone1Ext.Trim()); } else { shipAddr.Phone = ""; } if (impCust.ShippingZipCode != null) { shipAddr.PostalCode = (string.IsNullOrWhiteSpace(impCust.ShippingZipCode) ? "" : impCust.ShippingZipCode.Trim()); } else { shipAddr.PostalCode = ""; } if (impCust.ShippingState != null) { shipAddr.State = (string.IsNullOrWhiteSpace(impCust.ShippingState) ? "" : impCust.ShippingState.Trim()); } else { shipAddr.State = ""; } if (impCust.ShipMethod == null) { shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.Delivery; } else if (impCust.ShipMethod.Trim() == "F") { shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.Delivery; } else if (impCust.ShipMethod.Trim() == "P") { shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.LocalPickUp; } else if (impCust.ShipMethod.Trim() == "D") { shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.LocalDelivery; } else { shipAddr.DefaultShippingTypeID = (int)Enums.DeliveryTypes.Delivery; } if (shipAddr != null) { try { using (var cont = new healthychefEntities()) { EntityKey key = cont.CreateEntityKey("hccAddresses", shipAddr); object originalItem = null; if (cont.TryGetObjectByKey(key, out originalItem)) { cont.hccAddresses.ApplyCurrentValues((hccAddress)originalItem); } else { cont.hccAddresses.AddObject(shipAddr); } cont.SaveChanges(); } //cont.Refresh(System.Data.Objects.RefreshMode.StoreWins, shipAddr); } catch (Exception ex) { Console.WriteLine(newUser.UserName + " =Shipping address save failed." + ex.Message + ex.StackTrace); } } if (shipAddr != null && shipAddr.AddressID > 0) { newProfile.ShippingAddressID = shipAddr.AddressID; } else { newProfile.ShippingAddressID = null; } using (var cont = new healthychefEntities()) { System.Data.EntityKey upkey = cont.CreateEntityKey("hccUserProfiles", newProfile); object oldObj; if (cont.TryGetObjectByKey(upkey, out oldObj)) { cont.ApplyCurrentValues("hccUserProfiles", newProfile); } else { cont.hccUserProfiles.AddObject(newProfile); } cont.SaveChanges(); } Console.WriteLine(newUser.UserName + " Shipping address saved."); } catch (Exception ex) { Console.WriteLine(newUser.UserName + " =Shipping address not created." + ex.Message + ex.StackTrace); } } else { Console.WriteLine("User Profile for user: "******" ID not created."); } } else { Console.WriteLine("=New user for user: "******" not created."); } } else { Console.WriteLine(createResult.ToString() + " : " + impCust.Email); } } else { count++; Console.WriteLine("=Customer: " + impCust.FirstName + " " + impCust.LastName + " has no email address."); } } } catch (Exception ex) { Console.WriteLine("=" + ex.Message + " : " + ex.StackTrace); } } }
protected override void SaveForm() { try { MembershipUser user = null; if (CurrentAspNetId != null) { user = Membership.GetUser(CurrentAspNetId); } else { try { user = Membership.GetUser(Membership.GetUserNameByEmail(txtEmail.Text.Trim())); } catch (Exception) { } } if (user == null) // create new profile { // create membership user //formulate username string email = txtEmail.Text.Trim(); string userName = email.Split('@')[0] + DateTime.Now.ToString("yyyyMMddHHmmtt"); string password = OrderNumberGenerator.GenerateOrderNumber("?#?#?#?#"); MembershipCreateStatus createResult; MembershipUser newUser = Membership.CreateUser(userName, password, email, null, null, true, out createResult); List <ListItem> selRoles = cblRoles.Items.OfType <ListItem>().Where(a => a.Selected).ToList(); selRoles.ForEach(delegate(ListItem item) { Roles.AddUserToRole(userName, item.Value); }); if (createResult == MembershipCreateStatus.Success) { CurrentAspNetId = (Guid)newUser.ProviderUserKey; Email.EmailController ec = new Email.EmailController(); ec.SendMail_NewUserConfirmation(email, password); if (selRoles.Where(a => a.Text.Contains("Customer")).Count() > 0) { hccUserProfile newProfile = new hccUserProfile { MembershipID = (Guid)newUser.ProviderUserKey, CreatedBy = (Guid)Helpers.LoggedUser.ProviderUserKey, CreatedDate = DateTime.Now, ProfileName = txtProfileName.Text.Trim(), FirstName = txtFirstName.Text.Trim(), LastName = txtLastName.Text.Trim(), IsActive = true }; if (ddlCoupons.SelectedIndex > 0) { newProfile.DefaultCouponId = int.Parse(ddlCoupons.SelectedValue); } else { newProfile.DefaultCouponId = null; } newProfile.Save(); CurrentUserID.Value = newProfile.MembershipID.ToString(); this.PrimaryKeyIndex = newProfile.UserProfileID; Response.Redirect("~/WebModules/ShoppingCart/Admin/AccountManager.aspx?UserID=" + newProfile.MembershipID.ToString(), false); } liBilling.Visible = true; liShipping.Visible = true; liPrefs.Visible = true; liAllergens.Visible = true; liSubProfiles.Visible = true; liNotes.Visible = true; liTransactions.Visible = true; liPurchases.Visible = true; liCart.Visible = true; tabs2.Visible = true; tabs3.Visible = true; tabs4.Visible = true; tabs5.Visible = true; tabs6.Visible = true; tabs8.Visible = true; tabs10.Visible = true; tabs7.Visible = true; tabs9.Visible = true; LoadForm(); OnSaved(new ControlSavedEventArgs(newUser.ProviderUserKey)); } else { cstValProfile0.Enabled = true; cstValProfile0.ErrorMessage = Helpers.CreateUserStatusMessage(createResult); cstValProfile0.Validate(); Page.Validate(); } } else // edit existing profile { if (user.Email != txtEmail.Text.Trim()) // update userprofile and aspmembership user { user.Email = txtEmail.Text.Trim(); Membership.UpdateUser(user); } if (chkIsLockedOut.Checked) { Helpers.LockUser(user); } else { if (user.IsLockedOut) { user.UnlockUser(); } if (!user.IsApproved) { user.IsApproved = true; Membership.UpdateUser(user); } } List <ListItem> selRoles = cblRoles.Items.OfType <ListItem>().Where(a => a.Selected).ToList(); if (Roles.IsUserInRole(Helpers.LoggedUser.UserName, "Administrators")) { Roles.GetAllRoles().ToList().ForEach(delegate(string roleName) { if (Roles.IsUserInRole(user.UserName, roleName)) { Roles.RemoveUserFromRole(user.UserName, roleName); } }); selRoles.ForEach(delegate(ListItem item) { Roles.AddUserToRole(user.UserName, item.Value); }); } hccUserProfile editProfile = hccUserProfile.GetParentProfileBy((Guid)user.ProviderUserKey); if (editProfile == null && selRoles.Where(a => a.Text.Contains("Customer")).Count() > 0) { editProfile = new hccUserProfile { MembershipID = (Guid)user.ProviderUserKey, CreatedBy = (Guid)Helpers.LoggedUser.ProviderUserKey, CreatedDate = DateTime.Now, ProfileName = txtProfileName.Text.Trim(), FirstName = txtFirstName.Text.Trim(), LastName = txtLastName.Text.Trim(), CanyonRanchCustomer = cbCanyonRanchCustomer.Checked }; editProfile.Save(); this.PrimaryKeyIndex = editProfile.UserProfileID; OnSaved(new ControlSavedEventArgs(editProfile.UserProfileID)); } if (editProfile != null) { editProfile.ProfileName = txtProfileName.Text.Trim(); editProfile.FirstName = txtFirstName.Text.Trim(); editProfile.LastName = txtLastName.Text.Trim(); editProfile.CanyonRanchCustomer = cbCanyonRanchCustomer.Checked; if (ddlCoupons.SelectedIndex > 0) { editProfile.DefaultCouponId = int.Parse(ddlCoupons.SelectedValue); } else { editProfile.DefaultCouponId = null; } editProfile.Save(); if (!ProfilePrefsEdit1.ShowSave) { ProfilePrefsEdit1.Save(); } if (!ProfileAllgsEdit1.ShowSave) { ProfileAllgsEdit1.Save(); } ProfileCartEdit1.Bind(); OnSaved(new ControlSavedEventArgs(editProfile.UserProfileID)); } OnSaved(new ControlSavedEventArgs(editProfile.UserProfileID)); } } catch (ProviderException pex) { lblFeedback.Text = pex.Message; } catch { throw; } }
protected void btnContinue_Click(object sender, EventArgs e) { lblerror.Text = ""; lblsuccess.Text = ""; var users = (from MembershipUser u in Membership.GetAllUsers() where u.Email == txtForgotEmail.Text.Trim() select new { Email = u.Email }).ToList(); if (users.Count == 0) { lblerror.Text = "This email is not registered"; } else { string userName = string.Empty; MembershipUser user = null; bool success = false; string newPassword = string.Empty; try { userName = Membership.GetUserNameByEmail(txtForgotEmail.Text.Trim()); MembershipUser forgotpassworduser = Membership.GetUser(userName); string[] roles = Roles.GetRolesForUser(userName); if (roles.Contains("Customer") && roles.Count() == 1) { lblerror.Text = "Access denied"; } else { if (!string.IsNullOrWhiteSpace(userName)) { user = Membership.GetUser(userName); if (user != null) { string tempPassword = user.ResetPassword(); newPassword = OrderNumberGenerator.GenerateOrderNumber("?#?#?#?#"); success = user.ChangePassword(tempPassword, newPassword); } if (success) { //send Email EmailController Ec = new EmailController(); Ec.SendMail_PasswordReset(txtForgotEmail.Text.Trim(), newPassword); lblsuccess.Text = "Password Reset Successful - Your new password has been sent to the email address: " + txtForgotEmail.Text.Trim(); } else { lblerror.Text = "Password Reset Failed. Email address not recognized. " + "Please re-enter your email address or call customer service at 866-575-2433 for assistance."; } } } } catch (MembershipPasswordException ex) { lblerror.Text = "Cannot reset password. This account is currently locked."; } catch (Exception exstring) { lblerror.Text = exstring.Message; } } }