public IActionResult UpdateCourse(long Id)
        {
            if (Id.Equals(0))
            {
                ViewBag.ErrorMessage = $"The Course resource with Id = { Id } could not be found";
                return(View("NotFound"));
            }
            Course course = entityRepository.GetById(Id);

            if (course == null)
            {
                ViewBag.ErrorMessage = $"The Course with Id = { Id } could not be found";
                return(View("NotFound"));
            }
            UpdateCourseViewModel model = new UpdateCourseViewModel
            {
                Id           = course.Id,
                CourseCode   = course.CourseCode,
                CourseName   = course.CourseName,
                CourseYearId = course.CourseYearId,
                DepartmentId = course.DepartmentId
            };

            GetAllCourseYears(model);
            GetAllDepartments(model);
            return(PartialView(model));
        }
        public async Task <IActionResult> UpdateCourse([FromBody] UpdateCourseViewModel course)
        {
            var result = await _MongocourseService.UpdateCourse(course);

            if (result)
            {
                return(Ok(new { Status = 1, Message = "Updated Successfuly" }));
            }
            return(BadRequest(new { Status = 0, Message = "Failed to Update" }));
        }
        public async Task <IActionResult> UpdateCourse([FromBody] UpdateCourseViewModel updateCourseView)
        {
            var       updateCourse = _mapper.Map <UpdateCourseDTO>(updateCourseView);
            CourseDTO course       = await _courseService.UpdateCourse(updateCourse);

            if (course == null)
            {
                return(BadRequest("Not updated"));
            }
            return(Ok(_mapper.Map <CourseViewModel>(new CourseDTO())));
        }
Example #4
0
        public async Task <IActionResult> UpdateCourse(long courseId, [FromBody] UpdateCourseViewModel courseViewModel)
        {
            await _coursesService.UpdateAsync(courseId, new Course()
            {
                Name       = courseViewModel.Name,
                GroupName  = courseViewModel.GroupName,
                IsComplete = courseViewModel.IsComplete,
                IsOpen     = courseViewModel.IsOpen
            });

            return(Ok());
        }
Example #5
0
        public async Task <IActionResult> Update(UpdateCourseViewModel model, int page)
        {
            if (this.ModelState.IsValid)
            {
                await _courseService.UpdateAsync(new UpdateCourseRequest { CourseId = model.CourseId, Name = model.Name });

                _toastNotification.AddSuccessToastMessage("The course was updated.");

                return(RedirectToAction("ManageCourses", new { page }));
            }

            return(View(model));
        }
        /// <summary>
        /// Updates course start and end date
        /// Throws AppObjectNotFound if course does not exist
        /// </summary>
        /// <param name="id">Id of course that you want to update</param>
        /// <param name="c">New Start and end Date</param>
        public void UpdateCourseByID(int id, UpdateCourseViewModel c)
        {
            Debug.Print("Inside update course by id factory");
            var results = _db.Courses.SingleOrDefault(x => x.ID == id);

            if (results == null)
            {
                throw new AppObjectNotFoundException();
            }
            results.StartDate = c.StartDate;
            results.EndDate   = c.EndDate;

            _db.SaveChanges();
        }
Example #7
0
        public IActionResult UpdateCourseInfo(int id, [FromBody] UpdateCourseViewModel model)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                _service.UpdateCourseInfo(id, model);
                return(new NoContentResult());
            }
            catch (AppObjectNotFoundException) { return(new NotFoundResult()); }
        }
Example #8
0
        public IActionResult UpdateCourseDates(int id, [FromBody] UpdateCourseViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestResult());
            }

            try
            {
                _service.UpdateCourseDates(id, model.StartDate, model.EndDate);
                return(new NoContentResult());
            }
            catch (AppObjectNotFoundException) { return(new NotFoundResult()); }
        }
Example #9
0
        public async Task <bool> UpdateCourse(UpdateCourseViewModel course)
        {
            if (course == null)
            {
                return(false);
            }
            var OldCourse = await GetCourse(course.Id);

            OldCourse.Name = course.Name;
            OldCourse.Doctors.SingleOrDefault().Id   = course.DrId;
            OldCourse.Doctors.SingleOrDefault().Name = course.Name;
            var result = await _course.ReplaceOneAsync(x => x.Id == course.Id, OldCourse);

            return(result.IsAcknowledged);
        }
Example #10
0
        /// <summary>
        /// Updates the only mutable attributes (StartDate, EndDate and MaxStudents)
        /// of a course with 'id' as it's Id. Throws an AppObjectNotFoundException
        /// if a course isn't found.
        /// </summary>
        /// <param name="cId">The course's Id</param>
        /// <param name="model">The UpdateCourseViewModel with the new values</param>
        /// <exception cref="AppObjectNotFoundException" />
        public void UpdateCourseInfo(int cId, UpdateCourseViewModel model)
        {
            var course = (from c in _db.Courses
                          where c.Id == cId
                          select c).SingleOrDefault();

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

            course.StartDate   = Convert.ToDateTime(model.StartDate);
            course.EndDate     = Convert.ToDateTime(model.EndDate);
            course.MaxStudents = model.MaxStudents;
            _db.SaveChanges();
        }
