Example #1
0
        protected void btnStudentSave_DirectClick(object sender, DirectEventArgs e)
        {
            //var courseRef = courseRef(Course.Id);

            CourseStudent courseStudent = new CourseStudent();

            var control = CourseStudent;

            if (control.StudentNameSurname == "")
            {
                X.Msg.Alert("UYARI", "Lütfen geçerli bir ad giriniz").Show();
                return;
            }

            int returnValue = control.save();

            if (returnValue > 0)
            {
                X.Msg.Alert("UYARI", "Öğrenci eklenmiştir. Yeni bir öğrenci daha ekleyebilirsiniz").Show();
                CourseStudent = new CourseStudent();
            }
            else
            {
                X.Msg.Alert("UYARI", "Öğrenci kayıt edilememiştir").Show();
            }
        }
 public void ValidateScore(CourseStudent info)
 {
     if (info.Score > 0 || info.Score > 100)
     {
         throw new Exception(Common.Constants.Messages.CALIFICACION_ENTRE_0_Y_100);
     }
 }
Example #3
0
        public IHttpActionResult PutCourseStudent(int id, CourseStudent courseStudent)
        {
            if (id != courseStudent.Id)
            {
                return(BadRequest());
            }

            db.Entry(courseStudent).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CourseStudentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #4
0
        public IHttpActionResult PostCourseStudent(CourseStudent courseStudent)
        {
            db.CourseStudent.Add(courseStudent);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = courseStudent.Id }, courseStudent));
        }
Example #5
0
        public async Task <IActionResult> Drop(int CourseId)
        {
            if (CourseId == 0)
            {
                TempData["errorMessage"] = "No course selected. Please try again.";
                return(RedirectToAction(nameof(EnrolledCoursesList)));
            }
            Course course = courseDB.Courses.FirstOrDefault(c => c.CourseId == CourseId);

            if (course == null)
            {
                TempData["errorMessage"] = "Please select a valid course.";
                return(RedirectToAction(nameof(EnrolledCoursesList)));
            }
            Student student = await getLoggedInStudent();

            if (student == null)
            {
                TempData["errorMessage"] = "No student registered with this account. Please contact customer support.";
                return(RedirectToAction(nameof(List)));
            }
            if (student.Courses.Contains(course))
            {
                CourseStudent csdb = course.DeleteStudent(student);
                studentDB.SaveStudent(student);
                csDB.DeleteCourseStudents(csdb);
                courseDB.SaveCourse(course);
                TempData["successMessage"] = $"Successfully dropped course {course.Code}: {course.Name}.";
                return(RedirectToAction(nameof(EnrolledCoursesList)));
            }
            return(View("Enroll", course));
        }
        public async Task <SuccessResponse> CreateAsync(CourseEnrollCreateRequest request)
        {
            var courseEnroll = new CourseStudent()
            {
                CourseId  = request.CourseId,
                StudentId = request.StudentId
            };

            var alreadyExists = await _unitOfWork.CourseEnrollRepository.GetAAsynce(x =>
                                                                                    x.CourseId == request.CourseId &&
                                                                                    x.StudentId == request.StudentId);

            if (alreadyExists != null)
            {
                throw new MyAppException("hello student you are already exists in this course.");
            }
            await _unitOfWork.CourseEnrollRepository.CreateAsync(courseEnroll);

            if (await _unitOfWork.ApplicationSaveChangesAsync())
            {
                return(new SuccessResponse()
                {
                    StatusCode = 200,
                    Message = "The course enrolls has been successfully done."
                });
            }

            throw new MyAppException("Something went wrong!");
        }
        public bool Checkout(List<Course> courses, List<Course> newCourses, string StudentEmail)
        {
            var student = _dbContext.Students.FirstOrDefault(x => x.Email.ToLower() == StudentEmail.ToLower());

            if (student == null)
            {
                student = _dbContext.Students.FirstOrDefault();
            }

            foreach (var course in newCourses)
            {
                _dbContext.Courses.Add(course);
            }

            var newList = courses.Concat(newCourses).ToList();

            foreach (var course in newList)
            {
                var courseStudent = new CourseStudent()
                {
                    CourseId = course.Id,
                    StudentId = student.Id,
                    
                };

                _dbContext.CourseStudents.Add(courseStudent);
            }
            _dbContext.SaveChanges();
            return true;
        }
        public async Task <ApiSuccessResponse> InsertAsync(CourseAssignInsertViewModel request)
        {
            var isStudentAlreadyEntroll = await _unitOfWork.CourseStudentRepository.FindSingleAsync(x =>
                                                                                                    x.CourseId == request.CourseId &&
                                                                                                    x.StudentId == request.StudentId);

            if (isStudentAlreadyEntroll != null)
            {
                throw new ApplicationValidationException("this student already enroll this course");
            }

            var courseStudent = new CourseStudent()
            {
                CourseId  = request.CourseId,
                StudentId = request.StudentId
            };

            await _unitOfWork.CourseStudentRepository.CreateAsync(courseStudent);

            if (await _unitOfWork.SaveCompletedAsync())
            {
                return(new ApiSuccessResponse()
                {
                    StatusCode = 200,
                    Message = "student enroll successfully"
                });
            }
            throw new ApplicationValidationException("something wrong for enrollment");
        }
