public void ApproveTeacher(string username)
 {
     using (XorHubEntities db = new XorHubEntities())
     {
         db.LoginInfoes.Where(l => l.Username.Equals(username)).FirstOrDefault().Stat = true;
         db.SaveChanges();
     }
 }
        public ActionResult Reject(Solution sol)
        {
            using (XorHubEntities db = new XorHubEntities())
            {
                var soln = db.Solutions.Where(s => s.SolutionId == sol.SolutionId).FirstOrDefault();
                soln.Stat    = "R";
                soln.Comment = sol.Comment; db.SaveChanges();
            }

            return(RedirectToAction("TeacherResponse", new { id = sol.AssignmentId }));
        }
        public ActionResult Register(int BatchId, LoginInfo model)
        {
            using (XorHubEntities db = new XorHubEntities())
            {
                List <SelectListItem> list = new List <SelectListItem>();
                foreach (var item in db.Batches)
                {
                    list.Add(new SelectListItem {
                        Text = item.Name, Value = item.BatchId.ToString()
                    });
                }

                ViewData["BatchList"] = list;
            }


            if (ModelState["Name"].Errors.Count > 0 || ModelState["Username"].Errors.Count > 0 || ModelState["Passwd"].Errors.Count > 0)
            {
                return(View("Index", model));
            }

            if (model.Usertype.Equals("T"))
            {
                model.BatchId = null;
                model.Stat    = false;
            }
            else
            {
                model.Stat = true;
            }

            using (XorHubEntities db = new XorHubEntities())
            {
                db.LoginInfoes.Add(model);
                db.SaveChanges();
            }

            ViewBag.Message = "User Registered Successfully!! ";
            ModelState.Clear();
            return(View("Index"));
        }
        public ActionResult PostQuestion(HttpPostedFileBase QueFile, Assignment assignment)
        {
            assignment.PostedDate = DateTime.Now;

            if (assignment.Deadline < assignment.PostedDate)
            {
                return(RedirectToAction("Teacher", "Home", new { id = 4 }));
            }

            assignment.TeacherName = Session["username"].ToString();

            if (!Directory.Exists(Server.MapPath("~/Database/Questions/")))
            {
                Directory.CreateDirectory(Server.MapPath("~/Database/Questions/"));
            }

            using (XorHubEntities db = new XorHubEntities())
            {
                db.Assignments.Add(assignment);
                db.SaveChanges();
            }

            try
            {
                QueFile.SaveAs(Path.Combine(Server.MapPath("~/Database/Questions"), assignment.AssignmentId.ToString() + ".pdf"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Teacher", "Home", new { id = 1 }));
            }



            ViewBag.Message = "Question Successfully uploaded!";

            return(RedirectToAction("Teacher", "Home"));
        }
        public ActionResult Submit(HttpPostedFileBase solutionDoc, AssignmentSolutionModel asModel)
        {
            if (asModel.Assignment.Deadline < DateTime.Now)
            {
                ViewBag.Message  = "Deadline crossed! Cannot Submit Solution";
                ViewBag.filePath = "~/Database/Questions/" + asModel.Assignment.AssignmentId + ".pdf";
                return(View("StudentResponse", asModel));
            }

            if (!Directory.Exists(Server.MapPath("~/Database/Solutions/" + Session["username"].ToString())))
            {
                Directory.CreateDirectory(Server.MapPath("~/Database/Solutions/" + Session["username"].ToString()));
            }

            try
            {
                solutionDoc.SaveAs(Path.Combine(Server.MapPath("~/Database/Solutions/" + Session["username"].ToString() + "/"), asModel.Assignment.AssignmentId + ".pdf"));
            }
            catch (Exception ex)
            {
                ViewBag.Message  = "Please Select File!";
                ViewBag.filePath = "~/Database/Questions/" + asModel.Assignment.AssignmentId + ".pdf";
                return(View("StudentResponse", asModel));
            }


            Solution soln = new Solution()
            {
                AssignmentId = asModel.Assignment.AssignmentId,
                Username     = Session["username"].ToString(),
                Stat         = "P",
                UploadedOn   = DateTime.Now,
                Document     = asModel.Assignment.AssignmentId + ".pdf",
                Comment      = ""
            };

            using (XorHubEntities db = new XorHubEntities())
            {
                try
                {
                    string userName = Session["username"].ToString();
                    if (db.Solutions.Any(s => s.Username.Equals(userName) && s.AssignmentId == asModel.Assignment.AssignmentId))
                    {
                        var tmp = db.Solutions.Where(s => s.Username.Equals(userName) && s.AssignmentId == asModel.Assignment.AssignmentId).FirstOrDefault();
                        tmp = soln;
                        db.SaveChanges();
                    }
                    else
                    {
                        db.Solutions.Add(soln);
                        db.SaveChanges();
                    }
                }
                catch (DbEntityValidationException e)
                {
                }
            }

            return(RedirectToRoute(new
            {
                Controller = "Home",
                Action = "Student",
                id = 3
            }
                                   ));
        }