public ActionResult Change_emailtemplate(int?id, string type, string act, string ctrl, string type_act, string lang) { EmailTemplateModels emailTemplateModels = new EmailTemplateModels(); C_EmailTemplate objEmailTemplate = new C_EmailTemplate(); var email_template_view = new Web.Areas.Admin.ViewModels.Email_template_view(); StringBuilder sb = new StringBuilder(); if (string.IsNullOrEmpty(type)) { type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.CateNews; } if (string.IsNullOrEmpty(act)) { act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "change_post"; } if (string.IsNullOrEmpty(ctrl)) { ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "adminPost"; } if (id == null) { id = RouteData.Values["id"] != null?Convert.ToInt32(RouteData.Values["id"].ToString()) : 0; } if (string.IsNullOrEmpty(lang)) { lang = LanguageModels.ActiveLanguage().LangCultureName; } if (string.IsNullOrEmpty(type_act)) { type_act = Request.QueryString["type_act"] != null ? Request.QueryString["type_act"].ToString() : CommonGlobal.Add; if (id == 0) { type_act = CommonGlobal.Add; } else { type_act = CommonGlobal.Edit; } } if (type_act == CommonGlobal.Edit) { objEmailTemplate = emailTemplateModels.GetEmailTemplateById((int)id); email_template_view.Id = objEmailTemplate.id; email_template_view.Name = objEmailTemplate.name; email_template_view.Template = objEmailTemplate.template; ////Link tab sb.Append("<li><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_emailtemplate", ctrl = "adminEmail", page = "1" }) + "\"><span><span>Danh sách email template</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Cập nhật</span></span></a></li>"); } else { ////Link tab sb.Append("<li><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_emailtemplate", ctrl = "adminEmail", page = "1", lang = lang }) + "\"><span><span>Danh sách email template</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm mới</span></span></a></li>"); } email_template_view.Type = type; email_template_view.Type_act = type_act; email_template_view.Html_link_tab = sb.ToString(); ////action email_template_view.Act = act; email_template_view.Ctrl = ctrl; email_template_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); email_template_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); ////end action return(this.PartialView("../control/change_emailtemplate", email_template_view)); }
public ActionResult Change_emailtemplate(FormCollection collection) { EmailTemplateModels emailTemplateModels = new EmailTemplateModels(); C_EmailTemplate objEmailTemplate = new C_EmailTemplate(); StringBuilder sb = new StringBuilder(); int rt = 0; bool is_valid = true; var email_template_view = new Web.Areas.Admin.ViewModels.Email_template_view(); this.TryUpdateModel(email_template_view); if (email_template_view.Id > 0) { objEmailTemplate = emailTemplateModels.GetEmailTemplateById(email_template_view.Id); } ////validation server if (string.IsNullOrEmpty(email_template_view.Name)) { is_valid = false; email_template_view.Message = "Bạn cần nhập tên email template"; } ////validation server if (string.IsNullOrEmpty(email_template_view.Template)) { is_valid = false; email_template_view.Message = "Bạn cần nhập nội dung email"; } ////action ////post_view.act = "change_post"; ////post_view.ctrl = "adminPost"; email_template_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); email_template_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); if (email_template_view.Id != 0 && email_template_view.Type_act == CommonGlobal.Edit) { ////Link tab sb.Append("<li><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_emailtemplate", ctrl = "adminEmail", type = email_template_view.Type, page = "1" }) + "\"><span>Danh sách email template</span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Cập nhật</span></span></a></li>"); } else { ////Link tab sb.Append("<li><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_emailtemplate", ctrl = "adminEmail", type = email_template_view.Type, page = "1" }) + "\"><span>Danh sách email template</span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm mới</span></span></a></li>"); } email_template_view.Html_link_tab = sb.ToString(); if (!is_valid) { return(this.PartialView("../control/change_emailtemplate", email_template_view)); } ////Post info objEmailTemplate.name = email_template_view.Name; objEmailTemplate.template = email_template_view.Template; if (email_template_view.Id != 0 && email_template_view.Type_act == CommonGlobal.Edit) { rt = emailTemplateModels.Edit(objEmailTemplate); } else { objEmailTemplate.createdate = DateTime.Now; rt = emailTemplateModels.Add(objEmailTemplate); } if (rt > 0) { email_template_view.Message = "Cập nhật thành công!"; email_template_view.Id = rt; email_template_view.Type_act = CommonGlobal.Edit; } else { email_template_view.Message = "Cập nhật không thành công!"; } return(this.PartialView("../control/change_emailtemplate", email_template_view)); }