public void ShouldAddCourse() { _courseService.Add(_courseDto); //_courseRepositoryMock.Verify(r => r.Add(It.IsAny<Course>()), Times.AtLeast(1)); _courseRepositoryMock.Verify(r => r.Add( It.Is <Course>( c => c.Name == _courseDto.Name && c.Description == _courseDto.Description ))); }
public void Add_WhenAdded_CourseWillGetNewId() { // arrange var expectedId = 10; var courseToAdd = new Course() { Id = expectedId, Name = "Swimming", CourseType = _externalCT, CourseTypeId = _externalCT.Id, IsDeleted = false }; _courseRepository.Setup(m => m.Add(It.IsAny <Course>())) .Callback((Course c) => { c.Id = expectedId; }); var courseService = new CourseService(_courseRepository.Object); courseService.CourseTypeService = _courseTypeService.Object; // act courseService.Add(courseToAdd); // assert _courseRepository.Verify(cr => cr.Add(courseToAdd)); Assert.That(courseToAdd.Id, Is.EqualTo(expectedId)); }
public IActionResult Add([FromBody] CourseInfo item) { if (ModelState.IsValid) { var dbCompany = _courseService.Add(item); return(Ok(dbCompany)); } return(BadRequest(ModelState)); }
public ActionResult <int> Post() { CourseDto course = new CourseDto(); string jsonCourse = HttpContext.Request.Form["model"]; course = Newtonsoft.Json.JsonConvert.DeserializeObject <CourseDto>(jsonCourse); var files = Request.Form.Files.Count() > 0 ? Request.Form.Files.ToList() : null; return(_courseService.Add(course, files)); }
public void Add_CourseIsNull_ArgumentNullExceptionWillBeThrown() { // arrange var courseService = new CourseService(_courseRepository.Object); courseService.CourseTypeService = _courseTypeService.Object; // act and assert Assert.Throws <ArgumentNullException>(() => courseService.Add(null)); }
public ActionResult Create(Course course) { try { courseService.Add(course); return(RedirectToAction("Index")); } catch { return(View()); } }
public IActionResult Add(NewCourseViewModel model) { var success = service.Add( Utility.GetUserContext().UserId, model.SubjectId, model.Title, model.Image, model.Content, model.Remarks, model.Objective); return(Ok(success)); }
public ActionResult AddCourse(CourseDTO newCourse) { if (!ModelState.IsValid) { return(View()); } string title = newCourse.Title; string description = newCourse.Description; var course = CourseService.Add(title, description); return(RedirectToAction("Course", new { courseId = course.Id })); }
public async Task <IHttpActionResult> PostCourse(CourseCreateViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var course = await _courses.Add(new Course { Title = model.Title, Credits = model.Credits, DepartmentId = model.DepartmentId }); return(CreatedAtRoute("DefaultApi", new { id = course.Id }, (CourseResultViewModel)course)); }
public IActionResult Add(CourseDto model) { try { _courseService.Add(model); } catch (DomainException exception) { return(new JsonResult(exception.ListOfRules)); } catch (Exception ex) { return(new JsonResult(ex.Message)); } return(Ok()); }
public async Task <ActionResult> Create([Bind(Include = "CourseId,Title,Credits,DepartmentId")] Course course) { if (ModelState.IsValid) { try { await _courseService.Add(course); return(RedirectToAction("Index")); } catch (RetryLimitExceededException) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } } await PopulateDepartmentDropDown(course.DepartmentId); return(View(course)); }
protected void btnSave_Click(object sender, EventArgs e) { if (!CheckSlug()) { return; } course.Name = tbName.Text; course.Slug = tbSlug.Text; course.Description = tbDescription.Text; course.CategoryId = pCategory.SelectedValueAsId(); course.IsActive = false; course.ImageId = uImage.BinaryFileId; course.ExternalCourseUrl = tbExternalUrl.Text; if (course.ImageId.HasValue) { BinaryFileService binaryFileService = new BinaryFileService(rockContext); var img = binaryFileService.Get(course.ImageId.Value); if (img != null) { img.IsTemporary = false; } } if (course.Id == 0) { courseService.Add(course); } rockContext.SaveChanges(); //If they want a new course take them to the edit page NavigateToLinkedPage(AttributeKey.EditPage, new Dictionary <string, string> { { PageParameterKey.CourseId, course.Id.ToString() } }); }
public Course SyncCourse(RiseCourse riseCourse, CourseService courseService) { RockContext rockContext = ( RockContext )courseService.Context; var course = courseService.GetByCourseId(riseCourse.Id); if (course.IsNull()) { course = new Course(); courseService.Add(course); } course.Name = riseCourse.Title; course.Url = riseCourse.Url; course.CourseId = riseCourse.Id; rockContext.SaveChanges(); course.GetExperienceObject(); //make sure we have the xObject in the DB return(course); }
public async Task <IActionResult> Edit(AdminCourseDto model) { if (!ModelState.IsValid) { await ShowCourseCategoryList(false); return(PartialView("_EditPartial", model)); } //主键初始Id大于0表示是编辑,反之则是新增 if (model.Id > 0) { var result = await _service.Update(model); return(Json(result)); } else { var result = await _service.Add(model); return(Json(result)); } }
public IActionResult AddCourse([FromBody] Course course) { course.Id = Guid.NewGuid().ToString(); course.Created = DateTime.Now; course.Modified = DateTime.Now; course.CreatedBy = "system"; course.ModifiedBy = "system"; course.IsActive = true; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bool added = _service.Add(course); if (added) { return(Ok(course.Id)); } return(BadRequest("Couldn't save course.")); }
public async Task <IActionResult> Add([FromBody] CourseWithLecturesViewModel courseWithLecturesViewModel) { try { Course courseMapped = mapper.Map <Course>(courseWithLecturesViewModel.CourseViewModel); courseMapped.LastUpdated = DateTime.Now; IList <Lecture> lecturesMapped = new List <Lecture>(); foreach (LectureViewModel l in courseWithLecturesViewModel.LectureViewModels) { { Lecture lectureMapped = mapper.Map <Lecture>(l); lecturesMapped.Add(lectureMapped); } } courseMapped.Lectures = lecturesMapped; await courseService.Add(courseMapped); return(Ok(new { Results = courseMapped })); } catch (Exception e) { Console.WriteLine($"ErrorMesages: {e}"); return(BadRequest(new { Errors = new { Code = "InvalidInputParameters", Description = "Invalid Input Parameters!" } })); } }
public ResultViewModel <CourseEditViewModel> Post(CourseEditViewModel Course) { ResultViewModel <CourseEditViewModel> result = new ResultViewModel <CourseEditViewModel>(); string Token = Request.Headers.Authorization? .Parameter; Dictionary <string, string> cliams = SecurityHelper.Validate(Token); int UserID = int.Parse(cliams.First(i => i.Key == "ID").Value); try { if (!ModelState.IsValid) { result.Message = "In Valid Model State"; } else { CourseEditViewModel selectedCourse = courseService.Add(Course); result.Successed = true; result.Data = selectedCourse; } } catch (Exception ex) { result.Successed = false; result.Message = "Semething Went Wrong"; } return(result); }
public void Add_CourseAlreadyExist_PreexistingEntityExceptionWillBeThrown() { // arrange var courseToAdd = new Course() { Id = 5, Name = "Gym", CourseTypeId = _externalCT.Id, CourseType = _externalCT, IsDeleted = false }; _courseRepository.Setup(m => m.Find(It.IsAny <Expression <Func <Course, bool> > >(), null, "")) .Returns(() => { return(new List <Course> { new Course() }); }); var courseService = new CourseService(_courseRepository.Object); courseService.CourseTypeService = _courseTypeService.Object; // act and assert Assert.Throws <PreexistingEntityException>(() => courseService.Add(courseToAdd)); _courseRepository.Verify(cr => cr.Find(It.IsAny <Expression <Func <Course, bool> > >(), null, "")); }
public void Add_ReturnsId() { // Arrange int id = 322; Course course = new Course { Id = 322, WordSuites = new List <WordSuite>() }; List <int> list = new List <int>() { 1, 2, 3, 4, 322 }; Mock <IRepository <WorldOfWords.Domain.Models.Course> > repo = new Mock <IRepository <Course> >(); _uow.Setup(x => x.CourseRepository).Returns(repo.Object); _uow.Setup(x => x.CourseRepository.GetById(It.IsAny <int>())).Returns(course); Mock <ICollection <WordSuite> > WordSuites = new Mock <ICollection <WordSuite> >(); Mock <IWordSuiteRepository> wordSuiteRepository = new Mock <IWordSuiteRepository>(); _uow.Setup(x => x.WordSuiteRepository).Returns(wordSuiteRepository.Object); wordSuiteRepository.Setup(x => x.GetById(It.IsAny <int>())).Returns(It.IsAny <WordSuite>()); // Act var actual = _service.Add(course, list); // Assert _factory.Verify(x => x.GetUnitOfWork(), Times.Exactly(2)); _uow.Verify(x => x.CourseRepository.GetById(course.Id), Times.AtLeastOnce()); _uow.Verify(x => x.Save(), Times.Exactly(3)); _uow.Verify(x => x.CourseRepository, Times.Exactly(2)); _uow.Verify(x => x.CourseRepository.Add(course), Times.Once); //WordSuites.Verify(x=>x.Add(),Times.AtLeastOnce); Assert.AreEqual(id, actual); }
public async Task <IActionResult> Add(CourseModel input) => (await courseService.Add(input)).Result();
protected void btnSave_Click(object sender, EventArgs e) { if (!CheckSlug()) { return; } RockContext rockContext = new RockContext(); CourseService courseService = new CourseService(rockContext); var course = GetCourse(courseService); course.Name = tbName.Text; course.IsActive = cbIsActive.Checked; course.Description = tbDescription.Text; course.IconCssClass = tbIconCssClass.Text; course.CategoryId = pCategory.SelectedValueAsId(); course.Slug = tbSlug.Text; var oldImageId = course.ImageId; course.ImageId = uImage.BinaryFileId; if (oldImageId != course.ImageId) { BinaryFileService binaryFileService = new BinaryFileService(rockContext); var oldImage = binaryFileService.Get(oldImageId ?? 0); if (oldImage != null) { oldImage.IsTemporary = true; } var newImage = binaryFileService.Get(course.ImageId ?? 0); if (newImage != null) { newImage.IsTemporary = false; } } switch (ddlViewSecurity.SelectedValue) { case "Group": course.AllowedDataViewId = null; course.AllowedGroupId = pAllowedGroup.GroupId; break; case "DataView": course.AllowedGroupId = null; course.AllowedDataViewId = pAllowedDataView.SelectedValueAsId(); break; default: course.AllowedGroupId = null; course.AllowedDataViewId = null; break; } course.ExternalCourseUrl = tbExternalUrl.Text; if (course.Id == 0) { courseService.Add(course); } rockContext.SaveChanges(); NavigateToCurrentPage(new Dictionary <string, string> { { PageParameterKey.CourseId, course.Id.ToString() } }); }