示例#1
0
        public ActionResult GenerateMail(string mode, string topic_code, string dept = null, string[] dept_arry = null, string due_date = "", string pos = "")
        {
            try{
                Topic        = M_Mail.GetTopicByCode(topic_code);
                ViewBag.Mode = mode;
                ViewBag.Url  = $"http://172.27.170.19/ChangeControl/Detail/Index/?id={Topic.Code}";
                // ViewBag.Url = $"{Request.Url.Host}:{Request.Url.Port}/{Request.ApplicationPath}/Detail/Index/?id={Topic.Code}";
                ViewBag.Topic   = Topic;
                ViewBag.DueDate = due_date;
                if (ViewBag.Topic.FullStatus == "Waiting")
                {
                    ViewBag.Topic.FullStatus = "Request";
                }

                var           email           = RenderView("~/Views/Mail/index.cshtml", Topic);
                var           address_list    = new List <string>();
                List <String> temp_email_list = new List <string>();

                if (dept_arry != null) //Dept as array
                {
                    foreach (var temp_dept in dept_arry)
                    {
                        temp_email_list = M_Mail.GetEmailByDeptAndPosition(temp_dept, pos);
                        if (temp_email_list != null)
                        {
                            address_list.AddRange(temp_email_list);
                        }
                    }
                }
                else if (dept == "" || dept == null)  //Default department that related
                {
                    var related_list = M_Mail.GetRelatedByTopicCode(topic_code);

                    related_list.ForEach(rl => {
                        temp_email_list = M_Mail.GetEmailByDeptAndPosition(rl, pos);
                        if (temp_email_list != null)
                        {
                            address_list.AddRange(temp_email_list);
                        }
                    });
                }
                else   //Single department
                {
                    temp_email_list = M_Mail.GetEmailByDeptAndPosition(dept, pos);
                    if (temp_email_list != null)
                    {
                        address_list.AddRange(temp_email_list);
                    }
                }

                if (temp_email_list != null)
                {
                    SendMail(email, address_list);
                }
                return(Json(new { status = true }, JsonRequestBehavior.AllowGet));
                // return View(Topic);
            }catch (Exception err) {
                return(Json(new { error = err }, JsonRequestBehavior.AllowGet));
            }
        }
示例#2
0
        public ActionResult Index(string mode, string topic_code, string dept = null)
        {
            try{
                ViewBag.Mode = mode;
                // if(Topic.Type == "ERR0R"){
                Topic = M_Mail.GetTopicByCode(topic_code);
                // }
                // ViewBag.Url = $"https://17.27.170.19/ChangeControl/Detail/Index/?id={Topic.Code}";
                ViewBag.Url     = $"{Request.Url.Host}:{Request.Url.Port}/{Request.ApplicationPath}/Detail/Index/?id={Topic.Code}";
                ViewBag.Topic   = Topic;
                ViewBag.DueDate = DateTime.Now.DueDateOn(10);

                var email        = RenderView("~/Views/Mail/index.cshtml", Topic);
                var related_list = M_Mail.GetRelatedByTopicCode(topic_code);

                Type           type  = related_list.GetType();
                PropertyInfo[] props = type.GetProperties();

                var address_list = new List <string>();
                foreach (var prop in props)
                {
                    if ((int)prop.GetValue(related_list) == 1)
                    {
                        address_list.AddRange(M_Mail.GetEmailByDept(prop.Name));
                    }
                }

                SendMail(email, address_list);
                // return Json(new {status = true}, JsonRequestBehavior.AllowGet);
                return(View(Topic));
            }catch (Exception err) {
                return(Json(new { error = err }, JsonRequestBehavior.AllowGet));
            }
        }
示例#3
0
 public string RenderView(string viewName, TopicAlt model = null)
 {
     ViewData.Model = model;
     using (var sw = new StringWriter()){
         var viewResult  = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
         var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
         viewResult.View.Render(viewContext, sw);
         viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
         return(sw.GetStringBuilder().ToString());
     }
 }
