Ejemplo n.º 1
0
        public HttpResponseMessage AddStudentToWaitingList(int id, AddStudentViewModel model)
        {
            var responseData = _service.AddStudentToWaitingList(id, model);
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, responseData);

            return response;
        }
Ejemplo n.º 2
0
        public HttpResponseMessage RemoveStudentFromCourse(int id, AddStudentViewModel model)
        {
            var responseData = _service.RemoveStudentFromCourse(id, model);
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, responseData);

            return response;
        }
Ejemplo n.º 3
0
 public IHttpActionResult AddStudentToCourse(int id, AddStudentViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var result = _service.AddStudentToCourse(id, model);
             var location = Url.Link("GetStudentInCourse", new { id = id, SSN = result.SSN });
             return Created(location, result);
         }
         catch (AppObjectNotFoundException)
         {
             return StatusCode(HttpStatusCode.NotFound);
         }
         catch (AppObjectIllegalAddException)
         {
             return StatusCode(HttpStatusCode.PreconditionFailed);
         }
         catch(AppMaxReachedException)
         {
             return StatusCode(HttpStatusCode.PreconditionFailed);
         }
     }
     else
     {
         return StatusCode(HttpStatusCode.PreconditionFailed);
     }
 }
Ejemplo n.º 4
0
        public IActionResult AddStudent(int id, AddStudentViewModel viewModel)
        {
            Course  course  = courseRepository.GetCourse(id);
            Student student = studentRepository.GetStudent(viewModel.StudentId);

            course.AddStudent(student);

            return(Redirect("Index"));
        }
        public int UpdateStudent(long id, AddStudentViewModel updateStudentModel)
        {
            var user = _StudentRepository.GetAll().SingleOrDefault(c => c.Id == id);
            var DATA = Mapper.Map <AddStudentViewModel, AddStudent>(updateStudentModel);

            _StudentRepository.Edit(user, DATA);;
            _unitOfWork.Commit();
            return(1);
        }
        public IActionResult Post([FromForm] AddStudentViewModel model)
        {
            var std = _mapper.Map <Student.Api.Models.Student>(model);

            std.PhotoPath = ProcessUploadedFile(model);
            _studentRepository.AddStudent(std);
            _studentRepository.Save();

            return(CreatedAtRoute("GetStudent", new { id = std.StudentId }, std));
        }
Ejemplo n.º 7
0
        //Add
        public int AddStudent(AddStudentViewModel addStudentModel)
        {
            //throw new NotImplementedException();
            var studentData = Mapper.Map <AddStudentViewModel, AddStudent>(addStudentModel);

            _StudentRepository.Add(studentData);
            _unitOfWork.Commit();

            return(1);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public IHttpActionResult Post([FromBody] AddStudentViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var a = _iAddStudentService.AddStudent(model);

            return(Ok(a));
        }
Ejemplo n.º 10
0
        public ActionResult AddStudentToCourse(int id, AddStudentViewModel addStudent)
        {
            addStudent.CourseId = id;

            if (addStudent.LastName != null || addStudent.GradeLevel.HasValue)
            {
                UserProfileRepo userProfiles = new UserProfileRepo();
                addStudent.SearchResults = userProfiles.SearchByNotInCourse(id, addStudent.LastName, addStudent.GradeLevel);
            }

            return(View(addStudent));
        }
        public async Task <IActionResult> AddStudent()
        {
            var user = await GetCurrentUserAsync();

            List <Student> StudentList = await context.Student.Where(s => s.ApplicationUserId == user.Id).ToListAsync();

            var model = new AddStudentViewModel(context, user);

            model.Student = StudentList;

            return(View(model));
        }
Ejemplo n.º 12
0
        public ActionResult Add(AddStudentViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Classes = GetClasses(model.SelectedClassId).ToList();
                return(View(model));
            }

            DataRepository.CreateStudent(model.Student);

            return(RedirectToAction("Index", new { selectedClassId = model.Student.ClassId }));
        }
