public HttpResponseMessage AddUsersData(UserCreate objUser, string Token) { string strJson = string.Empty; var response = this.Request.CreateResponse(HttpStatusCode.OK); try { using (TTPAPIDataContext DB = new TTPAPIDataContext()) { UserManagement objUserManagement = new UserManagement(); Guid id = Guid.NewGuid(); objUserManagement.UserId = id.ToString(); objUserManagement.UserName = objUser.UserName; objUserManagement.AccountID = objUser.AccountID; objUserManagement.RoleId = objUser.RoleId; objUserManagement.CreatedDateTime = DateTime.Now; DB.UserManagements.InsertOnSubmit(objUserManagement); DB.SubmitChanges(); UserContactDet objUserContactDet = new UserContactDet(); objUserContactDet.EmailAddress = objUser.Email; objUserContactDet.PhoneNumber = objUser.PhoneNumber; objUserContactDet.PostalAddress = objUser.Address; objUserContactDet.UserId = id.ToString(); objUserContactDet.PreferredAlert = objUser.PreferredAlert; DB.UserContactDets.InsertOnSubmit(objUserContactDet); DB.SubmitChanges(); UserLoginDet objUserLoginDet = new UserLoginDet(); objUserLoginDet.UpdatedDateTime = DateTime.Now; objUserLoginDet.Password = objUser.Password; objUserLoginDet.UserId = id.ToString(); objUserLoginDet.LastLoginDateTime = DateTime.Now; DB.UserLoginDets.InsertOnSubmit(objUserLoginDet); DB.SubmitChanges(); strJson = "{\"Result\":\"" + id + "\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } } catch (Exception ex) { strJson = "{\"Result\":\"" + ex.Message + "\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } }
public HttpResponseMessage UpdateProfile(UserCreate objUser, string Token, string AppKey) { string strJson = string.Empty; var response = this.Request.CreateResponse(HttpStatusCode.OK); try { Accountmeg objaccountmegment = new Accountmeg(); string result = objaccountmegment.Getresult(AppKey, Token); if (result == "true") { using (TTPAPIDataContext DB = new TTPAPIDataContext()) { UserManagement objUserManagement = new UserManagement(); var checkuser = DB.UserManagements.Where(x => x.UserId == objUser.UserId).FirstOrDefault(); if (checkuser != null) { checkuser.UserName = objUser.UserName; checkuser.AccountID = objUser.AccountID; checkuser.RoleId = objUser.RoleId; checkuser.CreatedDateTime = DateTime.Now; // DB.UserManagements.InsertOnSubmit(objUserManagement); DB.SubmitChanges(); UserContactDet objUserContactDet = new UserContactDet(); var objusercontact = DB.UserContactDets.Where(x => x.UserId == objUser.UserId).FirstOrDefault(); objusercontact.EmailAddress = objUser.Email; objusercontact.PhoneNumber = objUser.PhoneNumber; objusercontact.PreferredAlert = objUser.PreferredAlert; objusercontact.PostalAddress = objUser.Address; DB.SubmitChanges(); UserLoginDet objUserLoginDet = new UserLoginDet(); var objloginDet = DB.UserLoginDets.Where(x => x.UserId == objUser.UserId).FirstOrDefault(); objloginDet.UpdatedDateTime = DateTime.Now; objloginDet.Password = objUser.Password; //objUserLoginDet.LastLoginDateTime = DateTime.Now; // DB.UserLoginDets.InsertOnSubmit(objUserLoginDet); DB.SubmitChanges(); strJson = "{\"Result\":\"204\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } else { strJson = "{\"Result\":\"100\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } } } else { strJson = "{\"Result\":\"Invalide AppKey\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } } catch (Exception ex) { strJson = "{\"Result\":\"" + ex.Message + "\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } }
public HttpResponseMessage GetForgetPassword(string UserName, string Email, string Token, string AppKey) { string strJson = string.Empty; var response = this.Request.CreateResponse(HttpStatusCode.OK); try { Accountmeg objaccountmegment = new Accountmeg(); string result = objaccountmegment.Getresult(AppKey, Token); if (result == "true") { using (TTPAPIDataContext DB = new TTPAPIDataContext()) { var ForgetPassword = DB.UserManagements.Where(x => x.UserName == UserName).FirstOrDefault(); if (ForgetPassword != null) { UserLoginDet objUserLoginDet = new UserLoginDet(); var userdata = DB.UserLoginDets.Where(x => x.UserId == ForgetPassword.UserId).FirstOrDefault(); Random rng = new Random(); int Password = rng.Next(1000, 100000000); // string Password = rng.Next(10).ToString(); userdata.Password = Password.ToString(); DB.SubmitChanges(); SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["SMTP"], Convert.ToInt32(ConfigurationManager.AppSettings["PORT"])); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["FromEmail"].ToString(), ConfigurationManager.AppSettings["Password"].ToString()); string fromEmail = ConfigurationManager.AppSettings["FromEmail"].ToString(); string toEmail = Email; MailMessage message = new MailMessage(); message.To.Add(toEmail); message.From = new MailAddress(fromEmail, "TTPA"); message.IsBodyHtml = true; message.Subject = "Send Password"; message.Body = "Hello, <br />"; message.Body += "Email Id : " + Email; message.Body += "User Name: " + UserName; message.Body += "<br />Your Password Is: " + Password; message.Body += "<br />Thank You."; smtp.Send(message); strJson = "{\"Result\":\"Password is sent to your mail.\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } else { strJson = "{\"Result\":\"AccountID is Already Use\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } } } else { strJson = "{\"Result\":\"Invalide AppKey\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } } catch (Exception ex) { strJson = "{\"Result\":\"" + ex.Message + "\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } }