Example #1
0
        public ActionResult DeleteNotice()
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);

            if (Session["DeptOfAdmin"].ToString() == "CE")
            {
                CE_Notice notices = db.CE_Notices.Where(s => s.NoticeId == id).FirstOrDefault();
                db.CE_Notices.Remove(notices);
                db.SaveChanges();
                return(Redirect("~/LogInPage/DisplayCeNotice"));
            }
            else if (Session["DeptOfAdmin"].ToString() == "IT")
            {
                IT_Notice notices = db.IT_Notices.Where(s => s.NoticeId == id).FirstOrDefault();
                db.IT_Notices.Remove(notices);
                db.SaveChanges();
                return(Redirect("~/LogInPage/DisplayItNotice"));
            }
            else if (Session["DeptOfAdmin"].ToString() == "EC")
            {
                EC_Notice notices = db.EC_Notices.Where(s => s.NoticeId == id).FirstOrDefault();
                db.EC_Notices.Remove(notices);
                db.SaveChanges();
                return(Redirect("~/LogInPage/DisplayEcNotice"));
            }
            else if (Session["DeptOfAdmin"].ToString() == "CH")
            {
                CH_Notice notices = db.CH_Notices.Where(s => s.NoticeId == id).FirstOrDefault();
                db.CH_Notices.Remove(notices);
                db.SaveChanges();
                return(Redirect("~/LogInPage/DisplayChNotice"));
            }
            else if (Session["DeptOfAdmin"].ToString() == "MH")
            {
                MH_Notice notices = db.MH_Notices.Where(s => s.NoticeId == id).FirstOrDefault();
                db.MH_Notices.Remove(notices);
                db.SaveChanges();
                return(Redirect("~/LogInPage/DisplayMhNotice"));
            }
            else if (Session["DeptOfAdmin"].ToString() == "IC")
            {
                IC_Notice notices = db.IC_Notices.Where(s => s.NoticeId == id).FirstOrDefault();
                db.IC_Notices.Remove(notices);
                db.SaveChanges();
                return(Redirect("~/LogInPage/DisplayIcNotice"));
            }
            else
            {
                return(Redirect("~/LogInPage/AdminLogIn"));
            }
        }
Example #2
0
        public ActionResult DisplayNotice(HttpPostedFileBase file, FormCollection notice)
        {
            if (Request.Files.Count > 0)
            {
                if (file != null)
                {
                    var filename = Path.GetFileName(file.FileName);
                    file.SaveAs(Server.MapPath("~/uploads/" + filename));
                    var dept = (string)Session["DeptOfAdmin"];
                    ViewBag.dept = dept;
                    string   title        = notice["Title"];
                    DateTime dateofnotice = DateTime.Parse(notice["date"]);
                    string   noticetype   = Convert.ToString(notice["NoticeType"]);
                    if (dept == "CE")
                    {
                        CE_Notice record = new CE_Notice()
                        {
                            TitleOfNotice = title,
                            date          = dateofnotice,
                            NoticeType    = noticetype,
                            FileName      = filename
                        };
                        db.CE_Notices.Add(record);
                        db.SaveChanges();


                        return(RedirectToAction("DisplayCeNotice"));
                    }
                    else if (dept == "IT")
                    {
                        IT_Notice record = new IT_Notice()
                        {
                            TitleOfNotice = title,
                            date          = dateofnotice,
                            NoticeType    = noticetype,
                            FileName      = filename
                        };
                        db.IT_Notices.Add(record);
                        db.SaveChanges();
                        return(RedirectToAction("DisplayItNotice"));
                    }
                    else if (dept == "IC")
                    {
                        IC_Notice record = new IC_Notice()
                        {
                            TitleOfNotice = title,
                            date          = dateofnotice,
                            NoticeType    = noticetype,
                            FileName      = filename
                        };
                        db.IC_Notices.Add(record);
                        db.SaveChanges();
                        return(RedirectToAction("DisplayIcNotice"));
                    }
                    else if (dept == "EC")
                    {
                        EC_Notice record = new EC_Notice()
                        {
                            TitleOfNotice = title,
                            date          = dateofnotice,
                            NoticeType    = noticetype,
                            FileName      = filename
                        };
                        db.EC_Notices.Add(record);
                        db.SaveChanges();
                        return(RedirectToAction("DisplayEcNotice"));
                    }
                    else if (dept == "CH")
                    {
                        CH_Notice record = new CH_Notice()
                        {
                            TitleOfNotice = title,
                            date          = dateofnotice,
                            NoticeType    = noticetype,
                            FileName      = filename
                        };
                        db.CH_Notices.Add(record);
                        db.SaveChanges();
                        return(RedirectToAction("DisplayChNotice"));
                    }
                    else if (dept == "MH")
                    {
                        MH_Notice record = new MH_Notice()
                        {
                            TitleOfNotice = title,
                            date          = dateofnotice,
                            NoticeType    = noticetype,
                            FileName      = filename
                        };
                        db.MH_Notices.Add(record);
                        db.SaveChanges();
                        return(RedirectToAction("DisplayMhNotice"));
                    }
                    else
                    {
                    }
                    return(View());
                }
                else
                {
                    ViewBag.msg = "File not uploaded successfully";
                    return(View());
                }
            }
            return(View());
        }