Ejemplo n.º 1
0
        public void Edit_WithValidCourseObject_ReturnsCourse()
        {
            var course = new Course()
            {
                Id                  = 1,
                Category            = Category.A,
                Description         = "TestDesc",
                MinimumLessonsCount = 20,
                Price               = 100,

                TrainerId = 1,
                CarId     = 1,
                SchoolId  = 1
            };

            var returnValue = new List <Course>()
            {
                course
            };

            this.repository.Setup(r => r.All()).Returns(returnValue.AsQueryable);

            this.repository.Setup(r => r.Update(course)).Callback(() => new Course()
            {
                Id                  = 1,
                Category            = Category.A,
                Description         = "TestDescNew",
                MinimumLessonsCount = 40,
                Price               = 200,
                TrainerId           = 2,
                CarId               = 2,
                SchoolId            = 1
            });

            var model = new EditCourseInputModel()
            {
                Id                  = 1,
                Description         = "TestDescNew",
                MinimumLessonsCount = 40,
                Price               = 200,
                TrainerId           = 2,
                CarId               = 2,
            };

            var result = this.courseService.Edit(model).GetAwaiter().GetResult();

            Assert.That(result.Description, Is.EqualTo("TestDescNew"));
            Assert.That(result.MinimumLessonsCount, Is.EqualTo(40));
            Assert.That(result.Price, Is.EqualTo(200));
            Assert.That(result.Id, Is.EqualTo(1));
            Assert.That(result.TrainerId, Is.EqualTo(2));
            Assert.That(result.CarId, Is.EqualTo(2));

            Assert.That(result.SchoolId, Is.EqualTo(1));
            Assert.That(result, Is.TypeOf <Course>());
        }
        public async Task <IActionResult> Edit(EditCourseInputModel input, int id)
        {
            if (!this.ModelState.IsValid)
            {
                input.SubjectsItems = this.subjectsService.GetAllAsSelectListItems();
                return(this.View(input));
            }

            input.Id = id;
            await this.coursesService.UpdateAsync(input);

            this.TempData["Message"] = "Course updated successfully!";

            return(this.Redirect($"/Courses/AllUnapproved"));
        }
Ejemplo n.º 3
0
        public async Task <Course> Edit(EditCourseInputModel model)
        {
            var course = this.GetCourseById(model.Id);

            course.CarId               = model.CarId;
            course.TrainerId           = model.TrainerId;
            course.Price               = model.Price;
            course.Description         = model.Description;
            course.MinimumLessonsCount = model.MinimumLessonsCount;

            this.courseRepository.Update(course);
            await this.courseRepository.SaveChangesAsync();

            return(course);
        }
        public async Task UpdateAsync(EditCourseInputModel input)
        {
            Course course = this.coursesRepository.All().FirstOrDefault(c => c.Id == input.Id);

            course.Name        = input.Name;
            course.Description = input.Description;
            course.Price       = input.Price;
            course.StartDate   = input.StartDate;
            course.EndDate     = input.EndDate;
            course.SubjectId   = input.SubjectId;

            await this.coursesRepository.SaveChangesAsync();

            await this.courseTagsRepository.SaveChangesAsync();

            await this.courseLecturersRepository.SaveChangesAsync();
        }
        public IActionResult Edit(int id)
        {
            //EditCourseInputModel input = new EditCourseInputModel
            //{
            //    Id = id,
            //    Name = this.coursesService.GetNameById(id),
            //    Description = this.coursesService.GetDescriptionById(id),
            //    Price = this.coursesService.GetPriceById(id),
            //    StartDate = this.coursesService.GetStartDateById(id),
            //    EndDate = this.coursesService.GetEndDateById(id),
            //    SubjectId = this.coursesService.GetSubjectIdById(id),
            //    SubjectsItems = this.subjectsService.GetAllAsSelectListItems(),
            //};

            EditCourseInputModel input = this.coursesService.GetById <EditCourseInputModel>(id);

            input.SubjectsItems = this.subjectsService.GetAllAsSelectListItems();

            return(this.View(input));
        }
        public ActionResult Edit(EditCourseInputModel model)
        {
            try
            {
                if (!this.ModelState.IsValid)
                {
                    return(this.View(model));
                }

                if (!this.HasRights(model.Id))
                {
                    throw new OperationCanceledException("You do not have rights for this operation!");
                }

                model.Username = this.User.Identity.Name;
                var course = this.courseService.Edit(model).GetAwaiter().GetResult();
                return(this.RedirectToAction("Details", "Courses", new { Area = "", id = course.Id }));
            }
            catch (Exception e)
            {
                return(this.View("_Error", e.Message));
            }
        }