public ActionResult Call_Back_RazorPay(string razorpay_payment_id) { if (Session["User_Informations"] == null || Session["Shopping_Cart"] == null) { return(RedirectToAction("ShoppingCart", "Shop")); } var user_informations = (User_Informations)Session["User_Informations"]; // Add User Informations into DB User_Informations_Helper.Update(user_informations); int id = User_Informations_Helper.Get_ID(User.Identity.GetUserId()); var shoppingCartList = (List <Shopping_Cart>)Session["Shopping_Cart"]; foreach (var item in shoppingCartList) { var Item = new Order() { UID = @User.Identity.GetUserId(), Ordered = DateTime.Now, Paid = DateTime.Now, Delivered = DateTime.Now, UserInformationsID = id, ShopItemID = item.ID, Quantity = item.Quantity, RazorPayID = razorpay_payment_id }; _context.Order.Add(Item); _context.SaveChanges(); string message = $"Hello {user_informations.Fname}! <br/> We've just received your paiment for <b>{item.Name}</b>, RazorPaiID: <b>{razorpay_payment_id}</b>!<br /> Thank's for your shopping!"; string subject = "Information about payment"; Send_Mail.Mail("*****@*****.**", User.Identity.GetUserName(), message, subject); } // Clear Session Session["Shopping_Cart"] = null; Session["User_Informations"] = null; Session["Total_Price"] = null; // Set message Session["Message"] = "Congratulations! You just bought in our shop, we send e-mail with more informations!"; return(RedirectToAction("Information", "Shop")); return(View()); }
public async Task SendAsyncMail() { try { Boolean priority = false, MailTestEnable = true; string TestToId = ""; List <MailModel> MailS = _Base.GetMailList(); MailTestEnable = Convert.ToBoolean(_Mail_EnableTest); TestToId = _Mail_TestToID; foreach (var item in MailS) { Send_Mail SM = new Send_Mail(); SM.subject = item.Subject; SM.body = PopulateBody(item.TemplateName.Trim(), item.Body, item.Name, item.To); SM.priority = priority; SM.ID = item.Running_ID; SM.Q_UserID = item.Q_UserID; string To = "", Name = ""; if (MailTestEnable) { To = TestToId; Name = "Test"; } else { To = item.To.ToString(); Name = item.Name.ToString(); } await Task.Run(() => this.Send(To, Name, SM)); } _Log.createLog("All Mail Sent"); } catch (Exception ex) { _Log.createLog(ex, "-->SendAsyncMail" + ex.Message.ToString()); } }
protected void btnSave_Click(object sender, EventArgs e) { ClientScriptManager cm = this.ClientScript; DateTime dob = DateTime.Parse(Request.Form[TextBox1.UniqueID]); E_reunion reu = new E_reunion(); reu.Fecha = dob; new DAO_Admin().addReunion(reu); List <E_user> mail_user = new DAO_Admin().getUserMail(); Send_Mail mail = new Send_Mail(); foreach (E_user mails in mail_user) { mail.sendMail(mails.Mail, "", "", "", "Se ha registrado una nueva reunion: " + dob.ToString()); } cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Se ha programado la reunion y se ha informado a los usuarios');</script>"); }
public async Task <List <User> > Reset_Password_Pass([FromBody] User user) { List <User> temp = new List <User>(); Helper helper; foreach (User usere in GetUsers()) { if (usere.Reset_pass == user.Reset_pass) { Send_Mail send_Mail = new Send_Mail(); helper = send_Mail.Reset_Pass_Pass(usere.Email); if (helper.check == true) { SqlCommand command = new SqlCommand("UPDATE dbo.[User] SET Password = @Password, Reset_pass = @Reset_pass WHERE Email = @Email", cnn); command.Parameters.Add("@Password", SqlDbType.VarChar, 40).Value = helper.word; command.Parameters.Add("@Reset_pass", SqlDbType.VarChar, 40).Value = ""; command.Parameters.Add("@Email", SqlDbType.VarChar, 40).Value = usere.Email; cnn.Open(); command.ExecuteNonQuery(); command.Dispose(); cnn.Close(); temp.Add(user); return(temp); } else { user.Error_Messege = "Email_wasn't_send"; temp.Add(user); return(temp); } } } user.Error_Messege = "Wrong_code"; temp.Add(user); return(temp); }
protected void B_Cambiar_Click(object sender, EventArgs e) { ClientScriptManager cm = this.ClientScript; E_user e_user = new DAO_Admin().getUserLogin(((E_user)Session["validUser"]).User_name); if (TB_Pass.Text == TB_Repeat.Text) { e_user.Pass = TB_Pass.Text; new DAO_Admin().editUser(e_user); cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Su contraseña ha sido cambiada con exito');</script>"); Send_Mail mail = new Send_Mail(); mail.sendMail(e_user.Mail, "", e_user.User_name, e_user.Pass, "Su contraseña se ha actualizado"); TB_Pass.Text = String.Empty; TB_Repeat.Text = String.Empty; } else { cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Las contraseñas no coinciden');</script>"); return; } }
protected void BT_Enviar_Click(object sender, EventArgs e) { ClientScriptManager cm = this.ClientScript; string fileName = System.IO.Path.GetFileName(FU_Foto.PostedFile.FileName); string extension = System.IO.Path.GetExtension(FU_Foto.PostedFile.FileName); string saveLocation = Server.MapPath("~\\Images\\ProfilePictures\\") + DateTime.Now.ToFileTime().ToString() + extension; E_user e_user = new E_user(); e_user.Id_rol = 2; e_user.Name = TB_Nombre.Text; e_user.Last_name = TB_Apellido.Text; e_user.User_name = TB_User.Text; e_user.Pass = TB_Pass.Text; e_user.Mail = TB_Correo.Text; e_user.Id_ruta = int.Parse(DDL_NumRuta.SelectedValue); e_user.Activo = CB_Activo.Checked; e_user.Profile_pic = saveLocation; //---------------------------------// E_user euser = new DAO_Admin().getUserLogin(TB_User.Text); try { if (euser.User_name == TB_User.Text) { cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('El usuario ya existe');</script>"); return; } } catch (NullReferenceException) { } E_user euser_mail = new DAO_Admin().getMailUser(TB_Correo.Text); try { if (euser_mail.Mail == TB_Correo.Text) { cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('El correo ya existe');</script>"); return; } }catch (NullReferenceException) { } //---------------------------------// if (!(extension.Equals(".jpg") || extension.Equals(".jpeg") || extension.Equals(".png"))) { cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Tipo de archivo no valido o no subio archivo');</script>"); return; } if (System.IO.File.Exists(saveLocation)) { File.Delete(saveLocation); cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Ya existe un archivo en el servidor con ese nombre');</script>"); return; } try { FU_Foto.PostedFile.SaveAs(saveLocation); cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('El archivo ha sido cargado');</script>"); } catch (Exception exc) { cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Error: ');</script>"); return; } try { if (e_user.Profile_pic == " ") { cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('No ha subido ninguna foto');</script>"); return; } } catch (NullReferenceException) { } //---------------------------------// e_user.LastModified = DateTime.Now; e_user.Sesion = ((E_user)Session["validUser"]).User_name; e_user.Pasaporte_numero = 0; //---------------------------------// //Generador de usuario ahora en User/QRCode.aspx.cs e_user.Qr_hash = RNG_Gen.RNG_gen(); Send_Mail mail = new Send_Mail(); mail.sendMail(e_user.Mail, e_user.Token, "Su usuario: " + e_user.User_name, "Su contraseña: " + e_user.Pass, "Bienvenido al programa."); new DAO_Admin().addUser(e_user); cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('El usuario ha sido registrado');</script>"); //-------------------------------// TB_Pass.Text = String.Empty; TB_Nombre.Text = String.Empty; TB_Correo.Text = String.Empty; TB_Apellido.Text = String.Empty; TB_User.Text = String.Empty; }
protected void BT_Enviar_Click(object sender, EventArgs e) { ClientScriptManager cm = this.ClientScript; E_user e_user = new E_user(); e_user.Id_rol = 3; e_user.Name = TB_Nombre.Text; e_user.Last_name = TB_Apellido.Text; e_user.User_name = TB_User.Text; e_user.Pass = TB_Pass.Text; e_user.Mail = TB_Correo.Text; e_user.Id_ruta = int.Parse(DDL_NumRuta.SelectedValue); e_user.Id_driver = int.Parse(DDL_IdeConductor.SelectedValue); //---------------------------------// E_user euser = new DAO_Admin().getUserLogin(TB_User.Text); try { if (euser.User_name == TB_User.Text) { cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('El usuario ya existe');</script>"); return; } } catch (NullReferenceException) { } E_user euser_mail = new DAO_Admin().getMailUser(TB_Correo.Text); try { if (euser_mail.Mail == TB_Correo.Text) { cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('El correo ya existe');</script>"); return; } } catch (NullReferenceException) { } //----------------------------------// e_user.LastModified = DateTime.Now; e_user.Sesion = ((E_user)Session["validUser"]).User_name; //---------------------------------// Send_Mail mail = new Send_Mail(); mail.sendMail(e_user.Mail, e_user.Token, "Su usuario: " + e_user.User_name, "Su contraseña: " + e_user.Pass, "Bienvenido señor conductor al programa."); new DAO_Admin().addUser(e_user); cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('El usuario ha sido registrado');</script>"); //-------------------------------// TB_Pass.Text = String.Empty; TB_Nombre.Text = String.Empty; TB_Correo.Text = String.Empty; TB_Apellido.Text = String.Empty; TB_User.Text = String.Empty; }
public async Task <IActionResult> Mobile(string functionName) { var task = await Task.Run(async() => { dynamic d = null; string clientContentType; string clientAccept; string token = ""; int httpStatusCode = 404; int ResponseCode = -600; string ResponseMessage = "Truy vấn API thất bại"; string Data = ""; string taskReturn; d = GetConfig(); if (d == null) { ResponseCode = -99; ResponseMessage = "Lỗi file config API"; } else { if (d.Https.ToString() == "1" && !Request.IsHttps) { ResponseCode = -600; ResponseMessage = "Hệ thống yêu cầu SSL"; } else { if (Request.Method != "POST") { ResponseCode = -600; ResponseMessage = "Hệ thống yêu cầu phương thức POST"; } else { clientContentType = Request.Headers["Content-Type"]; clientAccept = Request.Headers["Accept"]; if (clientAccept.ToLower() != "application/json") { ResponseCode = -600; ResponseMessage = "Hệ thống yêu cầu Accept: application/json"; } else { if (clientContentType.ToLower() != "application/json") { ResponseCode = -600; ResponseMessage = "Hệ thống yêu cầu Content-Type: application/json"; } else { int i = 0; bool kt = false; while (i < d.config.Count && !kt) { if (d.config[i].clientId.ToString().ToUpper() == ClientID.ToUpper()) { kt = true; } i = i + 1; } if (kt) { i = i - 1; kt = false; string StoreName = ""; int j = 0; dynamic d1 = d.config[i].functionListName; while (j < d1.Count && !kt) { if (d1[j].FunctionName.ToString().ToUpper() == functionName.ToUpper()) { kt = true; } j = j + 1; } if (kt) { dynamic dRequest = null; StreamReader reader = new StreamReader(Request.Body); try { string content = await reader.ReadToEndAsync(); dRequest = JObject.Parse(content); } catch (Exception ex) { dRequest = null; } if (functionName.ToUpper() != "LOGIN") { token = Request.Headers["Authorization"]; if (token == null) { token = ""; } try { // Check token TokenDTO objToken; bool IsValid = TokenHelper.CheckToken(token, out objToken); // Thực hiện call nghiệp vụ với token nhận được if (!IsValid) { ResponseCode = -600; ResponseMessage = "Token không hợp lệ"; } else { // Điều hướng nghiệp vụ switch (functionName.ToLower()) { case "sendmail": string _SMTP = "smtp.gmail.com"; int _Port = 587; bool _IsSSL = true; string _AccountName = "Nguyen Van A"; string _EmailReceipt = "*****@*****.**"; string _AccountUser = "******"; string _AccountPassword = "******"; string[] _EmailTo = { "*****@*****.**" }; string[] _EmailCC = { "*****@*****.**", "*****@*****.**" }; string[] _EmailBCC = { }; string _Subject = "Test mail"; string _Content = "Test content"; string[] _FileList = { }; Send_Mail send_Mail = new Send_Mail(_SMTP, _Port, _IsSSL, _AccountName, _EmailReceipt, _AccountUser, _AccountPassword, _EmailTo, _EmailCC, _EmailBCC, _Subject, _Content, _FileList); bool IsSended = await send_Mail.EmailSendingAsync(); if (IsSended) { ResponseCode = 1; ResponseMessage = string.Format("Gửi email từ API thành công"); Data = ""; httpStatusCode = 200; } else { ResponseCode = -600; ResponseMessage = string.Format("Gửi email từ API thất bại"); Data = ""; } break; default: // Create param store proceduce List <string> arStoreName = new List <string>(); Dictionary <string, object> paramObj = new Dictionary <string, object>(); arStoreName.Add(functionName.ToLower()); arStoreName.Add(StoreName.ToLower()); dynamic d2 = d1[j].ParamIn; for (var l = 0; l < d2.Count; l++) { string a = ""; string b = ""; a = d2[l].LocalName.ToString(); if (dRequest != null) { if (dRequest[d2[l].ParamName.ToString()] != null) { b = dRequest[d2[l].ParamName.ToString()].ToString(); } } // IsHidden = 1 if (d2[l].IsHidden.ToString() == "1") { // Username if ((a.ToUpper() == "P_USERNAME") && (objToken != null)) { b = objToken.Username; } } paramObj.Add(a, b); } d2 = d1[j].ParamOut; for (var l = 0; l < d2.Count; l++) { string a = ""; string b = ""; a = d2[l].LocalName.ToString(); b = d2[l].LocalValue.ToString(); paramObj.Add(a, b); } // Call store with Param break; } ResponseCode = 1; ResponseMessage = string.Format("Truy vấn API thành công"); Data = ""; httpStatusCode = 200; } } catch (Exception ex) { ResponseCode = -600; ResponseMessage = string.Format("Token không hợp lệ: {0}", ex.ToString()); } } else { // Thực hiện call Login if (dRequest == null) { ResponseCode = -600; ResponseMessage = "Hệ thống không nhận được request Data"; } else { try { bool isValid; switch (int.Parse(dRequest.Provider.ToString())) { case 2: // Login Email string smtp = "mail.abc.com"; int port = 587; string Email = dRequest.UserName.ToString(); string UserPassword = dRequest.Password.ToString(); isValid = await Utils.EmailValidateAsync(smtp, port, Email, UserPassword); break; case 3: // Login LDAP Email = dRequest.UserName.ToString(); UserPassword = dRequest.Password.ToString(); string LdapURL = "LDAP://abc.com"; string LDAPDomain = "abc.com"; string LDAPBaseDN = "//ldap://abc.com/path"; LDAP m = new LDAP(LdapURL, LDAPDomain, LDAPBaseDN, 0, Email, UserPassword); // 0 - ContextType.Machine isValid = await m.ValidateUserAsync(); break; default: // Login bang store proceduce // Create param store proceduce List <string> arStoreName = new List <string>(); Dictionary <string, object> paramObj = new Dictionary <string, object>(); arStoreName.Add(functionName.ToLower()); arStoreName.Add(StoreName.ToLower()); dynamic d2 = d1[j].ParamIn; for (var l = 0; l < d2.Count; l++) { string a = ""; string b = ""; a = d2[l].LocalName.ToString(); if (dRequest != null) { if (dRequest[d2[l].ParamName.ToString()] != null) { b = dRequest[d2[l].ParamName.ToString()].ToString(); } } // Encrypt Password //if(a.ToUpper == "P_PASSWORD") //{ // using (encry = new EncryptData) // { // b = encry.EncryptString(b) // } //} paramObj.Add(a, b); } d2 = d1[j].ParamOut; for (var l = 0; l < d2.Count; l++) { string a = ""; string b = ""; a = d2[l].LocalName.ToString(); b = d2[l].LocalValue.ToString(); paramObj.Add(a, b); } // Call store with Param isValid = true; break; } if (!isValid) { ResponseCode = -600; ResponseMessage = "Login không thành công"; httpStatusCode = 200; } else { ResponseCode = 1; ResponseMessage = "Login thành công"; httpStatusCode = 200; token = TokenHelper.GenerateToken(dRequest["DeviceID"].ToString(), dRequest["UserName"].ToString()); Data = string.Format(",\"Token\":\"{0}\"", token); } } catch (Exception ex) { ResponseCode = -600; ResponseMessage = string.Format("Login không thành công {0}", ex.ToString()); } } } } else { ResponseCode = -600; ResponseMessage = "Hệ thống không tìm được nghiệp vụ: " + functionName; } } else { ResponseCode = -600; ResponseMessage = "Hệ thống không tìm được ClientID"; } } } } } } Utils.WriteLogAsync(string.Format("ResponseCode: {0}, ResponseMessage: {1}", ResponseCode, ResponseMessage)); taskReturn = httpStatusCode.ToString() + "^{\"Status\": " + ResponseCode + ", \"Message\": \"" + ResponseMessage + "\"" + Data + "}"; return(taskReturn); }); string[] a = task.Split(new string[] { "^" }, StringSplitOptions.None); int _StatusCode = int.Parse(a[0]); dynamic r = JObject.Parse(a[1]); if (_StatusCode == 200) { //return Json(a[1]); return(new ContentResult { Content = a[1], ContentType = "application/json" }); } else { return(StatusCode(_StatusCode)); } }
private void SendEmail(string To, string Name, Send_Mail SM) { try { ProAccEntities db = new ProAccEntities(); MailMessage msg = new MailMessage(); if (SM.Q_UserID > 0) { //To = "*****@*****.**"; //Name = "Akhil"; SM.priority = true; string Toaddresses = Mail_ToAddress; string CCAddress = Mail_CCAddress; foreach (var address in Toaddresses.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { msg.To.Add(address); } foreach (var CCAdd in CCAddress.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { msg.CC.Add(CCAdd); } } else if (SM.subject == "IssueTrack") { MailAddress toAddress = new MailAddress(To, Name); msg.To.Add(toAddress); var RoleId = db.RoleMasters.Where(x => x.RoleName == "Project Manager").FirstOrDefault().RoleId; var managerid = (from PM in db.ProjectMonitors join I in db.Instances on PM.InstanceID equals I.Instance_id join P in db.Projects on I.Project_ID equals P.Project_Id select P.ProjectManager_Id).FirstOrDefault(); var cc = db.UserMasters.Where(x => x.isActive == true && x.RoleID == RoleId && x.UserId == managerid).FirstOrDefault().EMail; msg.CC.Add(cc); string CCAddress = Mail_CCAddress; foreach (var CCAdd in CCAddress.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { msg.CC.Add(CCAdd); } } else if (SM.subject == "ProAcc Survey Mail") { MailAddress toAddress = new MailAddress(To, Name); msg.To.Add(toAddress); string CCAddress = Mail_CCAddress; foreach (var CCAdd in CCAddress.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { msg.CC.Add(CCAdd); } } else { MailAddress toAddress = new MailAddress(To, Name); msg.To.Add(toAddress); } MailAddress fromAddress = new MailAddress(_Base.Decrypt(WebConfigurationManager.AppSettings["Mail_UserName"])); msg.From = fromAddress; msg.Subject = SM.subject; msg.Body = SM.body; msg.IsBodyHtml = true; msg.HeadersEncoding = Encoding.UTF8; msg.SubjectEncoding = Encoding.UTF8; msg.BodyEncoding = Encoding.UTF8; if (SM.priority) { msg.Priority = MailPriority.High; } if (SM.Q_UserID > 0) { var fs = new FileStream(OutputPath_pdf + SM.Q_UserID + ".pdf", FileMode.Open); msg.Attachments.Add(new System.Net.Mail.Attachment(fs, "Questionnaire.pdf", "application/pdf")); } //Thread.Sleep(1000); SmtpClient client = new SmtpClient(serverName, port); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; //Convert.ToBoolean(WebConfigurationManager.AppSettings["SmtpSsl"]); client.UseDefaultCredentials = false; NetworkCredential smtpUserInfo = new NetworkCredential(_Base.Decrypt(userName), _Base.Decrypt(password)); client.Credentials = smtpUserInfo; // ProAccEntities db = new ProAccEntities(); client.Credentials = smtpUserInfo; var mm = db.MailMasters.Where(x => x.Running_ID == SM.ID).FirstOrDefault().MailStatus; if (mm == false) { client.Send(msg); _Log.createLog(SM.ID + "---> Email To->" + To.ToString()); _Base.UpdateMailList(SM.ID); } client.Dispose(); msg.Dispose(); } catch (Exception ex) { _Log.createLog(ex, "-->SendEmail" + ex.Message.ToString()); } }
public void Send(string To, string Name, Send_Mail SM) { Task.Factory.StartNew(() => SendEmail(To, Name, SM), TaskCreationOptions.LongRunning); }