Esempio n. 1
0
 public bool SaveStudentCourse(StudentCourseModel savemodel)
 {
     try
     {
         var StudentId = new SqlParameter("@StudentId", savemodel.StudentId);
         StudentId.Direction = ParameterDirection.InputOutput;
         var Name        = new SqlParameter("@Name", savemodel.Name);
         var DateOfBirth = new SqlParameter("@DateOfBirth", savemodel.DateOfBirth);
         var Gender      = new SqlParameter("@Gender", savemodel.Gender);
         var CourseIds   = new SqlParameter("@CourseIds", string.Join(",", savemodel.SelectedCourses.Select(p => p.CourseId).ToArray()));
         int retval      = ctx.Database.ExecuteSqlRaw(@"[dbo].[prcStudentCourseInsert] @StudentId OUTPUT
                                     ,@Name
                                     ,@DateOfBirth
                                     ,@Gender
                                     ,@CourseIds", new object[] { StudentId, Name, DateOfBirth, Gender, CourseIds });
         if (retval > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         ErrorMsg.Add(ex.Message);
         return(false);
     }
 }
Esempio n. 2
0
        public async Task AddStudentCourse(StudentCourseModel studentCourseModel)
        {
            var sc = _mapper.Map <StudentCourse>(studentCourseModel);

            _repositoryManager.StudentCourse.Add(sc);
            await _repositoryManager.CompleteAsync();
        }
Esempio n. 3
0
        public async Task UpdateStudentCourse(StudentCourseModel studentCourseModel)
        {
            var result = _mapper.Map <Student>(studentCourseModel);

            _repositoryManager.Student.Update(result);
            await _repositoryManager.CompleteAsync();
        }
 public async Task <ActionResult> AddResult([Bind(Include = "StudentCourseStudentId, StudentCourseCourseId, Grade")] StudentCourseModel studentCourseModel)
 {
     if (ModelState.IsValid)
     {
         var studentCourse = db.StudentCourses.Where(x => x.StudentCourseCourseId == studentCourseModel.StudentCourseCourseId && x.StudentCourseStudentId == studentCourseModel.StudentCourseStudentId && x.RecordStatus == 1).Single();
         studentCourse.Grade           = studentCourseModel.Grade;
         db.Entry(studentCourse).State = EntityState.Modified;
         if (await db.SaveChangesAsync() > 0)
         {
             TempData["Message"] = string.Format("<b>{0}</b> set for <b>{1}</b> enrolled by <b>{2}</b>",
                                                 studentCourse.Grade,
                                                 new CourseManager().GetCourseById(studentCourse.StudentCourseCourseId).CourseName,
                                                 new StudentManager().GetStudentById(studentCourse.StudentCourseStudentId).StudentName);
             TempData["MessageType"] = "success";
         }
         return(RedirectToAction("add-result"));
     }
     ViewBag.StudentCourseStudentId = new SelectList(new StudentManager().GetStudentsOrderByRegNo(), "StudentId", "StudentRegNo");
     ViewBag.StudentCourseCourseId  = new List <SelectListItem> {
         new SelectListItem {
             Value = "", Text = "Select Student Registration No First"
         }
     };
     ViewBag.Grade = new SelectList(new StudentManager().GetGrades(), "Grade", "Grade");
     return(View(studentCourseModel));
 }
        public async Task <ActionResult> EnrollCourse([Bind(Include = "StudentCourseStudentId, StudentCourseCourseId, EnrollDate, RecordStatus")] StudentCourseModel studentCourseModel)
        {
            studentCourseModel.RecordStatus = 1;
            if (ModelState.IsValid)
            {
                db.StudentCourses.Add(studentCourseModel);
                if (await db.SaveChangesAsync() > 0)
                {
                    var student = new StudentManager().GetStudentById(studentCourseModel.StudentCourseStudentId);
                    TempData["Message"] = string.Format("<b>{0}</b> of <b>{1}</b> enrolled to <b>{2}</b>",
                                                        student.StudentName,
                                                        student.DepartmentModel.Department,
                                                        db.Courses.Where(x => x.CourseId == studentCourseModel.StudentCourseCourseId).Single().Course);
                    TempData["MessageType"] = "success";
                }
                return(RedirectToAction("enroll-course"));
            }
            var deptId = new StudentManager().GetStudentById(studentCourseModel.StudentCourseStudentId).StudentDeptId;

            // db.Students.Where(y => y.StudentId == studentCourseModel.StudentCourseStudentId).Single().StudentDeptId;
            ViewBag.StudentCourseStudentId = new SelectList(new StudentManager().GetStudentsOrderByRegNo(), "StudentId", "StudentRegNo", studentCourseModel.StudentCourseStudentId);
            ViewBag.StudentCourseCourseId  = new SelectList(new CourseManager().GetCoursesByDepartment(deptId), "CourseId", "Course", studentCourseModel.StudentCourseCourseId);
            // db.Courses.Where(x => x.CourseDeptId == deptId).OrderBy(z => z.CourseCode).ToList()
            return(View(studentCourseModel));
        }
        public static StudentCourseModel Transform(StudentCourse input)
        {
            var output = new StudentCourseModel();

            Transformers.ForEach(i => i(input, output));
            return(output);
        }
Esempio n. 7
0
        public HttpResponseMessage PostStudents(StudentCourseModel request)
        {
            Students student = request.Student;
            List <CoursesViewModel> model = request.Courses;

            if (ModelState.IsValid)
            {
                if (model != null)
                {
                    student.Courses = new List <Course>();
                    foreach (var course in model)
                    {
                        if (course.IsSelected == true)
                        {
                            var coursesToAdd = db.Course.Find(Convert.ToInt32(course.CourseId));
                            student.Courses.Add(coursesToAdd);
                        }
                    }
                }

                db.Students.Add(student);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);
                return(response);
            }
            else
            {
                HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                return(response);
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,CourseId,StudentId")] StudentCourseModel studentCourseModel)
        {
            if (id != studentCourseModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(studentCourseModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentCourseModelExists(studentCourseModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"]  = new SelectList(_context.Courses, "CourseId", "Title", studentCourseModel.CourseId);
            ViewData["StudentId"] = new SelectList(_context.Students, "Id", "Fname", studentCourseModel.StudentId);
            return(View(studentCourseModel));
        }
Esempio n. 9
0
        public IActionResult Index()
        {
            var model = new StudentCourseModel();

            model.Courses  = _context.Courses.Include(i => i.StudentCourses).ThenInclude(i => i.Student).ToList();
            model.Students = _context.Students.Include(i => i.StudentCourses).ThenInclude(i => i.Course).ToList();

            return(View(model));
        }
        public async Task <IActionResult> Create([Bind("Id,CourseId,StudentId")] StudentCourseModel studentCourseModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(studentCourseModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"]  = new SelectList(_context.Courses, "CourseId", "Title", studentCourseModel.CourseId);
            ViewData["StudentId"] = new SelectList(_context.Students, "Id", "Fname", studentCourseModel.StudentId);
            return(View(studentCourseModel));
        }
Esempio n. 11
0
        public string SaveStudentCourse(StudentCourseModel model)
        {
            bool IsSaved = false;

            IsSaved = StudentBAL.SaveStudentCourse(model);
            if (IsSaved)
            {
                return("");
            }
            else
            {
                return(string.Join(",", StudentBAL.ErrorMsg.ToArray()));
            }
        }
        public IActionResult Index()
        {
            var model = new StudentCourseModel();

            model.Courses = context.Courses
                            .Include(x => x.StudentCourses)
                            .ThenInclude(x => x.Student)
                            .Where(x => x.isActive).ToList();

            model.Students = context.Students
                             .Include(x => x.StudentCourses)
                             .ThenInclude(x => x.Course)
                             .Where(x => x.StudentCourses.Any(a => a.Course.isActive)).ToList();

            return(View(model));
        }
        public static StudentCourse Transform(StudentCourseModel input, DomainStudent student, StudentCourse output = null)
        {
            var studentCourseRep  = IocRegistration.IoCContainer.Resolve <IStudentCourseRepository>();
            var courseInstanceRep = IocRegistration.IoCContainer.Resolve <ICourseInstanceRepository>();

            if (output == null)
            {
                output = studentCourseRep.Find(student.Id, input.Course, input.Semester);
            }

            if (output == null)
            {
                output = new StudentCourse();
            }

            Transformers.ForEach(i => i(input, student, output, courseInstanceRep));
            return(output);
        }
Esempio n. 14
0
 public IActionResult Save(StudentCourseModel model)
 {
     if (!ModelState.IsValid)
     {
         var errors = ModelState.Values.Where(p => p.Errors.Count > 0)
                      .Select(p => string.Join(",", p.Errors.Select(q => q.ErrorMessage).ToArray()));
         return(new JsonResult(new { valid = false, msg = string.Join(",", errors.ToArray()) }));
     }
     using (StudentHelper helper = new StudentHelper())
     {
         string Msg = helper.SaveStudentCourse(model);
         if (Msg == "")
         {
             return(new JsonResult(new { valid = true, msg = "" }));
         }
         else
         {
             return(new JsonResult(new { valid = false, msg = Msg }));
         }
     }
 }
Esempio n. 15
0
        public HttpResponseMessage PutStudents(StudentCourseModel request)
        {
            Students student = request.Student;
            List <CoursesViewModel> Courses = request.Courses;

            if (ModelState.IsValid)
            {
                if (Courses != null)
                {
                    var studentToUpdate = db.Students
                                          .Include(i => i.Courses)
                                          .Where(i => i.StudentId == student.StudentId).Single();

                    studentToUpdate.FirstName = student.FirstName;
                    studentToUpdate.LastName  = student.LastName;
                    studentToUpdate.GenderId  = student.GenderId;
                    studentToUpdate.CountryId = student.CountryId;
                    studentToUpdate.StateId   = student.StateId;
                    studentToUpdate.CityId    = student.CityId;
                    studentToUpdate.EmailId   = student.EmailId;
                    studentToUpdate.Password  = student.Password;
                    studentToUpdate.BirthDate = student.BirthDate;

                    string[] selectedCourses = Courses.Where(c => c.IsSelected).Select(i => i.CourseId.ToString()).ToArray();
                    UpdateStudentCourses(selectedCourses, studentToUpdate);
                }


                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
                return(response);
            }
            else
            {
                HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                return(response);
            }
        }
Esempio n. 16
0
        public IActionResult Index()
        {//modelin kurs kısmı dolduruldu.
            var model = new StudentCourseModel();

            model.Courses = _context
                            .Courses
                            .Include(i => i.StudentCourses)
                            .ThenInclude(i => i.Student)
                            //   .Where(i=>i.isActive)
                            .ToList();

            //modelin student kısmı

            model.Students = _context
                             .Students
                             .Include(i => i.StudentCourses)
                             .ThenInclude(i => i.Course)
                             //  .Where(i=>i.StudentCourses
                             //    .Any(j=>j.Course.isActive))//onaylı bir kursa dahil olmus öğrencileri getiriyoruz.
                             .ToList();
            return(View(model));
        }
Esempio n. 17
0
        public IActionResult Details(long?Id)
        {
            using (StudentHelper helper = new StudentHelper())
            {
                StudentCourseModel model = new StudentCourseModel();
                model.SelectedCourses = new List <CourseModel>();
                if (Id.HasValue)
                {
                    model = helper.GetData(Id.Value);
                }

                using (CourseHelper chelper = new CourseHelper())
                {
                    model.Courses = chelper.GetList();
                }
                if (!Id.HasValue || Id.Value == 0)
                {
                    model.DateOfBirth = System.DateTime.Now;
                    model.BirthDate   = System.DateTime.Now.ToString("dd-MMM-yyyy");
                }
                return(View(model));
            }
        }
 public async Task UpdateStudentCourse([FromBody] StudentCourseModel model)
 {
     await _operation.UpdateStudentCourse(model);
 }
 public async Task AddStudentCourse([FromBody] StudentCourseModel model)
 {
     await _operation.AddStudentCourse(model);
 }