Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        /// <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"));
        }