public ActionResult Add(StudentInfoViewModel model)
 {
     if (!CheckStudentExist(model.Number))
     {
         Student student = new Student
         {
             Number   = model.Number,
             Name     = model.Name,
             Gender   = model.Gender,
             Major    = model.Major,
             Password = "******"
         };
         db.Students.Add(student);
         int i = db.SaveChanges();
         if (i > 0)
         {
             return(GetAllStudentsView());
         }
         else
         {
             return(Json(new { code = 1, data = "添加失败" }));
         }
     }
     else
     {
         return(Json(new { code = 1, data = "该学生已存在" }));
     }
 }
        // GET: Registrations/Delete/5
        public IActionResult Delete(string id)
        {
            //Retrieve the registration from the database and remove it.
            //A registration is determined by the student number and course id.
            string       studentNum   = HttpContext.Session.GetString("StudentNum");
            Registration registration = (_context.Registration.Where(m => m.CourseCourseId == id && m.StudentStudentNum == studentNum)).FirstOrDefault();

            _context.Registration.Remove(registration);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "Id,Username,Password,Email,EName,EFamily,NatinalCardPhoto,Job,JobTelephone,PostCode,Peygiri,PeygiriPhotoFilename,Name,Family,FatherName,NatinalCode,ShenasnameCode,Birthday,City,Adderess,Mobile,Telephone,AltTelephone,PhotoFilename,Degree,Level,Average,Gender,SeatNumber,RegisterOn,Total,IsPaied,PaiedOn,TraceNumber,ReferenceNumber,TransactionReferenceID,TransactionDate,LastDegrePhotoFilename,University,Major,Country,EventId")] RegisterForm registerForm)
        {
            if (ModelState.IsValid)
            {
                db.RegisterForms.Add(registerForm);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.EventId = new SelectList(db.Events, "Id", "Name", registerForm.EventId);
            return(View(registerForm));
        }
        public ActionResult Modify(TeacherViewModel teacher)
        {
            Teacher _teacher = db.Teachers.SingleOrDefault(d => d.Id == teacher.Id);

            if (_teacher != null)
            {
                _teacher.Name      = teacher.Name;
                _teacher.LoginName = teacher.LoginName;
                _teacher.IsSuper   = teacher.IsSuper;
                int i = db.SaveChanges();
                return(PartialView("PartialTeacherList", bindTeacherViewModel()));
            }
            return(Json(new { code = 1, data = "修改失败" }));
        }
Exemple #5
0
        public ActionResult EnrollBest(string number)
        {
            var stu = db.Students.SingleOrDefault(s => s.Number == number);

            if (stu != null)
            {
                var direction  = stu.DirectionStudents.FirstOrDefault(ds => ds.Order == 1).Direction;
                var enrollment = new Enrollment
                {
                    Direction     = direction,
                    WhichTime     = 0,
                    ScoreOrder    = 0,
                    Student       = stu,
                    EnrollCourses = new List <Course>()
                };

                var scoreCount = direction.DirectionCourses.Count;
                if (scoreCount > 3)
                {
                    var scores = stu.Scores.Where(s => s.Course.DirectionCourse.Count != 0).OrderByDescending(s => s.Value).Take(4).ToList();
                    foreach (var sc in scores)
                    {
                        enrollment.EnrollCourses.Add(sc.Course);
                    }
                }
                else
                {
                    foreach (var c in direction.DirectionCourses)
                    {
                        enrollment.EnrollCourses.Add(c.Course);
                    }
                }

                if (stu.Enrollment == null)
                {
                    db.Enrollments.Add(enrollment);
                }
                else
                {
                    stu.Enrollment.Direction  = enrollment.Direction;
                    stu.Enrollment.WhichTime  = enrollment.WhichTime;
                    stu.Enrollment.ScoreOrder = enrollment.ScoreOrder;
                    stu.Enrollment.EnrollCourses.RemoveAll(c => true);
                    stu.Enrollment.EnrollCourses.AddRange(enrollment.EnrollCourses);
                }
                db.SaveChanges();
            }
            return(GetEnrollments(1, number, null, null, null));
        }
Exemple #6
0
 public ActionResult Add(CourseViewModel course)
 {
     if (!IsExistedCourse(course.CourseName))
     {
         Course _course = new Course
         {
             CourseName = course.CourseName
         };
         db.Courses.Add(_course);
         int i = db.SaveChanges();
         if (i > 0)
         {
             return(PartialView("PartialCourseList", GetCoursesViewModel()));
         }
     }
     return(Json(new { code = 1, data = "课程已存在" }));
 }
        public ActionResult Add(DirectionViewModel model)
        {
            if (!isExistedDirection(model.Title))
            {
                Direction d = new Direction
                {
                    Title = model.Title,
                    Max   = model.Max
                };
                db.Directions.Add(d);
                int i = db.SaveChanges();

                if (i > 0)
                {
                    return(PartialView("PartialDirectionList", BindDirectionsViewModel()));
                }
            }
            return(Json(new { code = 1, data = "添加失败" }));
        }
        public ActionResult Save(DirectionSaveViewModel model)
        {
            if (IsTimeOver)
            {
                return(Json(new { code = 1, data = "填报已截止" }));
            }

            Student stu = db.Students.SingleOrDefault(s => s.Id == model.Sid);
            //安全验证,如果当前提交的ID未与Session中学生ID一致,则强制退出,清空Session。
            string stu_number = Session["currStu"] as string;

            if (stu_number != stu.Number)
            {
                Session.Clear();
                return(Redirect(Url.Action("Login", "Home")));
            }
            if (stu != null)
            {
                int tag = 0;
                if (stu.DirectionStudents.Count == 0)
                {
                    foreach (var item in model.Orders)
                    {
                        var direction = db.Directions.SingleOrDefault(d => d.Id == item.Did);
                        if (direction != null)
                        {
                            var dd = new DirectionStudent
                            {
                                Order     = item.Order,
                                Direction = direction
                            };

                            stu.DirectionStudents.Add(dd);
                            tag++;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    //修改填报信息
                    foreach (var item in model.Orders)
                    {
                        var selectedDirection = db.DirectionStudents.SingleOrDefault(d => d.Student.Id == stu.Id && d.Direction.Id == item.Did);
                        if (selectedDirection != null)
                        {
                            selectedDirection.Order = item.Order;
                            tag++;
                        }
                    }
                }

                if (tag == model.Orders.Count)
                {
                    int i = db.SaveChanges();
                    return(Json(new { code = 0, data = "填报成功" }));
                }
            }
            return(Json(new { code = 1, data = "保存失败" }));
        }