Пример #1
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"));
            }
        }