public string InsertOrUpdateUser(Customer usr) { try { using (WebPresenceEntities _context = new WebPresenceEntities()) { if (usr.ID > 0) { _context.Customers.Single(o => o.ID == usr.ID); _context.Customers.ApplyCurrentValues(usr); } else { _context.Customers.AddObject(usr); } _context.SaveChanges(); return usr.ID.ToString(); } } catch (Exception ex) { return ex.Message; } }
protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { try { UserLogin user = new UserLogin(); user = UserManager.GetUserByEmail(txtEmail.Text); if (user != null) { lblEmailExists.Visible = true; return; } lblEmailExists.Visible = false; UserLogin UserObj = new UserLogin(); Customer CustomObject = new Customer(); CustomObject.FirstName = txtFirstName.Text; CustomObject.LastName = txtLastName.Text; CustomObject.Address = TexAddrress.Text; CustomObject.City = TextCity.Text; CustomObject.ContactNo = TexContact.Text; CustomObject.State = DropDownState.SelectedValue; CustomObject.Country = "USA"; CustomObject.PostalCode = TexPostal.Text; CustomObject.PackageFk = 1; CustomObject.IsCancelled = false; CustomObject.DateCancelled = CommonClass.CurrentTime(); if (usertupeId.Value == "1") { CustomObject.NextPaymentDate = DateTime.Now.AddDays(14); } else if (usertupeId.Value == "2") { CustomObject.NextPaymentDate = DateTime.Now.AddDays(7); } else { CustomObject.NextPaymentDate = DateTime.Now.AddDays(7); } CustomObject.IsFreeTrial = true; CustomObject.IsActive = true; CustomObject.IsDeleted = false; CustomObject.CreatedBy = 1; CustomObject.CreatedDate = DateTime.Now; CustomObject.DateCreated = CommonClass.CurrentTime(); CustomObject.DateUpdated = CommonClass.CurrentTime(); Customers objects = new Customers(); string id = objects.InsertOrUpdateUser(CustomObject); if (Convert.ToInt32(id) > 0) { Guid objGuid = Guid.NewGuid(); string uniqueID = objGuid.ToString().Substring(0, 8); UserObj.RoleId = Convert.ToInt32(usertupeId.Value); UserObj.CustomerId = Convert.ToInt32(id); UserObj.EmailId = txtEmail.Text; UserObj.Password = EncryptionHelper.Encrypt(txtPassword.Text); UserObj.IsClient = false; UserObj.LastLoginDate = CommonClass.CurrentTime(); UserObj.EmailVerificationCode = uniqueID; UserObj.IsEmailVerified = false; UserObj.PassWordResetCode = uniqueID; UserObj.IsLoginAllowed = false; UserObj.IsDeleted = false; UserObj.CreatedBy = 1; UserObj.CreatedDate = CommonClass.CurrentTime(); int UserLoginid = Convert.ToInt32(UserManager.InsertOrUpdateUserLogin(UserObj)); if (UserLoginid > 0) { string link = "http://" + System.Web.HttpContext.Current.Request.Url.Host.ToString() + "/WebPresence/EmailVerification.aspx?Email=" + txtEmail.Text + "&UserID=" + id + "&Code=" + uniqueID; string mailBody = "<table style='width:100%;'><tr><td width='25%'>Dear " + txtFirstName.Text + " " + txtLastName.Text + ",</td><td width='25%'> </td><td width='25%'> </td><td width='25%'> </td></tr><tr><td colspan='4'>An email verification code is being sending to you by webpresence team.Please find it below :</td></tr><tr><td width='25%'>" + link + "</td><td width='25%'> </td><td width='25%'> </td><td width='25%'> </td></tr><tr><td colspan='4'>You can verify your email by clicking at the link</td></tr><tr><td width='25%'> </td><td width='25%'> </td><td width='25%'> </td><td width='25%'> </td></tr><tr><td width='25%'>Thanks & Regards,</td><td width='25%'> </td><td width='25%'> </td><td width='25%'> </td></tr><tr><td width='25%'>WebPresence Team</td><td width='25%'> </td><td width='25%'> </td><td width='25%'> </td></tr><tr><td width='25%'>" + "http://" + System.Web.HttpContext.Current.Request.Url.Host.ToString() + "/WebPresence/" + "</td><td width='25%'> </td><td width='25%'> </td><td width='25%'> </td></tr></table>"; //<tr><td width='25%'>Verification Code :</td><td width='25%'>" + uniqueID + "</td><td width='25%'> </td><td width='25%'> </td></tr> string mailSubject = "Email Verification Code From WebPresence"; SendMail.SendEmail(mailBody, mailSubject, txtEmail.Text); if (CustomObject.IsFreeTrial == false) Response.Redirect("Signup2.aspx"); ClearControls(); } else { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "AlertMessage", "alert('Signup process failed! Please try again.');", true); } } else { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "AlertMessage", "alert('Signup process failed! Please try again.');", true); } } catch (Exception ex) { throw ex; } } }
/// <summary> /// Create a new Customer object. /// </summary> /// <param name="id">Initial value of the ID property.</param> /// <param name="firstName">Initial value of the FirstName property.</param> /// <param name="lastName">Initial value of the LastName property.</param> /// <param name="address">Initial value of the Address property.</param> /// <param name="city">Initial value of the City property.</param> /// <param name="state">Initial value of the State property.</param> /// <param name="country">Initial value of the Country property.</param> /// <param name="contactNo">Initial value of the ContactNo property.</param> /// <param name="postalCode">Initial value of the PostalCode property.</param> /// <param name="packageFk">Initial value of the PackageFk property.</param> /// <param name="isCancelled">Initial value of the IsCancelled property.</param> /// <param name="dateCancelled">Initial value of the DateCancelled property.</param> /// <param name="nextPaymentDate">Initial value of the NextPaymentDate property.</param> /// <param name="isFreeTrial">Initial value of the IsFreeTrial property.</param> /// <param name="isActive">Initial value of the IsActive property.</param> /// <param name="dateCreated">Initial value of the DateCreated property.</param> /// <param name="dateUpdated">Initial value of the DateUpdated property.</param> public static Customer CreateCustomer(global::System.Int32 id, global::System.String firstName, global::System.String lastName, global::System.String address, global::System.String city, global::System.String state, global::System.String country, global::System.String contactNo, global::System.String postalCode, global::System.Int32 packageFk, global::System.Boolean isCancelled, global::System.DateTime dateCancelled, global::System.DateTime nextPaymentDate, global::System.Boolean isFreeTrial, global::System.Boolean isActive, global::System.DateTime dateCreated, global::System.DateTime dateUpdated) { Customer customer = new Customer(); customer.ID = id; customer.FirstName = firstName; customer.LastName = lastName; customer.Address = address; customer.City = city; customer.State = state; customer.Country = country; customer.ContactNo = contactNo; customer.PostalCode = postalCode; customer.PackageFk = packageFk; customer.IsCancelled = isCancelled; customer.DateCancelled = dateCancelled; customer.NextPaymentDate = nextPaymentDate; customer.IsFreeTrial = isFreeTrial; customer.IsActive = isActive; customer.DateCreated = dateCreated; customer.DateUpdated = dateUpdated; return customer; }
/// <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); }