Exemplo n.º 1
0
        public IHttpActionResult Post([FromBody] EnrollmentDto form)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var enrollment = Mapper.Map <EnrollmentDto, Enrollment>(form);

                    _enrollmentService.Add(enrollment);

                    var enrollmentDto = GetEnrollmentDto(enrollment);

                    return(Created(new Uri(enrollmentDto.Url), enrollmentDto));
                }
                catch (ArgumentException ae)
                {
                    ModelState.AddModelError("", ae.Message);
                }
                catch (PreexistingEntityException pe)
                {
                    ModelState.AddModelError("", pe.Message);
                }
            }

            return(BadRequest(ModelState));
        }
        public IHttpActionResult Put(int id, [FromBody] EnrollmentDto dto)
        {
            var Enrollment = _db.Enrollments.All().FirstOrDefault(x => x.EnrollmentID == id);

            if (Enrollment == null)
            {
                var errorMessage = string.Format("Enrollment with Id:{0} dosent exist", id);
                _logger.Error(errorMessage);
                NotFound();
            }

            try
            {
                Enrollment.StudentID = dto.StudentID;
                Enrollment.CourseID  = dto.CourseID;
                Enrollment.Grade     = dto.Grade;

                _db.Enrollments.Update(Enrollment);
                _db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            string message = string.Format("Enrollment with id {0} was updated", id);

            _logger.Info(message);
            return(Ok(message));
        }
        public async Task <IActionResult> PutEnrollment(int studentId, EnrollmentDto enrollmentDto)
        {
            if (studentId != enrollmentDto.StudentId)
            {
                return(BadRequest(new { studentId = "Student Id is required and must match request body." }));
            }

            Course course = await _repository.GetCourse(enrollmentDto.CourseId);

            Student student = await _repository.GetStudent(studentId);

            if (course == null || student == null)
            {
                return(NotFound());
            }

            Enrollment enrollment = new Enrollment
            {
                Id      = enrollmentDto.EnrollmentId,
                Student = student,
                Course  = course
            };

            _repository.UpdateEnrollment(enrollment);
            await _repository.SaveAll();

            return(NoContent());
        }
 private Enrollment ConvertToEnrollment(EnrollmentDto enrollment)
 {
     return(new Enrollment()
     {
         EnrollmentID = enrollment.EnrollmentID,
         StudentID = enrollment.StudentID,
         CourseID = enrollment.CourseID,
         Grade = enrollment.Grade,
     });
 }
Exemplo n.º 5
0
        public bool AddPayment(EnrollmentDto objEnrollmentDto)
        {
            EnrollmentDal         objEnrollmentDal = new EnrollmentDal();
            ParticipantEnrollment objEnrollment    = new ParticipantEnrollment();

            objEnrollment.EnrollID      = objEnrollmentDto.EnrollId;
            objEnrollment.PaymentStatus = objEnrollmentDto.PaymentStatus;
            bool status = objEnrollmentDal.InsertPayment(objEnrollment);

            return(status);
        }
Exemplo n.º 6
0
        public async Task ListCoursesByStudent_ValidId_Ok()
        {
            var obj = new EnrollmentDto
            {
                CourseId  = 13,
                StudentId = 3
            };
            var actual = await _enrollmentLogic.EnrollStudent(obj);

            Assert.Greater(actual, 0);
        }
Exemplo n.º 7
0
        public void ListCoursesByStudent_InvalidStudent_Error()
        {
            var obj = new EnrollmentDto
            {
                CourseId  = 13,
                StudentId = 999
            };
            var ex = Assert.ThrowsAsync <ArgumentException>(async() => await _enrollmentLogic.EnrollStudent(obj));

            Assert.That(ex.Message, Is.EqualTo($"There's no student with studentId = {obj.StudentId}"));
        }
Exemplo n.º 8
0
        public bool AddEnrollment(EnrollmentDto objEnrollmentDto)
        {
            EnrollmentDal         objEnrollmentDal = new EnrollmentDal();
            ParticipantEnrollment objEnrollment    = new ParticipantEnrollment();

            objEnrollment.EnrollID      = objEnrollmentDto.EnrollId;
            objEnrollment.PaymentStatus = false;
            objEnrollment.EventID       = objEnrollmentDto.EnrollEventId;
            objEnrollment.UserID        = objEnrollmentDto.EnrollMemberId;
            bool status = objEnrollmentDal.InsertEnrollment(objEnrollment);

            return(status);
        }
        public IHttpActionResult CreateEnrollment(EnrollmentDto enrollmentDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Model is not valid. Check again!!!"));
            }

            var enrollment = Mapper.Map <EnrollmentDto, Enrollment>(enrollmentDto);

            _context.Enrollments.Add(enrollment);
            _context.SaveChanges();

            enrollmentDto.EnrollmentId = enrollment.EnrollmentId;
            return(Created(new Uri(Request.RequestUri + "/" + enrollment.EnrollmentId), enrollmentDto));
        }
