예제 #1
0
        public ActionResult SaveUpdatedQuiz( quiz q )
        {
            if (Session["id"] != null )
            {
                try
                {
                    teacher.SaveUpdatedQuiz(q);

                    LogTeacher log = new LogTeacher();
                    log.courseId = q.cid;
                    log.discription = "Update Quiz";
                    log.totalMarks = q.TotalMarks;
                    log.tName = q.tid;
                    log.type = "Quiz";
                    log.date = DateTime.Today;

                    db.LogTeachers.Add(log);
                    db.SaveChanges();

                    return RedirectToAction("TeacherHome");
                }
                catch (Exception e)
                {
                    ViewBag.ErrorType = "Exception";
                    ViewBag.message = e.Message;
                    return View("ErrorPage");
                }
            }
            return RedirectToAction("signIn", "Home");
        }
예제 #2
0
        public ActionResult Save(quiz z)
        {
            if (Session["id"] != null && db.users.Find(Session["id"]).type.Equals("Teacher"))
            {
                try
                {
                    string tid = Session["id"].ToString();
                    string id = tid;
                    var startdate = Request["startDate"];
                    var enddate = Request["endDate"];

                    LogTeacher log = new LogTeacher();
                    log.courseId = z.cid;
                    log.discription = "Save Quiz";
                    log.totalMarks = z.TotalMarks;
                    log.tName = tid;
                    log.type = "Quiz";
                    log.date = DateTime.Today;

                    db.LogTeachers.Add(log);
                    db.SaveChanges();

                    string[] str = startdate.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);
                        z.startDate = 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);
                        z.startDate = dt;
                    }

                    string[] str1 = enddate.Split(' ');
                    string[] time1 = str1[1].Split(':');
                    string[] date1 = str1[0].Split('/');
                    string tt1 = str1[2];

                    if (tt1.Equals("AM"))
                    {
                        DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[0]), Convert.ToInt32(date1[1]), Convert.ToInt32(time1[0]), Convert.ToInt32(time1[1]), 0);
                        z.endDate = dt;
                    }
                    else
                    {
                        DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[0]), Convert.ToInt32(date1[1]), Convert.ToInt32(time1[0]) + 12, Convert.ToInt32(time1[1]), 0);
                        z.endDate = dt;
                    }

                    teacher.SaveQuiz(z, id);
                    ViewBag.message = 2;
                    return View("TeacherHome");
                }
                catch (Exception e)
                {
                    ViewBag.ErrorType = "Exception";
                    ViewBag.message = e.Message;
                    return View("ErrorPage");
                }
            }
            else
                return RedirectToAction("signIn" , "Home");

        }