示例#4
0
        public ActionResult Index(string ID)
        {
            if ((string)(Session["User"]) == null || (string)(Session["Department"]) == null || (string)(Session["Department"]) == "Guest")
            {
                Session["RedirectID"]   = (ID != null) ? ID : null;
                Session["RedirectMode"] = "Request";
                return(RedirectToAction("Index", "LogIn"));
            }

            GenerateTopicList(Convert.ToString(Session["Department"]), Convert.ToString(Session["Position"]));
            Session["RedirectID"] = null;

            if (ID == null || M_Req.CheckTopicOwner((string)Session["User"], ID))
            {
                Session["Topic"] = null;
                ViewBag.mode     = "Insert";
                if ((string)(Session["User"]) == null || (string)(Session["Department"]) == null)
                {
                    Session["url"] = "Request";
                    return(RedirectToAction("Index", "Login"));
                }
                List <GetID> last_iTopic = new List <GetID>();
                List <GetID> last_eTopic = new List <GetID>();
                last_iTopic = M_Req.GetInternalTopicId();
                last_eTopic = M_Req.GetExternalTopicId();

                if (last_iTopic.Count == 0)                                       //Case Internal Topic not exist
                {
                    ViewData["iTopic_id"] = "IN-" + date.Substring(2, 4) + "001"; //Then new ID = IN2006001
                }
                else if (last_iTopic.Count > 0)                                   //Case Internal Topic exist
                {
                    int i_id = Int32.Parse(last_iTopic[0].Code.Substring(7, 3)) + 1;
                    ViewData["iTopic_id"] = "IN-" + date.Substring(2, 4) + "" + i_id.ToString("000") + ""; //Then new ID = last Topic ID +1
                }

                if (last_eTopic.Count == 0)                                       //Case External Topic not exist
                {
                    ViewData["eTopic_id"] = "EX-" + date.Substring(2, 4) + "001"; //Then new id = EX2006001
                }
                else if (last_eTopic.Count > 0)                                   //Case External Topic exist
                {
                    int e_id = Int32.Parse(last_eTopic[0].Code.Substring(7, 3)) + 1;
                    ViewData["eTopic_id"] = "EX-" + date.Substring(2, 4) + "" + e_id.ToString("000") + ""; //Then new ID = last Topic ID +1
                }

                ViewData["FormChangeItem"]  = M_Req.GetChangeItem();  //Get list of change items radio
                ViewData["FormProductType"] = M_Req.GetProductType(); //Get list of product type radio

                var DepartmentGroup = M_Req.GetDepartmentGroup();     //Get raw group of departments

                List <DepartmentList> departmentList = new List <DepartmentList>();
                foreach (string GroupName in DepartmentGroup)
                {
                    List <Department> department = new List <Department>();
                    department = M_Req.GetDepartmentByGroup(GroupName);
                    departmentList.Add(new DepartmentList()
                    {
                        Name = GroupName.Replace(" ", "_"), Department = department
                    });                                                                                                    //Convert raw group into department list for radio
                }
                ViewData["DepartmentList"] = departmentList;

                if (ID != null) // In case of edit mode
                {
                    Session["isEditMode"] = true;
                    TopicAlt temp_topic = M_Req.GetTopicByID(ID);
                    if (temp_topic.Status != 3 && temp_topic.Status != 7)
                    {
                        return(View("~/Views/Shared/404/index.cshtml"));
                    }
                    else
                    {
                        temp_topic.RelatedListAlt = M_Req.GetRelatedByID(temp_topic.Related);
                        temp_topic.Timing         = temp_topic.Timing.StringToDigitDate2();

                        Session["Topic"] = ViewData["Topic"] = temp_topic;

                        var topic_file_list = M_Req.GetFileByID(temp_topic.ID, "Topic", temp_topic.Code, temp_topic.Department); //Get file by topic id
                        if (topic_file_list != null)
                        {
                            temp_topic.FileList = topic_file_list;
                            ViewData["Topic"]   = temp_topic;
                        }
                    }
                }
                return(View());
            }
            else
            {
                return(View("~/Views/Shared/404/index.cshtml"));
            }
        }
示例#5
0
 public MailController()
 {
     M_Detail = new DetailModel();
     M_Mail   = new MailModel();
     Topic    = new TopicAlt();
 }