Exemplo n.º 10
0
 // [HttpPost]
 public ActionResult Enrollment(int EventID)
 {
     //Session["eventid"] = EventID;
     if (Session["Uid"] != null)
     {
         EnrollmentDto objEnrollmentDto = new EnrollmentDto();
         objEnrollmentDto.EnrollMemberId = Convert.ToInt32(Session["Uid"]);
         objEnrollmentDto.EnrollEventId  = EventID;
         EnrollmenttManager objEnroll = new EnrollmenttManager();
         objEnroll.AddEnrollment(objEnrollmentDto);
         return(RedirectToAction("ShowEvent"));
     }
     else
     {
         return(RedirectToAction("Login"));
     }
 }
Exemplo n.º 11
0
        public bool AddPayment(EnrollmentDto objEnrollmentDto)
        {
            EnrollmentDal objEnrollmentDal = new EnrollmentDal();
            Enrollment    objEnrollment    = new Enrollment();

            objEnrollment.EnrollId       = objEnrollmentDto.EnrollId;
            objEnrollment.PaymentStatus  = objEnrollmentDto.PaymentStatus;
            objEnrollment.Skill1         = objEnrollmentDto.Skill1;
            objEnrollment.Skill2         = objEnrollmentDto.Skill2;
            objEnrollment.Skill3         = objEnrollmentDto.Skill3;
            objEnrollment.Comments       = objEnrollmentDto.Comments;
            objEnrollment.EnrollEventId  = objEnrollmentDto.EnrollEventId;
            objEnrollment.EnrollMemberId = objEnrollmentDto.EnrollMemberId;
            bool status = objEnrollmentDal.InsertPayment(objEnrollment);

            return(status);
        }
Exemplo n.º 12
0
        private void Save()
        {
            var dto = new EnrollmentDto
            {
                Id     = _studentId,
                Course = Course,
                Grade  = Grade
            };
            Result result = ApiClient.Enroll(dto).ConfigureAwait(false).GetAwaiter().GetResult();

            if (result.IsFailure)
            {
                CustomMessageBox.ShowError(result.Error);
                return;
            }

            DialogResult = true;
        }
Exemplo n.º 13
0
        public CriacaoDaMatriculaTest()
        {
            _cursoRepositorio     = new Mock <ICourseRepository>();
            _alunoRepositorio     = new Mock <IStudentRepository>();
            _matriculaRepositorio = new Mock <IEnrollmentRepository>();

            _aluno = StudentBuilder.New().WithId(23).WithTargetAudience(TargetAudience.Graduate).Build();
            _alunoRepositorio.Setup(r => r.GetById(_aluno.Id)).Returns(_aluno);

            _course = CursoBuilder.Novo().ComId(45).ComPublicoAlvo(TargetAudience.Graduate).Build();
            _cursoRepositorio.Setup(r => r.GetById(_course.Id)).Returns(_course);

            _enrollmentDto = new EnrollmentDto {
                StudentId = _aluno.Id, CourseId = _course.Id, PaidAmount = _course.Amount
            };

            _enrollmentCreation = new EnrollmentCreation(_alunoRepositorio.Object, _cursoRepositorio.Object, _matriculaRepositorio.Object);
        }
