예제 #1
0
        public IActionResult UpdateCourse(int id, [FromBody] CourseUpdate coursedt)
        {
            CoursesDTO course = new CoursesDTO();

            if (ModelState.IsValid)
            {
                try
                {
                    course = _service.UpdateCourse(id, coursedt);
                }
                catch (AppObjectNotFoundException)
                {
                    return(NotFound());
                }
                catch (FailedToSaveToDatabaseException)
                {
                    return(StatusCode(500));
                }
            }
            else
            {
                return(BadRequest());
            }
            return(NoContent());
        }
        private void dgvCourses_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int             columnIndex = e.ColumnIndex;
            int             rowIndex    = e.RowIndex;
            Course          course      = new Course();
            DataGridViewRow row         = dgvCourses.Rows[rowIndex];

            course.ID                = Convert.ToInt32(row.Cells["colID"].Value.ToString());
            course.CourseNumber      = row.Cells["colCourseNumber"].Value.ToString();
            course.CourseName        = row.Cells["colCourseName"].Value.ToString();
            course.CourseDescription = row.Cells["colCourseDescription"].Value.ToString();
            course.Credits           = Convert.ToInt32(row.Cells["colCredits"].Value.ToString());
            switch (columnIndex)
            {
            case 6:
                CourseUpdate updateView = new CourseUpdate(_courseViewModel, course);
                updateView.ShowDialog();
                if (updateView.Success)
                {
                    LoadData();
                }
                break;

            case 7:
                break;

            default:
                break;
            }
        }
        // Update course 
        public static CourseUpdate.Response Handle(IRepository repository, CourseUpdate.Request request)
        {
            var container = CourseFactory.CreatePartial(request.CommandModel.CourseID).Modify(request.CommandModel);
            var validationDetails = repository.Save(container);

            return new CourseUpdate.Response(validationDetails);
        }
예제 #4
0
        public async Task <CourseUpdate> UpdateBasic(int courseId, CourseUpdate model)
        {
            var course = await context.Course.FirstOrDefaultAsync(_ => _.Id == courseId);

            if (course == null)
            {
                throw new ValidationException("Requested course doesn't exist.");
            }

            course.Name = model.Name;

            var errors = course.Validate();

            if (errors.Any())
            {
                throw new ValidationPropertyException(errors);
            }

            await context.SaveChangesAsync();

            return(new CourseUpdate
            {
                Id = course.Id,
                Name = course.Name
            });
        }
        public void UpdateCourse(CourseUpdate courseUpdate)
        {
            var course = this.GetCourseById(courseUpdate.Id);

            this.mapper.Map(courseUpdate, course);

            context.SaveChanges();
        }
예제 #6
0
        public IActionResult PutCourse(int id, CourseUpdate model)
        {
            var choose = _context.Course.Find(id);

            choose.InjectFrom(model);
            _context.SaveChanges();
            return(NoContent());
        }
예제 #7
0
        public async Task <IActionResult> Put(Guid id, CourseUpdate command)
        {
            command.Id = id;

            await Dispatcher.SendAsync(command);

            return(NoContent());
        }
예제 #8
0
        public EntityStateWrapperContainer Modify(CourseUpdate.CommandModel commandModel)
        {
            CourseID = commandModel.CourseID;
            DepartmentID = commandModel.DepartmentID;
            Credits = commandModel.Credits;
            Title = commandModel.Title;

            return new EntityStateWrapperContainer().ModifyEntity(this);
        }
        public async Task<ActionResult> Edit(CourseUpdate.CommandModel commandModel)
        {
            var request = new CourseUpdate.Request(SystemPrincipal.Name, commandModel);
            var response = DomainServices.Dispatch(request);

            if (!response.HasValidationIssues)
                return RedirectToAction("Index");

            ModelState.AddRange(response.ValidationDetails.AllValidationMessages);
            ViewBag.DepartmentID = await CreateDepartmentSelectList(commandModel.DepartmentID);
            return View(commandModel);
        }
        public void Renamed(object sender, RenamedEventArgs e)
        {
            var deletedCourseUpdate = new CourseUpdate(e.OldFullPath);

            courseUpdateQuery.RegisterDelete(deletedCourseUpdate);

            var courseUpdate = BuildCourseUpdateByFileSystemEvent(e);

            courseUpdateQuery.RegisterCreate(courseUpdate);

            debouncedSendUpdates();
        }
예제 #11
0
        // Update specific item
        public CourseUpdate UpdateCourse(CourseUpdate updatedCourse)
        {
            var p = ds.Courses.Find(updatedCourse.Id);

            if (p == null)
            {
                return(null);
            }
            else
            {
                // For the object fetched from the data store,
                // set its values to those provided
                // (the method ignores missing properties, and navigation properties)
                ds.Entry(p).CurrentValues.SetValues(updatedCourse);
                ds.SaveChanges();
                return(updatedCourse);
            }
        }
예제 #12
0
        public async Task <IActionResult> PutCourse([FromRoute] int id, [FromBody] CourseUpdate request)
        {
            Course course = await _em.Courses.GetAsync(id);

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

            if (!await UserHasCourse(course))
            {
                return(Forbid());
            }

            if (request.Name != null)
            {
                course.Name = request.Name;
                await _em.FlushAsync();
            }

            return(Ok());
        }
예제 #13
0
        /// <summary>
        /// Allows us to update the startdate and endate and the maxStudents value of the course.
        /// </summary>
        /// <param name="id">The id of the course we want to update</param>
        /// <param name="coursedt">instance of CourseUpdate that we can get startdate, enddate and MaxStudents</param>
        /// <returns>The course we created or FailedToSaveToDatabaseException() if we can't save to the database</returns>
        public CoursesDTO UpdateCourse(int id, CourseUpdate coursedt)
        {
            var courseToUpdate = (from x in _db.Courses
                                  where x.ID == id
                                  select x).SingleOrDefault();

            if (courseToUpdate == null)
            {
                throw new AppObjectNotFoundException();
            }
            else
            {
                courseToUpdate.StartDate   = coursedt.StartDate;
                courseToUpdate.EndDate     = coursedt.EndDate;
                courseToUpdate.MaxStudents = coursedt.MaxStudents;

                try
                {
                    _db.SaveChanges();
                }
                catch (System.Exception)
                {
                    throw new FailedToSaveToDatabaseException();
                }
            }

            var courseToReturn = (from x in _db.Courses
                                  where x.ID == id
                                  select  new CoursesDTO {
                ID = x.ID,
                TemplateID = x.TemplateID,
                Semester = x.Semester,
                StartDate = x.StartDate,
                EndDate = x.EndDate,
                MaxStudents = x.MaxStudents
            }).SingleOrDefault();

            return(courseToReturn);
        }
예제 #14
0
 public static CourseUpdateableModel MapCourseUpdateableModel(this CourseUpdateableModel dest, CourseUpdate source)
 {
     dest.Name = source.Name;
     return(dest);
 }
 public void Update(CourseUpdate courseUpdate)
 {
     courseService.UpdateCourse(courseUpdate);
 }
        private ICourseUpdate BuildCourseUpdateByFileSystemEvent(FileSystemEventArgs fileSystemEventArgs)
        {
            var courseUpdate = new CourseUpdate(fileSystemEventArgs.FullPath);

            return(courseUpdate);
        }
 public void UpdateCourse(CourseUpdate courseUpdate)
 {
     courseRepository.UpdateCourse(courseUpdate);
 }