Exemplo n.º 1
0
        public JsonResult Notification1(string uid)
        {
           
            string name = Request["uid"];
            Response.AppendHeader("Access-Control-Allow-Origin", "null");

            var a = from x in db.Announcements
                    where x.destination.Equals(name) && (!(x.title.Equals("message")) && !(x.Sender_u_id.Equals("ExamBranch"))) //&& x.status.Equals("0")
                    select x;
            List<Announcement> anno = new List<Announcement>();
            foreach (Announcement b in a)
            {
                Announcement an = new Announcement();
                an.mesg_text = b.mesg_text;
                an.Sender_u_id = b.Sender_u_id;
                an.status = b.status;
                an.title = b.title;
                an.dateTime = b.dateTime;
                an.audience = b.audience;
                an.destination = b.destination;
                anno.Add(an);
            }
            
            
            return this.Json(anno, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 2
0
        public ActionResult saveSittingPlan()
        {
            if (Session["id"] != null && db.users.Find(Session["id"]).type.Equals("ExamBranch"))
            {

                string result;
                HttpPostedFileBase file = Request.Files[0];
                file.SaveAs(Server.MapPath(@"~\Files\" + file.FileName));

                var dataFile = Server.MapPath(@"~\Files\" + file.FileName);

                Announcement a = new Announcement();
                a.attachment = dataFile;
                a.Sender_u_id = "ExamBranch";

                

                char[] delimiterChar = { ',' };
                string[] data = null;

                System.IO.FileStream fin = new FileStream(dataFile, FileMode.Open);
                StreamReader sr = new StreamReader(fin);
                result = sr.ReadLine();

                try
                {

                    while (result != null)
                    {
                        data = result.Split(delimiterChar);
                        Announcement a1 = new Announcement();
                        a1.Sender_u_id = "ExamBranch";

                        a1.destination = data[0].ToString();
                        string[] str = data[1].Split(' ');
                        string[] time = str[1].Split(':');
                        string[] date = str[0].Split('/');
                        string tt = str[2];

                        if (tt.Equals("AM"))
                        {
                            DateTime dt = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[0]), Convert.ToInt32(date[1]), Convert.ToInt32(time[0]), Convert.ToInt32(time[1]), 0);
                            a1.dateTime = dt;
                        }
                        else
                        {
                            DateTime dt = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[0]), Convert.ToInt32(date[1]), Convert.ToInt32(time[0]) + 12, Convert.ToInt32(time[1]), 0);
                            a1.dateTime = dt;
                        }

                        
                        a1.mesg_text = data[2].ToString() + " " + data[3].ToString() + " " + data[4].ToString();
                        db.Announcements.Add(a1);

                        result = sr.ReadLine();
                        data = null;
                        db.Announcements.Add(a1);


                    }
                    sr.Close();
                    fin.Close();

                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    ViewBag.ErrorType = "Upload Sitting Plan";
                    ViewBag.message = "File format is not correct";
                    sr.Close();
                    fin.Close();
                    return View("ErrorPage");
                }
                return View("ExamBranchHome");
            }
            return RedirectToAction("signIn", "Home");

        }
Exemplo n.º 3
0
        public ActionResult personalMesg2T1()
        {

            if (Session["id"] != null && db.users.Find(Session["id"]).type.Equals("Teacher"))
            {
                try
                {
                    ViewBag.ttid = Session["id"];

                    String subject = Request["sub"];
                    String mesg = Request["mesg_text"];

                    var dateAsString = DateTime.Now.ToString("yyyy-MM-dd");

                    String ttid = Request["tid"];
                    var q = from x in db.teachers
                            where x.tid.Equals(ttid)
                            select x;

                    foreach (var i in q)
                    {


                        var a = new Announcement();
                        a.destination = i.tid;

                        a.audience = i.name;
                        a.title = "message";
                        a.mesg_text = mesg;
                        //   a.attachment = attachment;
                        a.Sender_u_id = Session["id"].ToString();
                        a.dateTime = DateTime.Now;
                        a.status = "0";

                        db.Announcements.Add(a);

                    }

                    try
                    {

                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        StringBuilder sb = new StringBuilder();

                        foreach (var failure in ex.EntityValidationErrors)
                        {
                            sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                            foreach (var error in failure.ValidationErrors)
                            {
                                sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                                sb.AppendLine();
                            }
                        }

                        throw new DbEntityValidationException(
                            "Entity Validation Failed - errors follow:\n" +
                            sb.ToString(), ex
                        ); // Add the original exception as the innerException
                    }
                    return View("TeacherHome");
                }
                catch (Exception e)
                {
                    ViewBag.ErrorType = "Exception";
                    ViewBag.message = e.Message;
                    return View("ErrorPage");
                }
            }
            else
                return RedirectToAction("signIn", "Home");

        }
Exemplo n.º 4
0
        public ActionResult AnnouncementDegFallSection()
        {
            {
                if (Session["id"] != null && db.users.Find(Session["id"]).type.Equals("CustomUser") || Session["id"] != null && db.users.Find(Session["id"]).type.Equals("ExamBranch"))
                {
                    ViewBag.ttid = Session["id"];

                 


                    String subject = Request["sub"];
                    String mesg = Request["mesg_text"];
                   


                    var dateAsString = DateTime.Now.ToString("yyyy-MM-dd");



                    String fall = Request["fall"];
                    String degree = Request["degree"];
                    String section = Request["section"];

                    var q = from x in db.students
                            where x.batch.Equals(fall)
                            where x.degree.Equals(degree)
                            where x.section.Equals(section)
                            select x;

                    foreach (var i in q)
                    {


                        var a = new Announcement();
                        a.destination = i.sid;

                        a.audience = fall + " " + degree;
                        a.mesg_text = mesg;

                        a.Sender_u_id = Session["id"].ToString();
                        a.dateTime = DateTime.Now;
                        a.status = "0";

                        db.Announcements.Add(a);


                       
                    }

                    try
                    {

                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        StringBuilder sb = new StringBuilder();

                        foreach (var failure in ex.EntityValidationErrors)
                        {
                            sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                            foreach (var error in failure.ValidationErrors)
                            {
                                sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                                sb.AppendLine();
                            }
                        }

                        throw new DbEntityValidationException(
                            "Entity Validation Failed - errors follow:\n" +
                            sb.ToString(), ex
                        ); 
                    }
                    return View("CustomUserHome");
                }

                return RedirectToAction("signIn", "Home");
            }
        }
Exemplo n.º 5
0
        public ActionResult AnnouncementDegFallSection()
        {
            if (Session["id"] != null && db.users.Find(Session["id"]).type.Equals("Teacher"))
            {
                try
                {
                    ViewBag.ttid = Session["id"];
                    String subject = Request["sub"];
                    String mesg = Request["mesg_text"];
                    // String attachment = Request["attachment"];
                    //String audience = Request["a"]; // check on this if audience == "fall" then which fall, populate Student list acc.
                    //if audience == "degree" then which degree, populate Student list acc. 

                    //int id = -1;
                    //  String a_id;

                    //a_id = ViewBag.annID;
                    //int ann;

                    //a_id = db.Announcements.Max(p => p.announcement_id);


                    var dateAsString = DateTime.Now.ToString("yyyy-MM-dd");



                    String fall = Request["fall"];
                    String degree = Request["degree"];
                    String section = Request["section"];

                    var q = from x in db.students
                            where x.batch.Equals(fall)
                            where x.degree.Equals(degree)
                            where x.section.Equals(section)
                            select x;

                    foreach (var i in q)
                    {


                        var a = new Announcement();
                        a.destination = i.sid;

                        a.audience = fall + " " + degree;
                        a.mesg_text = mesg;

                        a.Sender_u_id = Session["id"].ToString();
                        a.dateTime = DateTime.Now;
                        a.status = "0";

                        db.Announcements.Add(a);


                        // id.ToString();
                        // ViewBag.annID = id;
                    }

                    try
                    {

                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        StringBuilder sb = new StringBuilder();

                        foreach (var failure in ex.EntityValidationErrors)
                        {
                            sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                            foreach (var error in failure.ValidationErrors)
                            {
                                sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                                sb.AppendLine();
                            }
                        }

                        throw new DbEntityValidationException(
                            "Entity Validation Failed - errors follow:\n" +
                            sb.ToString(), ex
                        ); // Add the original exception as the innerException
                    }
                    return View("TeacherHome");
                }
                catch (Exception e)
                {
                    ViewBag.ErrorType = "Exception";
                    ViewBag.message = e.Message;
                    return View("ErrorPage");
                }
            }
            else
                return RedirectToAction("signIn", "Home");
        }