Exemplo n.º 14
0
        public IHttpActionResult Post([FromBody] EnrollmentDto dto)
        {
            try
            {
                var Enrollment = ConvertToEnrollment(dto);
                _db.Enrollments.Add(Enrollment);
                _db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            string message = string.Format("Enrollment with grade {0} was created", dto.Grade);

            _logger.Info(message);
            return(Ok(message));
        }
        public async Task <IActionResult> EnrollStudentInACourse([FromBody] EnrollmentDto enrollStudent)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(ValidationProblem("Invalid parameters"));
                }

                var enrollmentId = await _enrollmentLogic.EnrollStudent(enrollStudent);

                var actionName = ControllerContext.RouteData.Values["action"].ToString();
                return(CreatedAtAction(actionName, new { enrollmentId }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
        public IHttpActionResult UpdateEnrollment(int id, EnrollmentDto enrollmentDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Model is not valid. Check again!!!"));
            }

            var enrollmentInDb = _context.Enrollments.SingleOrDefault(c => c.EnrollmentId == id);

            if (enrollmentInDb == null)
            {
                return(NotFound());
            }

            Mapper.Map(enrollmentDto, enrollmentInDb);

            _context.SaveChanges();

            return(Ok("Enrollment updated successfully"));
        }
Exemplo n.º 17
0
            public async Task <IActionResult> EnrollStudent(EnrollmentModel model)
            {
                var enrollment = new EnrollmentDto()
                {
                    Birthdate   = model.Birthdate,
                    Email       = model.Email,
                    Studies     = model.Studies,
                    FirstName   = model.FirstName,
                    IndexNumber = model.IndexNumber,
                    LastName    = model.LastName
                };

                var result = await _enrollmentsService.EnrollStudent(enrollment);

                if (result.studiesExists is false)
                {
                    return(BadRequest("Studies does not exist"));
                }

                return(Ok());
            }
Exemplo n.º 18
0
        public async Task <int> EnrollStudent(EnrollmentDto enrollmentDto)
        {
            var course = await _courseRepository.GetById(enrollmentDto.CourseId);

            if (course == null)
            {
                throw new ArgumentException($"There's no course with courseId = {enrollmentDto.CourseId}");
            }

            var student = await _studentRepository.GetById(enrollmentDto.StudentId);

            if (student == null)
            {
                throw new ArgumentException($"There's no student with studentId = {enrollmentDto.StudentId}");
            }

            return(await _enrollmentRepository.Add(new Enrollment
            {
                CourseId = enrollmentDto.CourseId,
                StudentId = enrollmentDto.StudentId
            }));
        }
Exemplo n.º 19
0
        // GET: Student/OfferingEnrollments/Enrollment
        public async Task <ActionResult> Enrollment(int?offeringId)
        {
            if (!offeringId.HasValue)
            {
                return(HttpNotFound());
            }

            try
            {
                var studentId = SessionHelper.User.UserId;

                var enrollment = new EnrollmentDto
                {
                    StudentId  = studentId,
                    OfferingId = offeringId.Value
                };

                await _enrollmentRepository.PostEnrollment(enrollment);

                var offering = await _offeringRepository.GetOfferingById(offeringId.Value);

                // Add properties to layout
                AddPageHeader("Enrollment confirmed", "");

                AddBreadcrumb("Enroll (Offerings)", "");
                AddBreadcrumb("Enrollment confirmed", "");
                //Enrollment confirmed

                return(View(offering));
            }
            catch (BadRequestException bre)
            {
                AddPageAlerts(ViewHelpers.PageAlertType.Error, GetErrorsFromAdycHttpExceptionToString(bre));
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 20
0
 public ActionResult Enrollment(EnrollmentDto objEnrollmentDto)
 {
     return(RedirectToAction("ShowEvent"));
 }
Exemplo n.º 21
0
        public EnrollmentDto Promote(PromotionDto promotionDto)
        {
            var enrollment = new EnrollmentDto();

            using (SqlConnection connection = new SqlConnection(ConString))
                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection = connection;
                    connection.Open();
                    var transaction = connection.BeginTransaction();
                    command.Transaction = transaction;
                    SqlDataReader dataReader = null;

                    try
                    {
                        command.CommandText = "select IdStudy " +
                                              "from studies " +
                                              "where name = @studies ";
                        command.Parameters.AddWithValue("studies", promotionDto.Studies);

                        dataReader = command.ExecuteReader();
                        if (!dataReader.Read())
                        {
                            throw new NotFoundException("Study doesn't exist: " + promotionDto.Studies);
                        }
                        dataReader.Close();

                        command.CommandText = "select e.IdEnrollment, s.IdStudy, e.Semester, e.StartDate " +
                                              "from enrollment e " +
                                              "join studies s on e.IdStudy = s.IdStudy " +
                                              "where s.name = @studies2 " +
                                              " and e.semester = @semester2";
                        command.Parameters.AddWithValue("studies2", promotionDto.Studies);
                        command.Parameters.AddWithValue("semester2", promotionDto.Semester);

                        dataReader = command.ExecuteReader();
                        if (!dataReader.Read())
                        {
                            throw new NotFoundException("Semester for selected studies doesn't exist: semester-" + promotionDto.Semester + ", studies-" + promotionDto.Studies);
                        }
                        else
                        {
                            dataReader.Close();
                            command.CommandText = "exec promotions @Studies3, @Semester3";
                            command.Parameters.AddWithValue("Studies3", promotionDto.Studies);
                            command.Parameters.AddWithValue("Semester3", promotionDto.Semester);
                            dataReader = command.ExecuteReader();

                            if (dataReader.Read())
                            {
                                enrollment = new EnrollmentDto()
                                {
                                    IdEnrollment = dataReader["IdEnrollment"].ToString(),
                                    Semester     = dataReader["Semester"].ToString(),
                                    IdStudy      = dataReader["IdStudy"].ToString(),
                                    StartDate    = dataReader["StartDate"].ToString()
                                };
                            }

                            dataReader.Close();
                            transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        if (dataReader != null)
                        {
                            dataReader.Close();
                            transaction.Rollback();
                        }
                        throw e;
                    }
                }

            return(enrollment);
        }
Exemplo n.º 22
0
        public EnrollmentDto EnrollStudent(EnrollStudentDto newStudent)
        {
            var enrollment = new EnrollmentDto();

            using (SqlConnection connection = new SqlConnection(ConString))
                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection = connection;
                    connection.Open();
                    var transaction = connection.BeginTransaction();
                    command.Transaction = transaction;
                    SqlDataReader dataReader = null;

                    try
                    {
                        command.CommandText = "select IdStudy " +
                                              "from studies " +
                                              "where name = @name ";
                        command.Parameters.AddWithValue("name", newStudent.Studies);

                        dataReader = command.ExecuteReader();
                        if (!dataReader.Read())
                        {
                            throw new BadRequestException("Study doesn't exist: " + newStudent.Studies);
                        }

                        if (GetStudent(newStudent.IndexNumber) != null)
                        {
                            throw new BadRequestException("Index number already taken: " + newStudent.IndexNumber);
                        }

                        var idStudy = dataReader["IdStudy"].ToString();
                        dataReader.Close();

                        command.CommandText = "select * " +
                                              "from Enrollment " +
                                              "where IdStudy=@idStudy " +
                                              "   and Semester=1 ";
                        command.Parameters.AddWithValue("idStudy", idStudy);
                        dataReader = command.ExecuteReader();

                        string idEnrollment;
                        string startDate;

                        if (dataReader.Read())
                        {
                            idEnrollment = dataReader["IdEnrollment"].ToString();
                            startDate    = dataReader["StartDate"].ToString();
                        }
                        else
                        {
                            dataReader.Close();
                            command.CommandText = "select max(IdEnrollment) as MaxIdEnrollment " +
                                                  "from Enrollment ";
                            dataReader.Read();
                            idEnrollment = (int.Parse(dataReader["currentMax"].ToString()) + 1).ToString();
                            startDate    = "2020-03-29";
                            dataReader.Close();

                            command.CommandText = "insert into Enrollment(IdEnrollment, Semester, IdStudy, StartDate) " +
                                                  "values(@newId, @Semester, @IdStudy, @StartDate) ";
                            command.Parameters.AddWithValue("newId", idEnrollment);
                            command.Parameters.AddWithValue("IdStudy", idStudy);
                            command.Parameters.AddWithValue("Semester", 1);
                            command.Parameters.AddWithValue("StartDate", startDate);
                            command.ExecuteNonQuery();
                        }
                        dataReader.Close();

                        command.CommandText = "insert into Student (IndexNumber, FirstName, LastName, BirthDate, IdEnrollment) " +
                                              "values(@IndexNumber, @FirstName, @LastName, @BirthDate, @IdEnrollment) ";
                        command.Parameters.AddWithValue("IndexNumber", newStudent.IndexNumber);
                        command.Parameters.AddWithValue("FirstName", newStudent.FirstName);
                        command.Parameters.AddWithValue("LastName", newStudent.LastName);
                        command.Parameters.AddWithValue("BirthDate", newStudent.BirthDate);
                        command.Parameters.AddWithValue("IdEnrollment", idEnrollment);
                        command.ExecuteNonQuery();

                        enrollment = new EnrollmentDto()
                        {
                            IdEnrollment = idEnrollment,
                            Semester     = "1",
                            IdStudy      = idStudy,
                            StartDate    = startDate
                        };

                        transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        if (dataReader != null)
                        {
                            dataReader.Close();
                            transaction.Rollback();
                        }
                        throw e;
                    }
                }

            return(enrollment);
        }
Exemplo n.º 23
0
 public IActionResult Salvar(EnrollmentDto model)
 {
     _enrollmentCreation.Create(model);
     return(Ok());
 }
Exemplo n.º 24
0
 public EnrollmentDetailsViewModel(EnrollmentDto enrollment)
 {
     Enrollment = enrollment;
 }
Exemplo n.º 25
0
 public IEnrollment convert(EnrollmentDto enrollmentDto)
 {
     throw new System.NotImplementedException();
 }