Example #11
0
        public IHttpActionResult UpdateCourse(int id, UpdateCourseViewModel editedCourse)
        {
            if (!ModelState.IsValid || editedCourse.StartDate.Equals(DateTime.MinValue) || editedCourse.EndDate.Equals(DateTime.MinValue))
            {
                throw new HttpResponseException(HttpStatusCode.PreconditionFailed);
            }

            try
            {
                CourseDetailsDTO course = _service.UpdateCourse(id, editedCourse);
                var location            = Url.Link("GetCourse", new { id = course.ID });
                return(Created(location, course));
            }
            catch (CourseNotFoundException)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
        }
Example #12
0
        public async Task <IActionResult> PutCourse(int id, UpdateCourseViewModel course)
        {
            var c = await _context.Course.FirstOrDefaultAsync(i => i.Id == id);

            if (course.Sigla != null)
            {
                c.Sigla = course.Sigla;
            }
            if (course.Designacao != null)
            {
                c.Designacao = course.Designacao;
            }

            _context.Update(c);
            await _context.SaveChangesAsync();

            return(Ok(c));
        }
Example #13
0
        /// <summary>
        /// Updates a course that already exists
        /// Note that this edits a Course, not a CourseTemplate.
        /// Only start and end date are editable
        /// </summary>
        /// <param name="courseID">The ID of the course to edit</param>
        /// <param name="updateCourse">a course with the information to edit</param>
        /// <returns></returns>
        public CourseDetailsDTO UpdateCourse(int courseID, UpdateCourseViewModel updateCourse)
        {
            // Get the course, throw exception if the course is not found
            Entities.Course course = _db.Courses.SingleOrDefault(x => x.ID == courseID);
            if (course == null)
            {
                throw new CourseNotFoundException();
            }

            // Check if the course tamplate exists
            var courseTemplate = _db.CourseTemplates.SingleOrDefault(x => x.ID == course.TemplateID);

            if (courseTemplate == null)
            {
                throw new TemplateCourseNotFoundException();
            }

            // Update the start and end date based on the view model
            course.StartDate = updateCourse.StartDate;
            course.EndDate   = updateCourse.EndDate;

            // If all is successfull, we save our changes
            _db.SaveChanges();

            return(new CourseDetailsDTO
            {
                ID = course.ID,
                TemplateID = courseTemplate.TemplateID,
                Name = courseTemplate.Name,
                Description = courseTemplate.Description,
                Semester = course.Semester,
                StartDate = updateCourse.StartDate,
                EndDate = updateCourse.EndDate,
                StudentCount = _db.StudentEnrollment.Count(x => x.CourseID == course.ID),
                Students = (from sr in _db.StudentEnrollment
                            join s in _db.Students on sr.StudentID equals s.ID
                            where sr.CourseID == course.ID
                            select new StudentDTO
                {
                    SSN = s.SSN,
                    Name = s.Name
                }).ToList()
            });
        }
Example #14
0
 public IHttpActionResult UpdateCourseByID(int id, UpdateCourseViewModel model)
 {
     Debug.Print("hehe");
     if (ModelState.IsValid)
     {
         try
         {
             //var result = _service.UpdateCourseByID(id, model);
             //return Content(HttpStatusCode.OK, result);
             _service.UpdateCourseByID(id, model);
             return(Ok());
         }
         catch (AppObjectNotFoundException)
         {
             return(NotFound());
         }
     }
     else
     {
         return(StatusCode(HttpStatusCode.PreconditionFailed));
     }
 }
Example #15
0
        public CourseModel UpdateCourse(UpdateCourseViewModel viewModel)
        {
            var course = new CourseModel
            {
                ID           = viewModel.ID,
                CategoryName = viewModel.Category,
                CompanyID    = principalProvider.Principal.CompanyID,
                Name         = viewModel.Name,
                Description  = viewModel.Description,
                Price        = viewModel.Price,
                Weight       = viewModel.Weight
            };

            var updatedCourse = this.courseService.UpdateCourse(course);

            if (!string.IsNullOrEmpty(viewModel.ImageId))
            {
                imageService.UpdateCoursePicture(viewModel.ImageId, updatedCourse.CompanyID, updatedCourse.ID);
            }

            return(updatedCourse);
        }
 public IActionResult UpdateCourse(UpdateCourseViewModel model)
 {
     if (ModelState.IsValid)
     {
         Course course = entityRepository.GetById(model.Id);
         if (course == null)
         {
             ViewBag.ErrorMessage = $"The Course Resource with Id = { model.Id } could not be found";
             return(View("NotFound"));
         }
         course.CourseCode   = model.CourseCode;
         course.CourseName   = model.CourseName;
         course.CourseYearId = model.CourseYearId;
         course.DepartmentId = model.DepartmentId;
         entityRepository.Update(course);
         entityRepository.Save();
         return(Json(new { success = true }));
     }
     GetAllCourseYears(model);
     GetAllDepartments(model);
     return(PartialView(model));
 }
        public IHttpActionResult UpdateCourse(int id, [FromBody] UpdateCourseViewModel course)
        {
            CourseDetailDTO input = new CourseDetailDTO();

            input.ID        = id;
            input.StartDate = course.NewStartDate;
            input.EndDate   = course.NewEndDate;

            try
            {
                _context.UpdateCourse(input);
            }
            catch (Exception ex)
            {
                if (ex is KeyNotFoundException)
                {
                    return(NotFound());
                }
                return(InternalServerError());
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #18
0
 public void UpdateCourse([FromBody] UpdateCourseViewModel model, int id)
 {
     _service.UpdateCourse(model, id);
 }