Example #9
0
        public void UpdateStudent(StudentVM studentVm)
        {
            Student student = _db.Students.Where(s => s.Id == studentVm.Id).FirstOrDefault();

            student.StudentName        = studentVm.StudentName.ToUpper();
            student.RegistrationNumber = studentVm.RegistrationNumber;
            _db.SaveChanges();

            //delete all courses of student in CourseStudent table
            var cs = _db.CourseStudents.Where(s => s.StudentId == studentVm.Id).ToList();

            foreach (var i in cs)
            {
                _db.Remove(i);
            }
            _db.SaveChanges();

            foreach (var courseId in studentVm.CourseIDs)
            {
                var CourseStudentDb = new CourseStudent();
                CourseStudentDb.CourseId  = courseId;
                CourseStudentDb.StudentId = student.Id;
                _db.CourseStudents.Add(CourseStudentDb);
            }
            _db.SaveChanges();
        }
        /// <summary>
        /// Adding Student to course
        /// Throws AppObjectNotFound if course does not exist
        /// Throws AppPersonNotFound if person does not exist
        /// </summary>
        /// <param name="id">Id of the course</param>
        /// <param name="model">SSN and Name</param>
        public StudentDTO AddStudentToCourse(int id, AddStudentViewModel model)
        {
            var course = _db.Courses.SingleOrDefault(x => x.ID == id);

            if (course == null)
            {
                // if course cannot be found
                throw new AppObjectNotFoundException();
            }
            // Checking if the person exists
            var person = _db.Persons.SingleOrDefault(x => x.SSN == model.SSN);

            if (person == null)
            {
                throw new AppPersonNotFoundException();
            }
            var ret = new StudentDTO();

            ret.SSN  = person.SSN;
            ret.Name = person.Name;

            //Checking if maximum number of student in course has been reached
            var studentsInCourse = NumberStudentsCourse(course.ID);

            if (studentsInCourse >= course.MaxStudents)
            {
                throw new MaxStudentsException();
            }
            //Removing student from waiting list
            var alreadyInCourse = _db.CourseStudents.SingleOrDefault(x => x.CourseID == course.ID && x.PersonID == person.ID);

            if (alreadyInCourse != null)
            {
                //If student is already in course but not active
                if (alreadyInCourse.Active == 0)
                {
                    alreadyInCourse.Active = 1;
                    _db.SaveChanges();
                    RemoveFromWaitingList(alreadyInCourse.CourseID, alreadyInCourse.PersonID);
                    return(new StudentDTO
                    {
                        Name = person.Name,
                        SSN = person.SSN
                    });
                }
                else
                {
                    throw new AlreadyRegisteredException();
                }
            }
            RemoveFromWaitingList(course.ID, person.ID);
            var adding = new CourseStudent();

            adding.CourseID = course.ID;
            adding.PersonID = person.ID;
            adding.Active   = 1;
            _db.CourseStudents.Add(adding);
            _db.SaveChanges();
            return(ret);
        }
        public async Task <CourseStudent> AddCourseEnrollAsync(CourseEnrollRequest request)
        {
            Guid id        = Guid.NewGuid();
            var  studentId = _unitOfWork.StudentRepository.GetAAsync(x => x.RollNo == request.studentRollNo).Result
                             .StudentId;
            var courseId = _unitOfWork.CourseRepository.GetAAsync(x => x.Code == request.CourseCode).Result.CourseId;

            var courseStudentEnroll =
                await _unitOfWork.CourseStudentEnrollRepository.GetAAsync(x =>
                                                                          x.CourseId == courseId && x.StudentId == studentId);

            if (courseStudentEnroll != null)
            {
                throw new MyAppException("Student Already enroll in this course");
            }
            var courseStudent = new CourseStudent
            {
                CourseStudentId = id.ToString(),
                StudentId       = studentId,
                CourseId        = courseId
            };
            await _unitOfWork.CourseStudentEnrollRepository.createAsync(courseStudent);

            if (await _unitOfWork.ApplicationSaveChangesAsync())
            {
                return(courseStudent);
            }
            throw new MyAppException("Something went wrong");
        }
        private bool Insert()
        {
            try
            {
                CourseStudent courseStudent = new CourseStudent();

                courseStudent.CourseStudentName       = CourseStudentName;
                courseStudent.CourseStudentNationalId = CourseStudentNationalId;
                courseStudent.UniqueID    = UniqueID;
                courseStudent.BookMoney   = BookMoney;
                courseStudent.CoursePrice = CoursePrice;
                courseStudent.PaidMoney   = PaidMoney;
                courseStudent.Notes       = Notes;

                MainClass.DbObj.CourseStudents.InsertOnSubmit(courseStudent);
                MainClass.DbObj.SubmitChanges();

                CourseStudentId = courseStudent.CourseStudentId;

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public void DeleteCourseStudent(string CourseID, string StudentID)
        {
            Console.WriteLine("Izbrisi slusanje slusanje");
            CourseStudent courseStudent = _courseStudentData.Find(StudentID, CourseID);

            _courseStudentData.Delete(courseStudent);
        }
Example #14
0
        public ActionResult Index(CourseStudent courseStudent)
        {
            List <Student> students = studentManager.GetAll();

            ViewBag.students = students;
            List <Course> courses = new List <Course>
            {
                new Course {
                    Id = ' ', Code = "--Select--", CourseName = "", Credit = ' '
                }
            };
            string message = "";

            if (!courseStudentManager.IsEnrollBefore(courseStudent))
            {
                message = courseStudentManager.Save(courseStudent);
            }
            else
            {
                message = "Sorry, This Student Already Enrolled This Course";
            }


            ViewBag.message = message;
            ViewBag.Courses = courses;
            ModelState.Clear();
            return(View());
        }
        public async Task <IActionResult> AddCourseStudent(int id)
        {
            var studentId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            var studentFromRepo = await _repo.GetStudent(studentId);

            var courseFromRepo = await _repo.GetCourse(id);

            if (await _repo.CourseStudentExists(id, studentId))
            {
                return(BadRequest("Student already exists in this course."));
            }

            var courseStudent = new CourseStudent
            {
                Course  = courseFromRepo,
                Student = studentFromRepo
            };

            courseFromRepo.CourseStudents.Add(courseStudent);

            if (await _repo.SaveAll())
            {
                return(Ok(courseFromRepo));
            }

            return(BadRequest("Could not add the student to the course."));
        }
Example #16
0
 public CourseStudentDTO MapCourseStudent(CourseStudent courseStudent)
 {
     return(new CourseStudentDTO {
         CourseId = courseStudent.CourseId,
         Student = MapStudent(courseStudent.Student)
     });
 }
Example #17
0
        public IActionResult AddStudentToCourse(int coId, int SoId)

        {
            Course course = _courseService.FindById(coId);

            if (course == null)
            {
                return(BadRequest());
            }

            Student student = _studentService.FindById(SoId);


            if (student == null)
            {
                return(BadRequest());
            }
            CourseStudent courseStudent = new CourseStudent()
            {
                CourseId = course.Id, StudentId = student.Id
            };

            course.Students.Add(courseStudent);
            _courseService.Update(course);

            student.Courses = null;

            return(PartialView("_StudentInClass", courseStudent));
        }
        public async Task <ApiSuccessResponse> CreateAsync(CourseEnrollCreateRequest request)
        {
            var courseEnroll = new CourseStudent()
            {
                CourseId  = request.CourseId,
                StudentId = request.StudentId
            };

            var alreadyCourseEnrollOrNot = await _unitOfWork.CourseEnrollRepository.FindSingleAsync(x =>
                                                                                                    x.CourseId == request.CourseId && x.StudentId == request.StudentId);

            if (alreadyCourseEnrollOrNot != null)
            {
                throw new MyAppException("The given student id already enrolled by this course.");
            }

            await _unitOfWork.CourseEnrollRepository.CreateAsync(courseEnroll);

            if (await _unitOfWork.AppSaveChangesAsync())
            {
                return(new ApiSuccessResponse()
                {
                    StatusCode = 200,
                    Message = "The course enrolls has been successfully done."
                });
            }

            throw new MyAppException("Something went wrong!");
        }
        public IActionResult EnrollStudent([FromRoute] int courseId)
        {
            // check if course exists or not
            var course = _context.Courses.FirstOrDefault(x => x.CourseId == courseId);

            if (course == null)
            {
                return(BadRequest(new { Message = "Course not found" }));
            }

            // check if student is already enrolled
            var studentCourse = _context.CourseStudents.FirstOrDefault(x => x.CourseId == courseId && x.UserId == _authenticatedUser.UserId);

            if (studentCourse != null)
            {
                return(BadRequest(new { Message = "Student is already enroled" }));
            }

            studentCourse = new CourseStudent()
            {
                CourseId  = course.CourseId,
                UserId    = _authenticatedUser.UserId,
                CreatedAt = DateTime.UtcNow,
                UpdatedAt = DateTime.UtcNow,
                Status    = "enrolled"
            };

            _context.Add(studentCourse);
            _context.SaveChanges();

            return(Ok(new { Message = "New student saved" }));
        }
Example #20
0
        public List <CourseStudent> GetAllCourse()
        {
            SqlConnection connection = new SqlConnection(connectionString);

            string queary = "select*from Vw_CourseStus";

            SqlCommand command = new SqlCommand(queary, connection);

            connection.Open();

            SqlDataReader        reader      = command.ExecuteReader();
            List <CourseStudent> aCourseList = new List <CourseStudent>();
            CourseStudent        course      = null;

            while (reader.Read())
            {
                course            = new CourseStudent();
                course.Id         = (int)reader["St_id"];
                course.CourseName = reader["CourseName"].ToString();
                course.RegNo      = reader["RegNo"].ToString();
                course.DeptId     = (int)reader["Id"];
                //course.RegNo = reader["RegNo"].ToString();
                //course.Credit = Convert.ToDecimal(reader["Credit"]);
                //course.Description = reader["Description"].ToString();
                //course.DepartmentId = (int)reader["Id"];
                //course.SemesterId = (int)reader["SemID"];
                aCourseList.Add(course);
            }
            reader.Close();
            connection.Close();
            return(aCourseList);
        }
Example #21
0
        public int Calculate(CourseStudent courseStudent, IEnumerable <Activity> studentActivities)
        {
            int    finalGrade = 0;
            double points     = 0;
            bool   passed     = true;

            foreach (ActivityType activityType in courseStudent.Course.ActivityTypes)
            {
                bool missed = true;
                foreach (Activity activity in studentActivities)
                {
                    if (activity.ActivityTypeID == activityType.ID && activity.Valid == true)
                    {
                        missed = false;
                        if (activityType.Required == true && activity.Status == false)
                        {
                            return(5);
                        }
                        if (activity.Status == true)
                        {
                            points = points + activity.Points * activityType.WeightCoefficient;
                        }
                    }
                }
                if (missed == true && activityType.Required == true)
                {
                    passed = false;
                }
            }
            if (passed == false)
            {
                return(0);
            }
            if (points <= 50)
            {
                finalGrade = 5;
            }
            if (points > 50 && points <= 60)
            {
                finalGrade = 6;
            }
            if (points > 60 && points <= 70)
            {
                finalGrade = 7;
            }
            if (points > 70 && points <= 80)
            {
                finalGrade = 8;
            }
            if (points > 80 && points <= 90)
            {
                finalGrade = 9;
            }
            if (points >= 91)
            {
                finalGrade = 10;
            }
            return(finalGrade);
        }
        public ActionResult DeleteCourse(int CourseStudentId)
        {
            CourseStudent joinEntry = _db.CourseStudent.FirstOrDefault(entry => entry.CourseStudentId == CourseStudentId);

            _db.CourseStudent.Remove(joinEntry);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #23
0
        public List <StudentLiteDTO> AddStudentToCourse(int id, StudentViewModel newStudent)
        {
            var course = _db.Courses.SingleOrDefault(x => x.ID == id);

            if (course == null)
            {
                throw new AppObjectNotFoundException();
            }

            var NumberOfStudents = (from cs in _db.CourseStudent
                                    where cs.CourseID == course.ID && cs.Active == 1
                                    join s in _db.Students on cs.SSN equals s.SSN
                                    select s).Count();

            if (NumberOfStudents >= course.MaxStudents)
            {
                throw new AppDataPreconditionFailedException();
            }
            var student = _db.Students.SingleOrDefault(x => x.SSN == newStudent.SSN);

            if (student == null)
            {
                throw new AppObjectNotFoundException();
            }

            var studentInCourse = _db.CourseStudent.SingleOrDefault(x => x.SSN == newStudent.SSN && x.CourseID == id);

            if (studentInCourse != null && studentInCourse.Active == 1)
            {
                throw new AppDataPreconditionFailedException();
            }

            var studentInWaitingList = _db.WaitingList.SingleOrDefault(x => x.SSN == newStudent.SSN && x.CourseID == id);

            if (studentInWaitingList != null)
            {
                _db.WaitingList.Remove(studentInWaitingList);
            }
            var addStudent = new CourseStudent {
                SSN = newStudent.SSN, CourseID = id, Active = 1
            };

            _db.CourseStudent.Add(addStudent);
            _db.SaveChanges();


            var result = (from cs in _db.CourseStudent
                          join s in _db.Students on cs.SSN equals s.SSN
                          where cs.CourseID == id
                          select new StudentLiteDTO
            {
                SSN = s.SSN,
                Name = s.Name
            }).ToList();

            return(result);
        }
Example #24
0
        public void CalculateGrade(string studentID, string courseID, IEnumerable <Activity> studentsActivity)
        {
            CourseStudent courseStudent = _context.CourseStudents.Include(s => s.Course).Include(s => s.Course.ActivityTypes).Include(s => s.Student).Where(s => s.Course.ID == courseID).Where(s => s.Student.ID == studentID).FirstOrDefault();
            int           grade         = Calculate(courseStudent, studentsActivity);

            courseStudent.ProposedGrade = grade;
            _context.CourseStudents.Update(courseStudent);
            _context.SaveChanges();
        }
Example #25
0
        public void DeleteCourseStudents(CourseStudent courseStudent)
        {
            CourseStudent dbcs = dbContext.CourseStudents.FirstOrDefault(cs => cs.CourseId == courseStudent.CourseId && cs.StudentId == courseStudent.StudentId);

            if (dbcs != null)
            {
                dbContext.CourseStudents.Remove(dbcs);
            }
            dbContext.SaveChanges();
        }
Example #26
0
 public static CURSOESTUDIANTE Map(this CourseStudent info)
 {
     return(new CURSOESTUDIANTE
     {
         ID = info.ID,
         IDCURSO = info.Course.ID,
         IDESTUDIANTE = info.Student.ID,
         CALIFICACION = info.Score
     });
 }
Example #27
0
        public void AddCourseStudents(CourseStudent courseStudent)
        {
            CourseStudent dbcs = dbContext.CourseStudents.FirstOrDefault(cs => cs.CourseId == courseStudent.CourseId && cs.StudentId == courseStudent.StudentId);

            if (dbcs == null)
            {
                dbContext.CourseStudents.Add(dbcs);
            }
            dbContext.SaveChanges();
        }
Example #28
0
        public string UpdateResult(CourseStudent courseStudent)
        {
            string query = "UPDATE CourseStudent SET Grade = '" + courseStudent.Grade + "' WHERE StudentId='" + courseStudent.StudentId + "' AND CourseId='" + courseStudent.CourseId + "'";

            Connection.Open();
            Command.CommandText = query;
            int rowsEffected = Command.ExecuteNonQuery();

            Connection.Close();
            return("Grade has been Updated");
        }
Example #29
0
        /// <summary>
        /// Adds a student to the course with the given id
        /// </summary>
        /// <param name="id">
        /// integer representing the Course ID
        /// example: 1
        /// </param>
        /// <param name="model">
        /// An AddStudentViewModel with the SSN of the student
        /// example: { "SSN": "2302962315"}
        /// </param>
        /// <returns>
        /// bool
        /// </returns>
        public bool AddStudentToCourseByID(int id, AddStudentViewModel student)
        {
            Console.Write(student);
            if (student == null)
            {
                throw new NoStudentException("Student is null");
            }

            var course = (
                from c in _db.Courses
                where c.ID == id
                select c
                ).SingleOrDefault();

            if (course == null)
            {
                throw new NoCourseException("Course not found");
            }

            var studentInCourse = (
                from s in _db.Students
                where s.SSN == student.SSN
                select s
                ).SingleOrDefault();


            if (studentInCourse == null)
            {
                throw (new NoStudentException("Student not found"));
            }

            var result = (
                from s in _db.CourseStudents
                where s.CourseID == course.ID &&
                s.StudentID == studentInCourse.ID
                select s
                ).SingleOrDefault();

            if (result != null)
            {
                throw new ConnectionExistsException("Student and course already connected");
            }

            CourseStudent cs = new CourseStudent
            {
                StudentID = studentInCourse.ID,
                CourseID  = id
            };

            _db.CourseStudents.Add(cs);
            _db.SaveChanges();

            return(true);
        }
Example #30
0
        public bool RegisterStudent(StudentCourseRegister paylaod)
        {
            var entity = new CourseStudent
            {
                CourseId  = paylaod.CourseId,
                StudentId = paylaod.StudentId
            };

            _courseStudentRepository.Create(entity);
            return(_repository.SaveChanges());
        }