Ejemplo n.º 13
0
        private AddStudentViewModel ListAllFaculties(AddStudentViewModel model)
        {
            var faculties = facultyRepository.GetAll();

            foreach (var faculty in faculties)
            {
                model.Faculties.Add(new SelectListItem {
                    Text = faculty.FacultyName, Value = faculty.Id.ToString()
                });
            }
            return(model);
        }
Ejemplo n.º 14
0
        public ActionResult Add(int?selectedClassId = null)
        {
            var model = new AddStudentViewModel
            {
                Student         = new Data.Models.Student(),
                SelectedClassId = selectedClassId,
                Classes         = GetClasses(selectedClassId).ToList()
            };

            ViewBag.Title = "Add Student";
            return(View(model));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Method that adds a student to a course with a given ID.
        /// The attributes needed to add a student to a course are given with 
        /// a view model class.
        /// </summary>
        /// <param name="id">ID of the course</param>
        /// <param name="model">Add student view model (ViewModel class)</param>
        /// <returns>The student that was added to the course (DTO class)</returns>
        public StudentDTO AddStudentToCourse(int id, AddStudentViewModel model)
        {
            var course = _db.Courses.SingleOrDefault(x => x.ID == id);
            var student = _db.Students.SingleOrDefault(x => x.SSN == model.SSN);
            if (course == null || student == null)
            {
                throw new AppObjectNotFoundException();
            }

            var studentInCourse = _db.CourseStudents.SingleOrDefault(x => x.CourseID == id && x.StudentID == student.ID && x.IsActive == true);
            if(studentInCourse != null)
            {
                throw new AppObjectIllegalAddException();
            }

            if (course.MaxStudents <= GetStudentsInCourse(id).Count)
            {
                throw new AppMaxReachedException();
            }

            var studentInWaitingList = _db.WaitingLists.SingleOrDefault(x => x.CourseID == id && x.StudentID == student.ID);
            if(studentInWaitingList != null)
            {
                _db.WaitingLists.Remove(studentInWaitingList);
            }

            var courseStudent = _db.CourseStudents.SingleOrDefault(x => x.CourseID == id && x.StudentID == student.ID && x.IsActive == false);

            if(courseStudent != null)
            {
                courseStudent.IsActive = true;
            }
            else
            {
                var newCourseStudent = new CourseStudent
                {
                    CourseID = course.ID,
                    StudentID = student.ID,
                    IsActive = true
                };
                _db.CourseStudents.Add(newCourseStudent);
            }

            _db.SaveChanges();

            var result = new StudentDTO
            {
                Name = student.Name,
                SSN = student.SSN
            };

            return result;
        }
Ejemplo n.º 16
0
        public IActionResult AddStudents(AddStudentViewModel model)
        {
            Student student = new Student()
            {
                FirstName = model.FirstName,
                LastName  = model.LastName,
                Age       = model.Age,
                Academy   = model.Academy,
            };

            _studentService.Insert(student);
            return(RedirectToAction("GetAllStudents"));
        }
Ejemplo n.º 17
0
 public ActionResult Create(AddStudentViewModel model)
 {
     lastId++;
     studentModel.Students.Add(new Student
     {
         FullName = model.FullName,
         Age      = model.Age,
         Address  = model.Address,
         ImageUrl = model.ImageUrl
     });
     studentModel.SaveChanges();
     return(RedirectToAction(nameof(Index), "Student"));
 }
        public IActionResult AddStudent(AddStudentViewModel model)
        {
            Student student = new Student()
            {
                FirstName     = model.FirstName,
                LastName      = model.LastName,
                Age           = model.Age,
                TypeOfAcademy = model.TypeOfAcademy
            };

            _studentService.AddNewStudent(student);
            return(View("_ThankYouView"));
        }
Ejemplo n.º 19
0
        private AddStudentViewModel ListAllDepartments(AddStudentViewModel model)
        {
            ListAllFaculties(model);
            var departments = studentRepository.GetDepartmentsByFacultyId(model.FacultyId);

            foreach (var department in departments)
            {
                model.Departments.Add(new SelectListItem {
                    Text = department.DepartmentName, Value = department.Id.ToString()
                });
            }
            return(model);
        }
Ejemplo n.º 20
0
        public ActionResult Create(AddStudentViewModel model)
        {
            _context.Students.Add(new Student
            {
                Address   = model.Address,
                Age       = model.Age,
                FullName  = model.FullName,
                URL_Image = model.URL_Image,
            });
            _context.SaveChanges();

            return(RedirectToAction("Index", "Student"));
        }
Ejemplo n.º 21
0
        //public ActionResult Create(string studentName, string studentFirstName, string studentBirthDate)
        public ActionResult Create(AddStudentViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Add", viewModel));
            }
            else
            {
                studentService.Save(viewModel.Student);

                // Ajout de l'étudiant à la session en cours
                //Students.Add(viewModel);
                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 22
0
 public IActionResult AddStudent(AddStudentViewModel model)
 {
     if (ModelState.IsValid)
     {
         foreach (var item in model.Students)
         {
             if (item.Add)
             {
                 var user = _userService.GetUserId(item.Id);
                 _courseService.AddToCourse(user.Id, model.IdCourse);
             }
         }
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 23
0
        public bool StudentInStudents(AddStudentViewModel model)
        {
            var current = (from x in _db.Students
                           where x.SSN == model.SSN
                           select x).SingleOrDefault();

            if (current == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Add a student to a courses waiting list. Throws NotFound PreconditionFailed and DbException.
        /// </summary>
        /// <param name="id">The ID of the cours the waiting list is for.</param>
        /// <param name="addStudentModel">The view model for the student being added</param>
        /// <returns>A list of students in the courses waiting list.</returns>
        public List <StudentDTO> AddStudentToWaitingList(int id, AddStudentViewModel addStudentModel)
        {
            var course = _db.Courses.SingleOrDefault(c => c.ID == id);

            if (course == null)
            {
                throw new NotFoundException($"No course with ID: {id}");
            }

            var student = _db.Students.SingleOrDefault(s => s.SSN == addStudentModel.SSN);

            if (student == null)
            {
                throw new NotFoundException($"No student with SSN: {addStudentModel.SSN}");
            }

            var enroled =
                _db.CourseEnrolments.SingleOrDefault(ce => ce.CourseID == course.ID && ce.StudentID == student.ID && ce.Active);

            if (enroled != null)
            {
                throw new PreconditionFailedException($"{student.Name} is enroled in the course");
            }

            var waiting = _db.CourseWaitinglists.SingleOrDefault(e => e.CourseID == course.ID && e.StudentID == student.ID);

            if (waiting != null)
            {
                throw new PreconditionFailedException($"{student.Name} is already on the waiting list for {course.TemplateID}");
            }

            _db.CourseWaitinglists.Add(new CourseWaitinglist {
                CourseID = course.ID, StudentID = student.ID
            });

            try
            {
                _db.SaveChanges();
            }
            catch (Exception e)
            {
                throw new DbException(e);
            }

            return(GetWaitinglist(course.ID));
        }
Ejemplo n.º 25
0
        public IActionResult AddStudentG(AddStudentViewModel model)
        {
            ViewData["Adding"]           = _localizer["Adding"];
            ViewData["AddStudentHeader"] = _localizer["AddStudentHeader"];
            ViewData["CreateButton"]     = _localizer["CreateButton"];
            ViewData["BackToStudents"]   = _localizer["BackToStudents"];
            ViewData["Library"]          = _localizer["Library"];
            ViewData["Books"]            = _localizer["Books"];
            ViewData["Students"]         = _localizer["Students"];
            ViewData["Admins"]           = _localizer["Admins"];
            ViewData["MyBooks"]          = _localizer["MyBooks"];
            ViewData["LogOut"]           = _localizer["LogOut"];
            ViewData["Language"]         = _localizer["Language"];

            model.User = GetUser();
            return(View("AddStudent", model));
        }
        private string ProcessUploadedFile(AddStudentViewModel model)
        {
            string uniqueFileName = null;

            if (model.Photo != null)
            {
                string uploadsFolder = Path.Combine(_hostEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.Photo.CopyTo(fileStream);
                }
            }

            return(uniqueFileName);
        }
Ejemplo n.º 27
0
        public IActionResult AddStudent(int IdCourse)
        {
            AddStudentViewModel model = new AddStudentViewModel();
            var course = _courseService.GetCourse(IdCourse);

            model.Title    = course.Title;
            model.Students = _userService.GetAllUsersWithRoleNotInCourse("user", course.Id)
                             .Select(x => new Student
            {
                Add      = false,
                Id       = x.Id,
                Name     = x.Name,
                SurrName = x.Surrname
            })
                             .ToList();

            return(View(model));
        }
Ejemplo n.º 28
0
 public IHttpActionResult Put(long id, [FromBody] AddStudentViewModel model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest());
         }
         //var a= _iAddStudentService.UpdateStudent(id, model);
         //return Ok(a);
         _iAddStudentService.UpdateStudent(id, model);
         return(Created(new Uri(Request.RequestUri + "/" + model.Id), model));
     }
     catch
     {
         throw;
     }
 }
Ejemplo n.º 29
0
        public IActionResult AddStudent(AddStudentViewModel model)
        {
            Student student = new Student()
            {
                FirstName  = model.FirstName,
                LastName   = model.SecondName,
                FatherName = model.FatherName,
                Group      = model.Group,
                Faculty    = model.Faculty,
                Login      = model.Login,
                Password   = model.Password,
                Type       = Models.User.UserType.Student
            };

            dbContext.Students.Add(student);
            dbContext.SaveChanges();
            return(RedirectToAction("AddStudentG"));
        }
        public async Task <IActionResult> AddStudent(AddStudentViewModel model)
        {
            var user = await GetCurrentUserAsync();

            var newStudent = new Student {
                FirstName = model.FirstName, LastName = model.LastName, Grade = model.Grade, ApplicationUserId = user.Id
            };

            if (ModelState.IsValid && newStudent.ApplicationUserId != null)
            {
                context.Add(newStudent);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index", new RouteValueDictionary(
                                            new { controller = "Profile", action = "Index" })));
            }

            return(View(model));
        }
        public async Task <IHttpActionResult> CreateStudent([FromBody] AddStudentViewModel info)
        {
            #region Parameter validation

            if (info == null)
            {
                info = new AddStudentViewModel();
                Validate(info);
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            #endregion

            var students = UnitOfWork.RepositoryStudent.Search();
            students =
                students.Where(x => x.Username.Equals(info.Username, StringComparison.InvariantCultureIgnoreCase));

            // Student exists.
            if (await students.AnyAsync())
            {
                return(ResponseMessage(
                           Request.CreateErrorResponse(HttpStatusCode.Conflict, HttpMessages.CannotBeDuplicated)));
            }

            var student = new Database.Models.Entities.Student()
            {
                Username = info.Username,
                Password = IdentityService.HashPassword(info.Password),
                Fullname = info.Fullname,
                Gender   = info.Gender,
                Phone    = info.Phone,
                Status   = MasterItemStatus.Active
            };

            student = UnitOfWork.RepositoryStudent.Insert(student);

            await UnitOfWork.CommitAsync();

            return(Ok(student));
        }
Ejemplo n.º 32
0
 public IHttpActionResult AddStudentToWaitingList(int id, [FromBody] AddStudentViewModel student)
 {
     try
     {
         return(Content(HttpStatusCode.OK, _service.AddStudentToWaitingList(id, student)));
     }
     catch (NotFoundException)
     {
         return(StatusCode(HttpStatusCode.NotFound));
     }
     catch (PreconditionFailedException)
     {
         return(StatusCode(HttpStatusCode.PreconditionFailed));
     }
     catch (DbException)
     {
         return(InternalServerError());
     }
 }
Ejemplo n.º 33
0
        public bool AddStudentToCourse(AddStudentViewModel model, int id)
        {
            if (isCourseFull(id))
            {
                return(false);
            }

            CourseStudent current = (from x in _db.CourseStudents
                                     where x.CourseID == id && x.StudentSSN == model.SSN
                                     select x).SingleOrDefault();

            //if student is on the waiting list it should be removed when added to course
            StudentInWaitinglist waiting = (from x in _db.Waitinglist
                                            where x.CourseID == id && x.StudentSSN == model.SSN
                                            select x).SingleOrDefault();

            if (waiting != null)
            {
                _db.Waitinglist.Remove(waiting);
                _db.SaveChanges();
            }

            if (current == null)
            {
                var entry = new CourseStudent {
                    CourseID   = id,
                    StudentSSN = model.SSN,
                    Active     = true
                };

                _db.CourseStudents.Add(entry);
                _db.SaveChanges();
                return(true);
            }

            else if (current.Active == false)
            {
                current.Active = true;
                _db.SaveChanges();
                return(true);
            }
            return(false);
        }
Ejemplo n.º 34
0
        public async Task <IActionResult> StudentUpdate([FromBody] AddStudentViewModel vm)
        {
            var student = await _studentRepository.GetStudentByName(vm.StudentName);

            var studentModel = new Student
            {
                StudentId      = student.StudentId,
                Email          = student.Email,
                FullName       = student.FullName,
                Gender         = student.Gender,
                EnrollmentDate = student.EnrollmentDate
            };

            var viewModel = new StudentViewModel
            {
                Student = studentModel
            };

            return(PartialView("_SelectedStudent", viewModel));
        }
Ejemplo n.º 35
0
        public IHttpActionResult AddStudent(int id,AddStudentViewModel student)
        {
            AddStudentDTO newStudent = new AddStudentDTO();
            newStudent.TemplateID = student.TemplateID;
            newStudent.Semester = student.Semester;
            newStudent.SSN = student.SSN;

            try
            {
                _context.AddStudentToCourse(newStudent);
                var location = Url.Link("StudentInCourse", new { id = id });
                return Created(location, student.SSN);
            }
            catch(Exception ex)
            {
                if (ex is KeyNotFoundException)
                    return NotFound();
                else
                    return InternalServerError();
            }
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Mehod that adds a student to the waiting list of a course 
        /// with a given ID. The attributes needed to add a student to  
        /// the waiting list are given with a view model class.
        /// </summary>
        /// <param name="id">ID of the course</param>
        /// <param name="model">Add student view model (ViewModel class)</param>
        /// <returns>The student that was added to the waiting list (DTO class)</returns>
        public List<StudentDTO> AddStudentToWaitingList(int id, AddStudentViewModel model)
        {
            var course = _db.Courses.SingleOrDefault(x => x.ID == id);
            var student = _db.Students.SingleOrDefault(x => x.SSN == model.SSN);
            if (course == null || student == null)
            {
                throw new AppObjectNotFoundException();
            }

            var studentsInCourse = _db.CourseStudents.SingleOrDefault(x => x.CourseID == id && x.StudentID == student.ID && x.IsActive == true);
            var studentInWaitingList = _db.WaitingLists.SingleOrDefault(x => x.CourseID == id && x.StudentID == student.ID);
            if (studentsInCourse != null || studentInWaitingList != null)
            {
                throw new AppObjectIllegalAddException();
            }

            var waitingList = new WaitingListEntry
            {
                CourseID = course.ID,
                StudentID = student.ID
            };

            _db.WaitingLists.Add(waitingList);
            _db.SaveChanges();

            var result = GetCourseWaitingList(id);

            return result;
        }
Ejemplo n.º 37
0
 public IHttpActionResult AddStudentToWaitingList(int id, AddStudentViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var result = _service.AddStudentToWaitingList(id, model);
             return Ok(result);
         }
         catch (AppObjectNotFoundException)
         {
             return StatusCode(HttpStatusCode.NotFound);
         }
         catch(AppObjectIllegalAddException)
         {
             return StatusCode(HttpStatusCode.PreconditionFailed);
         }
     }
     else
     {
         return StatusCode(HttpStatusCode.PreconditionFailed);
     }
 }