public JsonResult SendACLRejectionNotification(string compID, string requester, string quoteQN, string quoteID, string rejectReason) { string result = null; ComponentFindDTO param = new ComponentFindDTO(); param.id = Convert.ToInt32(compID); var comp_data = UnitOfWork.TblComp.Get(Convert.ToInt32(compID)); var formattedRejectReason = rejectReason.Replace("\n", Environment.NewLine); var emailDTO = new { compID = compID, comp_data = comp_data, quoteQN = quoteQN, quoteID = quoteID, rejectReason = formattedRejectReason }; string aclApproverList = GetUsersInRole("9"); try { try { var email = new EmailController(); var message = new EmailModels(); message.To = requester; message.CC = aclApproverList; message.Subject = string.Format("ACL request rejected for Vendor Part Number {0}", comp_data.comp_vend_pn); Task.Run(() => email.Send(message, null, emailDTO, "componentACLRejectionNotification.html")); } catch (Exception ex) { _logger.Error(string.Format("Email Send Error: {0}", ex.ToString())); } } catch (Exception ex) { _logger.Error(ex); result = null; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult RequestACLApproval(string quoteQN, string quoteID, string requestReason, ComponentCreateDTO modal) { ComponentCreateDTO result = null; var requestUser = User.Identity.Name; var emailDTO = new { compDTO = modal, requestUser = requestUser, quoteQN = quoteQN, quoteID = quoteID, requestReason = requestReason }; string aclApproverList = GetUsersInRole("9"); try { try { var email = new EmailController(); var message = new EmailModels(); message.To = aclApproverList; message.Subject = string.Format("ACL Approval Request Component {0}", modal.id); Task.Run(() => email.Send(message, null, emailDTO, "componentACLApprovalRequest.html")); } catch (Exception ex) { _logger.Error(string.Format("Email Send Error: {0}", ex.ToString())); } } catch (Exception ex) { _logger.Error(ex); result = null; } return(Json(result, JsonRequestBehavior.AllowGet)); }
}// End #endregion /// <summary> /// desc: update the gatepass status to approved and return slip to not returned /// by: [email protected] /// date: january 23, 2017 /// </summary> /// <returns></returns> #region GuardApproved public JsonResult GuardApproved() { try { string headercode = Request["Id"].ToString(); string returndate = Request["returndate"].ToString(); ViewBag.headercodeOwnerId = guardModel.GetOwnerofHeader(headercode); string[] headercodeOwnerEmail = { guardModel.GetOwnerofHeaderEmail(ViewBag.headercodeOwnerId) }; string[] accountingEmail = { guardModel.GetAccountingEmail(headercode), ConfigurationManager.AppSettings["ampiguard_email"] }; string comment = ""; int guardIdLocal = Convert.ToInt32(Session["userId_local"]); string guardRights = Session["Department"].ToString(); string guradCode = Session["user_code"].ToString(); string guradname = Session["cn"].ToString(); string guardDateAdded = DateTime.Now.ToString(); bool guardIsApproved = true; guardModel.GatePassApproved(headercode, comment, guardIdLocal, guardRights, guradCode, guradname, guardDateAdded, guardIsApproved, returndate); // used for audit trail purposes auditObj.ProjectCode = "GAT"; // jira story name auditObj.Module = "GUARD"; // module transacted auditObj.Operation = "Approve"; //action inside the module auditObj.Object = "tblTransactionHeaders"; // table name transacted auditObj.ObjectId = Convert.ToInt32(Request["IdNumber"]); auditObj.ObjectCode = Request["Id"].ToString(); auditObj.UserCode = Convert.ToInt32(Session["userId_local"]); auditObj.IP = CustomHelper.GetLocalIPAddress(); auditObj.MAC = CustomHelper.GetMACAddress(); auditObj.DateAdded = DateTime.Now; auditModels.AddAuditTrail(auditObj); var emailMod = new EmailModels(); string emailContent = EmailContent(headercode); if (!SendEmailApprovedByGuard(emailContent, headercodeOwnerEmail, accountingEmail, headercode)) { throw new Exception(message: "Email not sent."); } response.Add(key: "success", value: true); response.Add(key: "error", value: false); response.Add(key: "message", value: " "); } catch (Exception e) { response.Add(key: "success", value: false); response.Add(key: "error", value: true); response.Add(key: "message", value: e.ToString()); } return(Json(response, JsonRequestBehavior.AllowGet)); }// End
public HttpResponseMessage SaveInvitation(int SID, int UID, string ITitle, string IImage, string Description, int Privacy) { string Status = string.Empty; EmailModels emailModelsList = new EmailModels(); emailModelsList.SchoolID = SID; emailModelsList.PostedBy = UID; emailModelsList.InvitationTitle = ITitle; emailModelsList.InvitationImage = IImage; emailModelsList.Description = Description; emailModelsList.Privacy = Privacy; Status = emailModelsList.SaveInvitations(); return(Request.CreateResponse(HttpStatusCode.OK, Status)); }
public HttpResponseMessage SaveMail(int SID, int UID, string Subject, string Message, string TO_list_ID, string CC_list_ID) { string Status = string.Empty; EmailModels emailModelsList = new EmailModels(); emailModelsList.SchoolID = SID; emailModelsList.UID = UID; emailModelsList.Subject = Subject; emailModelsList.Body = Message; emailModelsList.TO_list_ID = TO_list_ID; emailModelsList.CC_list_ID = CC_list_ID; Status = emailModelsList.InsertEmail(); return(Request.CreateResponse(HttpStatusCode.OK, Status)); }
public List <EmailModels> GetInvitationList(int SID, int UType) { List <EmailModels> emailModelsList = new List <EmailModels>(); EmailModels emailModels = new EmailModels(); if (!string.IsNullOrEmpty(Convert.ToString(SID)) && !string.IsNullOrEmpty(Convert.ToString(UType))) { DataTable dtInvitaionList = new DataTable(); dtInvitaionList = emailModels.getInvitations(SID, UType); if (dtInvitaionList.Rows.Count > 0) { foreach (DataRow dr in dtInvitaionList.Rows) { EmailModels emailModelsTypes = new EmailModels(); emailModelsTypes.InvitationID = Convert.ToInt32(dr["id"]); emailModelsTypes.SchoolID = Convert.ToInt32(dr["exam_id"]); emailModelsTypes.InvitationTitle = Convert.ToString(dr["invitation_title"]); if (!string.IsNullOrEmpty(Convert.ToString(dr["invitation_image"]))) { emailModelsTypes.InvitationImage = Convert.ToString(dr["invitation_image"]); } emailModelsTypes.Description = Convert.ToString(dr["description"]); emailModelsTypes.Privacy = Convert.ToInt32(dr["privacy"]); emailModelsTypes.PostedBy = Convert.ToInt32(dr["posted_by"]); emailModelsTypes.PostedOn = Convert.ToDateTime(dr["posted_on"]); emailModelsTypes.PostedTime = Convert.ToString(dr["posted_time"]); if (!string.IsNullOrEmpty(Convert.ToString(dr["first_name"]))) { emailModelsTypes.FirstName = Convert.ToString(dr["first_name"]); } if (!string.IsNullOrEmpty(Convert.ToString(dr["last_name"]))) { emailModelsTypes.LastName = Convert.ToString(dr["last_name"]).ToString().Trim(); } if (!string.IsNullOrEmpty(Convert.ToString(dr["profile_picture"]))) { emailModelsTypes.ProfilePicture = Convert.ToString(dr["profile_picture"]); } emailModelsList.Add(emailModelsTypes); } } } return(emailModelsList); }
public List <EmailModels> GetEmailNotificationList(int SchoolID, int UID, int Type) { List <EmailModels> emailModelsList = new List <EmailModels>(); EmailModels emailModels = new EmailModels(); if (!string.IsNullOrEmpty(Convert.ToString(SchoolID)) && !string.IsNullOrEmpty(Convert.ToString(UID))) { DataTable dtEmailList = new DataTable(); dtEmailList = emailModels.getEmailList(SchoolID, UID, Type); if (dtEmailList.Rows.Count > 0) { foreach (DataRow dr in dtEmailList.Rows) { EmailModels emailModelsTypes = new EmailModels(); emailModelsTypes.ID = Convert.ToInt32(dr["id"]); emailModelsTypes.SchoolID = Convert.ToInt32(dr["exam_id"]); emailModelsTypes.MessageBoxID = Convert.ToInt32(dr["message_box_id"]); emailModelsTypes.SentBy = Convert.ToInt32(dr["send_by"]); emailModelsTypes.SentByName = Convert.ToString(dr["send_by_name"]); emailModelsTypes.SentTo = Convert.ToInt32(dr["sent_to"]); if (!string.IsNullOrEmpty(Convert.ToString(dr["subject"]).ToString().Trim())) { emailModelsTypes.Subject = Convert.ToString(dr["subject"]).ToString().Trim(); } if (!string.IsNullOrEmpty(Convert.ToString(dr["body"]).ToString().Trim())) { emailModelsTypes.Body = Convert.ToString(dr["body"]).ToString().Trim(); } emailModelsTypes.MoveTo = Convert.ToInt32(dr["move_to"]); emailModelsTypes.FolderName = Convert.ToString(dr["folder_name"]).ToString().Trim(); emailModelsTypes.IsFavorite = Convert.ToBoolean(dr["isfavorite"]); emailModelsTypes.SendDate = Convert.ToDateTime(dr["send_date"]); emailModelsTypes.SendTime = Convert.ToString(dr["send_time"]).ToString().Trim(); emailModelsTypes.ReadContent = Convert.ToBoolean(dr["read_content"]); emailModelsTypes.Deleted = Convert.ToBoolean(dr["deleted"]); emailModelsList.Add(emailModelsTypes); } } } return(emailModelsList); }
public async Task <ActionResult> Contact(EmailModels model) { if (ModelState.IsValid) { try { var body = "<p>Email From: <bold>{0}</bold> ({1})</p><p>Message:</p><p>{2}</p>"; var from = "MyPortfolio<*****@*****.**>"; model.Body = "This is a message from your Portfolio site. The name and the email of the contacting person is above."; var email = new MailMessage(from, ConfigurationManager.AppSettings["emailto"]) { Subject = "Portfolio Contact Email", Body = string.Format(body, model.FromName, model.FromEmail, model.Body), IsBodyHtml = true }; var svc = new PersonalEmail(); await svc.SendAsync(email); return(RedirectToAction("Index")); } catch (Exception ex) { Console.WriteLine(ex.Message); await Task.FromResult(0); } } return(RedirectToAction("Index")); }
public async Task <ActionResult> Send(EmailModels mail, HttpPostedFileBase fileUploader = null, object modal = null, string email_template = null) { //NOTES: You can call this in the example below. (This example is in the QuoteMasterController.cs) // //var email = new EmailController(); //var message = new EmailModels(); //message.To = dto.tbl_rep.rep_email; //message.Subject = string.Format("Quote {0} has been confirmed", dto.qthdr_qn_basis + "-" + dto.qthdr_rev); //Task.Run(() => email.Send(message, null, dto, "quoteConfirmRepEmail.html")); // //You can also call this without sending models //message.Body = "some body string"; //Task.Run(() => email.Send(message)); _logger.Debug(string.Format("Start Send Email")); if (ModelState.IsValid) { var message = new MailMessage(); try { if (mail.To.ToString() != null) { foreach (string to in mail.To.ToString().Split(';')) { if (!string.IsNullOrEmpty(to)) { message.To.Add(new MailAddress(to)); _logger.Debug(string.Format("Sending Email to {0}", to)); } } } } catch (Exception ex) { _logger.Error("Either no To set or error setting To"); } try { if (mail.CC.ToString() != null) { foreach (string cc in mail.CC.ToString().Split(';')) { if (!string.IsNullOrEmpty(cc)) { message.CC.Add(new MailAddress(cc)); _logger.Debug(string.Format("Sending Email CC to {0}", cc)); } } } } catch (Exception ex) { _logger.Error("Either no CC set or error setting CC"); } message.Subject = mail.Subject; string template = ""; string templatefile = ""; string templatePath = "~/Content/Templates/"; string body = ""; string siteURL = System.Configuration.ConfigurationManager.AppSettings["SiteURL"]; if (email_template == null) { body = mail.Body; } else { try { template = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath(templatePath + email_template)); } catch (Exception) { string currentfolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); templatefile = currentfolder + "\\Content\\templates\\" + email_template; template = System.IO.File.ReadAllText(templatefile); } try { object templateModal = new object(); var viewBag = new DynamicViewBag(); viewBag.AddValue("SiteURL", siteURL); if (modal == null) { templateModal = mail; } else { templateModal = modal; } if (Engine.Razor.IsTemplateCached(email_template, null)) { body = Engine.Razor.Run(email_template, null, modal, viewBag); } else { body = Engine.Razor.RunCompile(template, email_template, null, modal, viewBag); } } catch (Exception ex) { _logger.Error(string.Format("Error Sending Email: {0}", ex.ToString())); body = ex.ToString(); } } message.Body = body; message.IsBodyHtml = true; if (mail.Attachment != null && mail.Attachment.ContentLength > 0) { message.Attachments.Add(new Attachment(mail.Attachment.InputStream, Path.GetFileName(mail.Attachment.FileName))); } using (var smtp = new SmtpClient()) { try { await smtp.SendMailAsync(message); return(RedirectToAction("Sent")); } catch (Exception ex) { _logger.Error(string.Format("Error Sending Email: {0}", ex.ToString())); return(RedirectToAction("Error")); } } } return(View(mail)); }
// GET: EmailTemplates/Email public ActionResult RegistrationEmail() { model = (EmailModels)ViewData.Model; return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { using (var context = new ApplicationDbContext()) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, BirthDate = model.BirthDate, FirstName = model.FirstName, LastName = model.LastName, DateCreated = DateTime.UtcNow, DateModified = DateTime.UtcNow }; var result = await UserManager.CreateAsync(user, model.Password); user.Email = model.Email; user.EmailConfirmed = false; var roleStore = new RoleStore <IdentityRole>(context); var roleManager = new RoleManager <IdentityRole>(roleStore); var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); userManager.AddToRole(user.Id, model.Roles); if (result.Succeeded) { // await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); var subjEmail = new EmailModels() { Admin = User.Identity.Name, UserName = user.UserName, Role = model.Roles, Link = callbackUrl, Password = model.Password }; var emailBody = RenderViewToString("RegistrationEmail", subjEmail); SendEmail(user.Email, "New registration", emailBody); TempData["ResultSuccess"] = String.Format("Successfully added user with role: {1}! Confirmation email is sent to the email: {0} .", user.Email, model.Roles); return(RedirectToAction("Register", "Account")); } AddErrors(result); } model.lsRoles = new SelectList(context.Roles.ToList(), "Name", "Name"); TempData["ResultError"] = "Error in adding administrator!"; // If we got this far, something failed, redisplay form return(View(model)); } }
public void EmailContactoComercial(string Comentario) { int IdUsuario = Convert.ToInt32(Session["PerfilInterior"]); EmailModels.EmailContactoComercial(IdUsuario, Comentario); }
}//End /// <summary> /// desc: update the item quantity by partial return /// by: [email protected] /// date: january 16, 2017 /// </summary> /// <returns></returns> /// /// <summary> /// desc: adding of headercode/gate pass number parameter to display on email notification /// by: [email protected] /// date: june 5, 2017 /// version : 2.0 /// </summary> /// <returns></returns> #region PartialReturnQuantity public JsonResult PartialReturnQuantity() { try { var res = new Dictionary <string, object>(); string[] itemCodeArr = Request["ItemCode"].ToString().Split(separator: new char[] { ',' }); string[] itemQuantityArr = Request["PartialQuantity"].ToString().Split(separator: new char[] { ',' }); string[] itemGuidArr = Request["ItemGUID_Arr"].ToString().Split(separator: new char[] { ',' }); for (int i = 0; i < itemCodeArr.Length; i++) { string itemCode = itemCodeArr[i]; string itemQuantity = itemQuantityArr[i]; string itemGuid = itemGuidArr[i]; itemReturnLogsDetails.HeaderCode = Request["HeaderCode"].ToString(); itemReturnLogsDetails.ItemCode = itemCode.ToString(); itemReturnLogsDetails.Quantity = Convert.ToInt32(itemQuantity); itemReturnLogsDetails.IsActive = true; itemReturnLogsDetails.AddedBy = Convert.ToInt32(Session["userId_local"]); itemReturnLogsDetails.DateAdded = DateTime.Now; itemReturnLogsDetails.Remarks = Request["PartialReturnComment"].ToString(); itemReturnLogsDetails.GUID = itemGuid.ToString(); guardModel.PartialReturn_Qty(itemReturnLogsDetails); } ViewBag.headercodeOwnerId = guardModel.GetOwnerofHeader(itemReturnLogsDetails.HeaderCode); ViewBag.departmentcodeapprover = guardModel.GetDepartmentCodebaseOnHeader(itemReturnLogsDetails.HeaderCode); string[] headercodeOwnerEmail = { guardModel.GetOwnerofHeaderEmail(ViewBag.headercodeOwnerId), ConfigurationManager.AppSettings["ampiguard_email"] }; string[] accountingEmail = { guardModel.GetAccountingEmailReturnSlip(itemReturnLogsDetails.HeaderCode), guardModel.GetDepartmentEmailReturnSlip(ViewBag.departmentcodeapprover) }; int getHeaderCodeId = guardModel.getHeaderCodeId(Request["HeaderCode"].ToString()); // used for audit trail purpose auditObj.ProjectCode = "GAT"; // jira story name auditObj.Module = "GUARD"; // module name transacted auditObj.Operation = "Return"; // action inside the module auditObj.Object = "tblTransactionHeaders"; // table name transacted auditObj.ObjectId = getHeaderCodeId; auditObj.ObjectCode = Request["HeaderCode"].ToString(); auditObj.UserCode = Convert.ToInt32(Session["userId_local"]); auditObj.IP = CustomHelper.GetLocalIPAddress(); auditObj.MAC = CustomHelper.GetMACAddress(); auditObj.DateAdded = DateTime.Now; auditModels.AddAuditTrail(auditObj); var emailMod = new EmailModels(); string emailContent = EmailContentReturnSlip(itemReturnLogsDetails.HeaderCode, itemReturnLogsDetails.Remarks); if (!SendEmailReturnSlipByGuard(emailContent, headercodeOwnerEmail, accountingEmail, itemReturnLogsDetails.HeaderCode)) { throw new Exception(message: "Email not sent."); } response.Add(key: "success", value: true); response.Add(key: "error", value: false); response.Add(key: "message", value: " "); } catch (Exception e) { response.Add(key: "success", value: false); response.Add(key: "error", value: true); response.Add(key: "message", value: e.ToString()); } return(Json(response, JsonRequestBehavior.AllowGet)); }// End
public ActionResult List_email(FormCollection collection, int?email_id, string type, string act, string ctrl, string type_act, int?page, int?page_size) { EmailModels emailModel = new EmailModels(); EmailTemplateModels emailTemplateModels = new EmailTemplateModels(); var list_email = new Web.Areas.Admin.ViewModels.List_email_view(); this.TryUpdateModel(list_email); List <SelectListItem> list_select_tempate = new List <SelectListItem>(); emailTemplateModels.List_email_template(0, ref list_select_tempate); StringBuilder sb = new StringBuilder(); int total_record = 0; if (string.IsNullOrEmpty(type)) { type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.RoleAdmin; } if (string.IsNullOrEmpty(act)) { act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "list_email"; } if (string.IsNullOrEmpty(ctrl)) { ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "dminEmail"; } if (page == null || page == 0) { page = Request.QueryString["page"] != null?Convert.ToInt32(Request.QueryString["page"].ToString()) : 1; } if (page_size == null) { page_size = int.Parse(Util.GetConfigValue("NumberPageSizeAdmin", "30")); } string email_address = collection["email_address"].ToString(); if (email_id > 0 && type_act != null && type_act == CommonGlobal.Delete) { if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, act, ctrl, type_act, type)) { bool rt = emailModel.Delete((int)email_id); if (rt) { list_email.Message = "Bạn đã xóa email: " + email_address; } else { list_email.Message = "Xóa không thành công"; } } } int totalRecord = 0; if (!string.IsNullOrEmpty(collection["total_record_on_page"])) { totalRecord = int.Parse(collection["total_record_on_page"]); } string subject = collection["emailSubject"]; string body = collection["emailBody"]; bool flag_SendMail = false; if (list_email.IsSendAll) { list_email.IsSendAll = true; list_email.IsSendAllText = "checked='checked'"; List <C_Email> lstEmailSend = emailModel.AllEmail(); if (lstEmailSend.Any()) { foreach (C_Email objEmail in lstEmailSend) { CommonGlobal.SendMail(objEmail.email, subject, body); } flag_SendMail = true; } } else { list_email.IsSendAll = false; list_email.IsSendAllText = string.Empty; for (int i = 1; i <= totalRecord; ++i) { string email = string.Empty; string chkBox = collection["chk_" + i]; if (!string.IsNullOrEmpty(chkBox)) { if (chkBox.Contains("true")) { email = collection["email_" + i]; CommonGlobal.SendMail(email, subject, body); flag_SendMail = true; } } } } if (flag_SendMail) { ////Message list_email.Message = "Đã gửi mail thành công."; } //////tab sb.Append("<li class=\"active\"><a href=\"#\"><span>Email Marketing</span></a></li>"); list_email.Html_link_tab = sb.ToString(); //////list post PagedList <C_Email> lstEmail = emailModel.GetListEmail((int)page, (int)page_size, out total_record); list_email.ListEmail = lstEmail; list_email.Total_record = total_record; list_email.Total_record_on_page = lstEmail.Count(); list_email.Type_act = type_act; list_email.ListTemplate = list_select_tempate; //////action list_email.Act = act; list_email.Ctrl = ctrl; list_email.SubjectEmail = subject; list_email.BodyEmail = body; list_email.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); list_email.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); //////end action return(this.PartialView("../control/list_email", list_email)); }
public ActionResult List_email(string type, string act, string ctrl, string type_act, int?page, int?page_size) { EmailModels emailModel = new EmailModels(); EmailTemplateModels emailTemplateModels = new EmailTemplateModels(); var list_email = new Web.Areas.Admin.ViewModels.List_email_view(); List <SelectListItem> list_select_template = new List <SelectListItem>(); emailTemplateModels.List_email_template(0, ref list_select_template); StringBuilder sb = new StringBuilder(); int total_record = 0; if (string.IsNullOrEmpty(type)) { type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.RoleAdmin; } if (string.IsNullOrEmpty(act)) { act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "list_email"; } if (string.IsNullOrEmpty(ctrl)) { ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "dminEmail"; } if (page == null || page == 0) { page = Request.QueryString["page"] != null?Convert.ToInt32(Request.QueryString["page"].ToString()) : 1; } if (page_size == null) { page_size = int.Parse(Util.GetConfigValue("NumberPageSizeAdmin", "30")); } list_email.Page = (int)page; list_email.Page_size = (int)page_size; ////tab sb.Append("<li class=\"active\"><a href=\"#\"><span>Email Marketing</span></a></li>"); list_email.Html_link_tab = sb.ToString(); ////list post PagedList <C_Email> lstEmail = emailModel.GetListEmail((int)page, (int)page_size, out total_record); list_email.ListPageSize = this.GetSizePagingPublic((int)page_size); list_email.ListEmail = lstEmail; list_email.Total_record = total_record; list_email.Total_record_on_page = lstEmail.Count(); list_email.Type_act = type_act; list_email.ListTemplate = list_select_template; ////action list_email.Act = act; list_email.Ctrl = ctrl; list_email.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); list_email.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); ////end action return(this.PartialView("../control/list_email", list_email)); }
/// <summary> /// Exports the email. /// </summary> /// <param name="act">The act.</param> /// <param name="ctrl">The control.</param> /// <param name="type_act">The type act.</param> /// <returns> /// export email /// </returns> public ActionResult Export_email(string act, string ctrl, string type_act) { EmailModels emailModels = new EmailModels(); StringBuilder sb = new StringBuilder(); var list_email_view = new Web.Areas.Admin.ViewModels.List_email_view(); string file_name = string.Empty; if (string.IsNullOrEmpty(act)) { act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "list_order"; } if (string.IsNullOrEmpty(ctrl)) { ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "adminOrder"; } var ms = new MemoryStream(); Document document = new Document(PageSize.A4, 40, 40, 40, 40); ////PagedList<order> arrAll = orderModels.getAllOrderByAdmin((DateTime)from_date, (DateTime)to_date, Payment, (int)Process, search, (int)page, (int)page_size, order_by, order_type, out total_record); List <C_Email> lstEmail = emailModels.AllEmail(); Response.Buffer = true; Response.Clear(); ////export to excel Response.AddHeader("Content-Disposition", "attachment; filename=Danh_sach_email_" + DateTime.Now.ToString("yyyyMMdd") + ".xls"); Response.ContentType = "application/ms-excel"; file_name = "Danh_sach_email_" + DateTime.Now.ToString("yyyyMMdd") + ".xls"; Response.Charset = string.Empty; Response.ContentEncoding = Encoding.Unicode; Response.BinaryWrite(Encoding.Unicode.GetPreamble()); sb.Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"padding:0px;margin:0px;width:27.7cm\" >"); sb.Append("<tr>"); sb.Append("<td colspan=\"5\" style=\"text-align:left;font-weight:bold;padding-bottom:10px;\">"); sb.Append(Util.GetConfigValue("Domain", Request.UserHostAddress)); sb.Append("</td>"); sb.Append("</tr>"); sb.Append("<tr>"); sb.Append("<td colspan=\"5\" style=\"text-align:center;text-transform: uppercase;font-weight:bold;\" >Danh sách đăng ký</td>"); sb.Append("</tr>"); sb.Append("<tr style=\"background:#555555;color:#FFFFFF;font-weight: bold\">"); sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;border-top:1px dotted #ccc;border-left:1px dotted #ccc;text-align:center;width:80px;\">STT<br/></td>"); sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;border-top:1px dotted #ccc;width:100px;\">" + App_GlobalResources.Lang.strName + "</td>"); sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;border-top:1px dotted #ccc;width:100px;\">" + App_GlobalResources.Lang.strPhone + "</td>"); sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;border-top:1px dotted #ccc;width:100px;\">Email</td>"); sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;border-top:1px dotted #ccc;width:100px;\">" + App_GlobalResources.Lang.strAddress + "</td>"); sb.Append("</tr>"); int i = 0; foreach (C_Email objEmail in lstEmail) { i++; sb.Append("<tr>"); sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;border-left:1px dotted #ccc;\">" + i + "</td>"); sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;\">" + objEmail.name + "</td>"); sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;\">" + objEmail.phone + "</td>"); sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;\">" + objEmail.email + "</td>"); sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;\">" + objEmail.address + "</td>"); sb.Append("</tr>"); } string test = sb.ToString(); sb.Append("<tr><td colspan=\"5\" style=\"text-transform:uppercase;padding-top:20px;padding-left:20px;text-align:left;\">Nhân viên thống kê</td></tr>"); sb.Append("<tr><td colspan=\"5\" style=\"text-transform:uppercase;padding-top:-20px;position: relative;text-align:right;padding-right:20px;\">" + this.Session["mem"] + "</td></tr>"); sb.Append("</table>"); Response.Write(sb.ToString()); Response.End(); return(this.Json("ok")); }