예제 #1
0
        public ActionResult update()
        {
            CourseDal  c  = new CourseDal();
            StudentDal st = new StudentDal();


            Grade g = new Grade();

            g.cid      = Request.Form["cid"];
            g.username = Request.Form["username"];
            g.grade1   = Request.Form["grade"];


            string a1 = Request.Form["update"];

            Gradedal     dal = new Gradedal();
            List <Grade> s   = dal.grade.ToList <Grade>();

            if (st.Dalstudents.Find(g.username) == null)
            {
                ModelState.AddModelError(string.Empty, "Student Name not exists.");
                return(View("editgrade"));
            }

            if (c.courses.Find(g.cid) == null)
            {
                ModelState.AddModelError(string.Empty, "Student Name not exists.");
                return(View("editgrade"));
            }



            if (a1.Equals("u"))
            {
                Grade a = dal.grade.Find(g.username, g.cid);
                if (a == null)
                {
                    ModelState.AddModelError(string.Empty, " this Student didnt have grade to update.");
                    return(View("editgrade"));
                }

                a.grade1 = g.grade1;

                dal.SaveChanges();
            }


            if (a1.Equals("i"))
            {
                dal.grade.Add(g);
                dal.SaveChanges();
            }



            return(View("editgrade"));
        }
예제 #2
0
        public ActionResult update()
        {
            //CourseDal c = new CourseDal();
            // StudentDal st = new StudentDal();
            LearnDal l = new LearnDal();

            Grade g = new Grade();

            g.cid      = Request.Form["cid"];
            g.username = Request.Form["username"];
            g.grade1   = Request.Form["grade"];


            string a1 = Request.Form["update"];

            if (a1 == null)
            {
                a1 = "i";
            }
            Gradedal     dal = new Gradedal();
            List <Grade> s   = dal.grade.ToList <Grade>();

            if (l.learns.Find(g.username, g.cid) == null)
            {
                ModelState.AddModelError(string.Empty, "Student Name not exists.");
                return(View("editGrade"));
            }



            if (a1.Equals("u"))
            {
                Grade a = dal.grade.Find(g.username, g.cid);
                if (a == null)
                {
                    ModelState.AddModelError(string.Empty, " this Student didnt have grade in this course to update.");
                    return(View("editGrade"));
                }

                a.grade1 = g.grade1;
                try
                {
                    dal.SaveChanges();
                }
                catch (SqlException)
                {
                    ModelState.AddModelError(string.Empty, "The Student have grade in this course you can do update.");
                }
            }


            if (a1.Equals("i"))
            {
                dal.grade.Add(g);
                dal.SaveChanges();
            }



            return(View("editGrade"));
        }