예제 #3
0
        public ActionResult EditAssignment(assignment assign)
        {
            if (Session["id"] != null && db.users.Find(Session["id"]).type.Equals("Teacher"))
            {
                try
                {
                    string tid = Session["id"].ToString();
                    string id = tid;
                    var startdate = Request["startDate"];
                    var enddate = Request["endDate"];

                    LogTeacher log = new LogTeacher();
                    log.courseId = assign.cid;
                    log.discription = "Edit Assignment";
                    log.totalMarks = assign.totalMarks;
                    log.tName = tid;
                    log.type = "Assignment";
                    log.date = DateTime.Today;

                    db.LogTeachers.Add(log);


                    if (!startdate.Equals(Request["start"]))
                    {
                        string[] str = startdate.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);
                            assign.startDate = 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);
                            assign.startDate = dt;
                        }
                    }
                    else
                    {
                        string[] str = Request["start"].Split(' ');
                        string[] time = str[1].Split(':');
                        string[] date = str[0].Split('/');
                        string tt = str[2];

                        if (tt.Equals("AM"))
                        {
                            var outputLines = new List<string>();
                            string s = "" + Convert.ToInt32(date[2]) + "/" + Convert.ToInt32(date[1]) + "/" + Convert.ToInt32(date[0]) + " " + Convert.ToInt32(time[0]) + ":" + Convert.ToInt32(time[1]);
                            outputLines.Add(s);
                            System.IO.File.AppendAllLines(@"d:\errors.txt", outputLines);

                            //DateTime dt = new DateTime(2014, 04, 12);
                            DateTime dt = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[1]), Convert.ToInt32(date[0]));
                            assign.startDate = dt;
                        }
                        else
                        {
                            var outputLines = new List<string>();
                            string s = "" + Convert.ToInt32(date[2]) + "/" + Convert.ToInt32(date[1]) + "/" + Convert.ToInt32(date[0]) + " " + Convert.ToInt32(time[0]) + ":" + Convert.ToInt32(time[1]);
                            outputLines.Add(s);
                            System.IO.File.AppendAllLines(@"d:\errors.txt", outputLines);

                            //DateTime dt = new DateTime(2014, 04, 12);
                            DateTime dt = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[1]), Convert.ToInt32(date[0]));
                            assign.startDate = dt;
                        }

                    }

                    if (!enddate.Equals(Request["end"]))
                    {
                        string[] str1 = enddate.Split(' ');
                        string[] time1 = str1[1].Split(':');
                        string[] date1 = str1[0].Split('/');
                        string tt1 = str1[2];

                        if (tt1.Equals("AM"))
                        {
                            DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[0]), Convert.ToInt32(date1[1]), Convert.ToInt32(time1[0]), Convert.ToInt32(time1[1]), 0);
                            assign.endDate = dt;
                        }
                        else
                        {
                            DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[0]), Convert.ToInt32(date1[1]), Convert.ToInt32(time1[0]) + 12, Convert.ToInt32(time1[1]), 0);
                            assign.endDate = dt;
                        }
                    }
                    else
                    {
                        string[] str1 = Request["end"].Split(' ');
                        string[] time1 = str1[1].Split(':');
                        string[] date1 = str1[0].Split('/');
                        string tt1 = str1[2];

                        if (tt1.Equals("AM"))
                        {
                            var outputLines = new List<string>();
                            string s = "" + Convert.ToInt32(date1[2]) + "/" + Convert.ToInt32(date1[1]) + "/" + Convert.ToInt32(date1[0]) + " " + Convert.ToInt32(time1[0]) + ":" + Convert.ToInt32(time1[1]);
                            outputLines.Add(s);
                            System.IO.File.AppendAllLines(@"d:\errors.txt", outputLines);

                            //DateTime dt = new DateTime(2014, 04, 23);
                            DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[1]), Convert.ToInt32(date1[0]));
                            assign.endDate = dt;
                        }
                        else
                        {
                            var outputLines = new List<string>();
                            string s = "" + Convert.ToInt32(date1[2]) + "/" + Convert.ToInt32(date1[1]) + "/" + Convert.ToInt32(date1[0]) + " " + Convert.ToInt32(time1[0]) + ":" + Convert.ToInt32(time1[1]);
                            outputLines.Add(s);
                            System.IO.File.AppendAllLines(@"d:\errors.txt", outputLines);

                            //DateTime dt = new DateTime(2014,04,23);
                            DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[1]), Convert.ToInt32(date1[0]));
                            assign.endDate = dt;
                        }

                    }

                    if (Request.Files[0].ContentLength != 0)
                    {
                        HttpPostedFileBase file = Request.Files[0];
                        if (file.ContentType.Equals("application/pdf"))
                        {
                            file.SaveAs(Server.MapPath(@"~\Files\" + file.FileName));

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

                            assign.questionFilePath = dataFile;
                        }
                        else
                        {
                            ViewBag.ErrorType = "File Uploading";
                            ViewBag.message = "Please upload a text code file and text output file";
                            return View("ErrorPage");
                        }
                    }
                    else
                    {
                        assign.questionFilePath = Request["Q"];
                    }

                    if (Request.Files[1].ContentLength != 0)
                    {
                        HttpPostedFileBase file1 = Request.Files[1];
                        if (file1.ContentType.Equals("text/plain"))
                        {
                            file1.SaveAs(Server.MapPath(@"~\Files\" + file1.FileName));

                            var dataFile1 = Server.MapPath(@"~\Files\" + file1.FileName);

                            assign.solutionFilePath = dataFile1;

                        }
                        else
                        {
                            ViewBag.ErrorType = "File Uploading";
                            ViewBag.message = "Please upload a text code file and text output file";
                            return View("ErrorPage");
                        }
                    }
                    else
                    {
                        assign.solutionFilePath = Request["S"];
                    }
                    db.Entry(assign).State = EntityState.Modified;
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (System.Data.Entity.Validation.DbEntityValidationException e)
                    {
                        var outputLines = new List<string>();
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            outputLines.Add(string.Format(
                                "{0}: Entity of type \"{1}\" in state \"{2}\" has the following validation errors:",
                                DateTime.Now, eve.Entry.Entity.GetType().Name, eve.Entry.State));
                            foreach (var ve in eve.ValidationErrors)
                            {
                                outputLines.Add(string.Format(
                                    "- Property: \"{0}\", Error: \"{1}\"",
                                    ve.PropertyName, ve.ErrorMessage));
                            }
                        }
                        System.IO.File.AppendAllLines(@"d:\errors.txt", outputLines);
                        throw;
                    }
                    return View("TeacherHome");
                }
                catch (Exception e)
                {
                    ViewBag.ErrorType = "Exception";
                    ViewBag.message = e.Message;
                    return View("ErrorPage");
                }
            }
            else
                return RedirectToAction("signIn" , "Home");
        }
예제 #4
0
        public ActionResult SaveAssignment( assignment ass )
        {
            if (Session["id"] != null && db.users.Find(Session["id"]).type.Equals("Teacher"))
            {
                try
                {
                    string tid = Session["id"].ToString();
                    string id = tid;
                    var startdate = Request["startDate"];
                    var enddate = Request["endDate"];

                    string[] str = startdate.Split(' ');
                    string[] time = str[1].Split(':');
                    string[] date = str[0].Split('/');
                    string tt = str[2];

                    LogTeacher log = new LogTeacher();
                    log.courseId = ass.cid;
                    log.discription = "Save Assignment";
                    log.totalMarks = ass.totalMarks;
                    log.tName = tid;
                    log.type = "Assignment";
                    log.date = DateTime.Today;

                    db.LogTeachers.Add(log);

                    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);
                        ass.startDate = 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);
                        ass.startDate = dt;
                    }

                    string[] str1 = enddate.Split(' ');
                    string[] time1 = str1[1].Split(':');
                    string[] date1 = str1[0].Split('/');
                    string tt1 = str1[2];

                    if (tt1.Equals("AM"))
                    {
                        DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[0]), Convert.ToInt32(date1[1]), Convert.ToInt32(time1[0]), Convert.ToInt32(time1[1]), 0);
                        ass.endDate = dt;
                    }
                    else
                    {
                        DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[0]), Convert.ToInt32(date1[1]), Convert.ToInt32(time1[0]) + 12, Convert.ToInt32(time1[1]), 0);
                        ass.endDate = dt;
                    }

                    HttpPostedFileBase file = Request.Files[0];

                    file.SaveAs(Server.MapPath(@"~\Files\" + file.FileName));

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

                    ass.questionFilePath = dataFile;

                    HttpPostedFileBase file1 = Request.Files[1];
                    if (file.ContentType.Equals("application/pdf") && file1.ContentType.Equals("text/plain"))
                    {
                        file1.SaveAs(Server.MapPath(@"~\Files\" + file1.FileName));

                        var dataFile1 = Server.MapPath(@"~\Files\" + file1.FileName);

                        ass.solutionFilePath = dataFile1;

                        teacher.SaveAssignment(ass, id);

                        return View("TeacherHome");
                    }
                    else
                    {
                        ViewBag.ErrorType = "File Uploading";
                        ViewBag.message = "Please upload a text code file and text output file";
                        return View("ErrorPage");
                    }
                }
                catch (Exception e)
                {
                    ViewBag.ErrorType = "Exception";
                    ViewBag.message = e.Message;
                    return View("ErrorPage");
                }
            }
            else
            {
                return RedirectToAction("signIn" , "Home");
            }

        }