public ActionResult <DogDTO> Put([FromBody] DogForUpdateDTO model) { try { var dog = mapper.Map <Dog>(model); TrainingCourse trainingCourse = trainingCourseService.GetBy(t => t.Name == model.TrainingCourse); Dog dogFromDatabase = dogService.GetById(model.Id); if (dogFromDatabase == null) { return(NotFound()); } dogFromDatabase.Breed = dog.Breed; dogFromDatabase.Name = dog.Name; dogFromDatabase.TaskEngagements = dog.TaskEngagements; dogFromDatabase.TrainingCourseId = dog.TrainingCourseId; dogFromDatabase.DateOfBirth = dogFromDatabase.DateOfBirth; dogFromDatabase.ChipNumber = dog.ChipNumber; dogFromDatabase.TrainingCourseId = trainingCourse.TrainingCourseId; dogService.Update(dogFromDatabase); DogDTO dogDTO = mapper.Map <DogDTO>(dogFromDatabase); // return Created($"api/dogs/get/{dogDTO.Name}", dogDTO); return(Ok(dogDTO)); } catch (Exception ex) { throw; } }
public void ItemUpdatingPositiveTest() { using (SPSite site = new SPSite(siteUrl)) { using (SPWeb web = site.AllWebs[webId]) { #region Arrange TrainingCourseRepository repository = new TrainingCourseRepository(); TrainingCourse course = new TrainingCourse { Title = "My Title", Code = "12345678", EnrollmentDate = DateTime.Today, StartDate = DateTime.Today.AddDays(1), EndDate = DateTime.Today.AddDays(2), Cost = 100 }; int id = repository.Add(course, web); #endregion course.Title = "New Title"; repository.Update(course, web); #region Cleanup repository.Delete(id, web); #endregion } } }
public async Task Then_The_Api_Client_Is_Called_With_The_Request( int courseId, double lat, double lon, string locationName, string baseUrl, Guid shortlistUserId, TrainingCourse response, [Frozen] Mock <IOptions <FindApprenticeshipTrainingApi> > config, [Frozen] Mock <IApiClient> apiClient, CourseService courseService) { //Arrange var courseApiRequest = new GetCourseApiRequest(config.Object.Value.BaseUrl, courseId, lat, lon, locationName, shortlistUserId); apiClient.Setup(x => x.Get <TrainingCourse>( It.Is <GetCourseApiRequest>(request => request.GetUrl.Equals(courseApiRequest.GetUrl)))).ReturnsAsync(response); //Act var actual = await courseService.GetCourse(courseId, lat, lon, locationName, shortlistUserId); //Assert actual.Should().BeEquivalentTo(response); }
/// <summary> /// Initializes a new instance of the <see cref="StaffTrainingCourse"/> class. /// </summary> /// <param name="trainingCourse">The training course.</param> /// <param name="otherTrainingCourseName">Name of the other training course.</param> /// <param name="completedDate">The completed date.</param> public StaffTrainingCourse(TrainingCourse trainingCourse, string otherTrainingCourseName, DateTime? completedDate) { Check.IsNotNull(trainingCourse, () => TrainingCourse); _trainingCourse = trainingCourse; _otherTrainingCourseName = otherTrainingCourseName; _completedDate = completedDate; }
private IEnumerable <TrainingCourse> GetCourseViews(Expression <Func <Data.TrainingCourse, bool> > whereClause, DateTime when) { return(db.TrainingCourses .Where(whereClause) .OrderBy(f => f.DisplayName) .Select(TrainingCourse.GetTrainingCourseConversion(when))); }
public void RenderCourseRegistrationPopulatesView() { string loginName = @"domain\alias"; string courseId = "1"; SPWeb mockWeb = CreateMockSPWeb(false); MockCourseRegistrationView mockView = new MockCourseRegistrationView(); mockView.QueryString = new System.Collections.Specialized.NameValueCollection(); mockView.QueryString["ID"] = courseId; TrainingCourse course = new TrainingCourse() { Id = 1, Code = "TestCode" }; MockTrainingCourseRepository.TrainingCourseReturnedByGet = course; this.serviceLocator.Register <IRegistrationRepository>(typeof(MockRegistrationRepository)); this.serviceLocator.Register <ITrainingCourseRepository>(typeof(MockTrainingCourseRepository)); CourseRegistrationPresenter presenter = new CourseRegistrationPresenter(mockView); presenter.RenderCourseRegistrationView(mockWeb, loginName); Assert.AreEqual <string>("Course Registration - TestCode", mockView.PageTitle); Assert.AreEqual <string>("Course Registration", mockView.HeaderTitle); Assert.AreEqual <string>("TestCode", mockView.HeaderSubtitle); Assert.AreEqual <string>("Would you like to register for course: TestCode?", mockView.ContentMessage); Assert.IsTrue(mockView.ShowConfirmationControls); Assert.IsFalse(mockView.ShowCourseSelectionControls); Assert.AreEqual("http://localhost/training", mockView.SiteLink); MockManager.Verify(); }
public override void load(IModelObject mo) { const int DATAREADER_FLD_CODE = 0; const int DATAREADER_FLD_DESCR_GR = 1; const int DATAREADER_FLD_DESCR_EN = 2; TrainingCourse obj = (TrainingCourse)mo; obj.IsObjectLoading = true; if (!this.reader.IsDBNull(DATAREADER_FLD_CODE)) { obj.PrCODE = this.reader.GetString(DATAREADER_FLD_CODE); } if (!this.reader.IsDBNull(DATAREADER_FLD_DESCR_GR)) { obj.PrDescrGr = this.reader.GetString(DATAREADER_FLD_DESCR_GR); } if (!this.reader.IsDBNull(DATAREADER_FLD_DESCR_EN)) { obj.PrDescrEn = this.reader.GetString(DATAREADER_FLD_DESCR_EN); } obj.isNew = false; // since we've just loaded from database, we mark as "old" obj.isDirty = false; obj.IsObjectLoading = false; obj.afterLoad(); return; }
public void PresenterInitializesViewTextHappyCase() { var view = new MockRegistrationApprovalView(); var presenter = new RegistrationApprovalPresenter(view); var trainingCourse = new TrainingCourse() { Cost = 100, Code = "12345678", Title = "MockCourse" }; MockTrainingCourseRepository.TrainingCourseReturnedByGet = trainingCourse; serviceLocator.Register <IRegistrationRepository>(typeof(MockRegistrationRepository)); serviceLocator.Register <ITrainingCourseRepository>(typeof(MockTrainingCourseRepository)); serviceLocator.Register <IRegistrationApprovalTaskRepository>(typeof(MockRegistrationApprovalTaskRepository)); MockRegistrationRepository.RegistrationReturnedByGet = new Registration(); MockRegistrationRepository.RegistrationReturnedByGet.UserId = 1; MockRegistrationApprovalTaskRepository.RegistrationApprovalTaskReturnedByGet = new RegistrationApprovalTask(); bool success = presenter.RenderRegApprovalView(web, "12345"); Assert.IsTrue(success); Assert.AreEqual("Registration Approval", view.HeaderTitle); Assert.AreEqual("Registration Approval - " + userName, view.PageTitle); Assert.AreEqual(userName, view.HeaderSubtitle); StringAssert.Contains(view.Message, string.Format("Please approve or reject the registration request by {0} for course: 12345678 - MockCourse.", userName)); StringAssert.Contains(view.Message, string.Format("The MockCourse has been requested by {0}.", userName)); StringAssert.Contains(view.Message, string.Format("The cost of this course is $100.00.", userName)); Assert.AreEqual(2, view.Status.Count); Assert.IsTrue(view.Status.Contains("Approved")); Assert.IsTrue(view.Status.Contains("Rejected")); Assert.IsTrue(view.ShowConfirmationControls); }
/// <summary> /// Initializes a new instance of the <see cref="StaffTrainingCourse"/> class. /// </summary> /// <param name="trainingCourse">The training course.</param> /// <param name="otherTrainingCourseName">Name of the other training course.</param> /// <param name="completedDate">The completed date.</param> public StaffTrainingCourse(TrainingCourse trainingCourse, string otherTrainingCourseName, DateTime?completedDate) { Check.IsNotNull(trainingCourse, () => TrainingCourse); _trainingCourse = trainingCourse; _otherTrainingCourseName = otherTrainingCourseName; _completedDate = completedDate; }
public static void saveTrainingCourse(DataTable dt, ref TrainingCourse mo) { foreach (DataRow dr in dt.Rows) { saveTrainingCourse(dr, ref mo); } }
private string StartTaskAtStudyDate(SystemUser user, TrainingCourse course, DateTime studyDate) { var notifyDate = studyDate; var messageBody = $"today at {studyDate.ToShortDateString()}!"; var job = ScheduleTask(notifyDate, studyDate, course, user, messageBody); return(job); }
public TrainingCourse Update(TrainingCourse trainingCourseChanges) { var trainingCourse = dBContext.TrainingCourses.Attach(trainingCourseChanges); trainingCourse.State = EntityState.Modified; dBContext.SaveChanges(); return(trainingCourseChanges); }
public void Then_The_Fields_Are_Correctly_Mapped(TrainingCourse source) { //Act var actual = (Course)source; //Assert actual.Should().BeEquivalentTo(source); }
public ActionResult DeleteConfirmed(int id) { TrainingCourse trainingCourse = db.TrainingCourses.Find(id); db.TrainingCourses.Remove(trainingCourse); db.SaveChanges(); return(RedirectToAction("Index")); }
public void UpdatingCourseWithExisitingCodeCancelsWithError() { using (SPSite site = new SPSite(siteUrl)) { using (SPWeb web = site.AllWebs[webId]) { #region Arrange TrainingCourseRepository repository = new TrainingCourseRepository(); TrainingCourse course = new TrainingCourse { Title = "My Title", Code = "12345678", EnrollmentDate = DateTime.Today, StartDate = DateTime.Today.AddDays(1), EndDate = DateTime.Today.AddDays(2), Cost = 100 }; course.Id = repository.Add(course, web); TrainingCourse course2 = new TrainingCourse { Title = "My Title", Code = "98765432", EnrollmentDate = DateTime.Today, StartDate = DateTime.Today.AddDays(1), EndDate = DateTime.Today.AddDays(2), Cost = 100 }; course2.Id = repository.Add(course2, web); #endregion try { course.Code = "98765432"; repository.Update(course, web); } catch (SPException ex) { throw; } finally { #region Cleanup repository.Delete(course.Id, web); repository.Delete(course2.Id, web); #endregion } } } }
public void Update_IdAndItemIsValid_ItemUpdated() { using (SPSite site = new SPSite(siteUrl)) { using (SPWeb web = site.AllWebs[webId]) { #region Arrange TrainingCourse targetItem = new TrainingCourse(); targetItem.Title = "TestTitle"; targetItem.Code = "TestCode"; targetItem.Description = "TestDescription"; targetItem.EnrollmentDate = DateTime.Today; targetItem.StartDate = DateTime.Today.AddDays(1); targetItem.EndDate = DateTime.Today.AddDays(2); targetItem.Cost = 123f; TrainingCourseRepository target = new TrainingCourseRepository(); targetItem.Id = target.Add(targetItem, web); #endregion #region Act targetItem.Title = "NewTitle"; targetItem.Code = "_NewCode"; targetItem.Description = "TestDescription"; targetItem.EnrollmentDate = DateTime.Today.AddDays(1); targetItem.StartDate = DateTime.Today.AddDays(2); targetItem.EndDate = DateTime.Today.AddDays(3); targetItem.Cost = 456f; target.Update(targetItem, web); #endregion #region Assert TrainingCourse trainingCourseFound = target.Get(targetItem.Id, web); Assert.IsNotNull(trainingCourseFound); Assert.AreEqual(targetItem.Id, trainingCourseFound.Id); Assert.AreEqual(targetItem.Title, trainingCourseFound.Title); Assert.AreEqual(targetItem.Code, trainingCourseFound.Code); Assert.AreEqual(targetItem.Description, trainingCourseFound.Description); Assert.AreEqual(targetItem.EnrollmentDate, trainingCourseFound.EnrollmentDate); Assert.AreEqual(targetItem.StartDate, trainingCourseFound.StartDate); Assert.AreEqual(targetItem.EndDate, trainingCourseFound.EndDate); Assert.AreEqual(targetItem.Cost, trainingCourseFound.Cost); #endregion #region Cleanup target.Delete(targetItem.Id, web); #endregion } } }
/// <summary> /// Reload the TrainingCourse from the database /// </summary> /// <remarks> /// use this method when you want to relad the TrainingCourse /// from the database, discarding any changes /// </remarks> public static void reload(ref TrainingCourse mo) { if (mo == null) { throw new System.ArgumentNullException("null object past to reload function"); } mo = (TrainingCourse) new TrainingCourseDBMapper().findByKey(mo.Id); }
public TrainingCourse Get(Guid id) { // Get the data object (if it exists), and pass it through a conversion to the view model. If it doesn't exist, throw a 404 exception return(GetObjectOrNotFound( () => db.TrainingCourses .Where(f => f.Id == id) .Select(TrainingCourse.GetTrainingCourseConversion(DateTime.Now)) .SingleOrDefault())); }
public static TrainingCourse loadFromDataRow(DataRow r) { DataRowLoader a = new DataRowLoader(); IModelObject mo = new TrainingCourse(); a.DataSource = r; a.load(mo); return((TrainingCourse)mo); }
public ActionResult New(string number, string title, string type) { var course = new TrainingCourse { Number = number, Title = title, Type = type }; dao.AddCourse(course); ViewData["message"] = "Course created successfully!"; return(View("NewCourseCreated", course)); }
private void SeedDogsTable(ApplicationDbContext context) { TrainingCourse trainingCourse1 = context.TrainingCourses.SingleOrDefault(t => t.TrainingCourseId == 1); TrainingCourse trainingCourse2 = context.TrainingCourses.SingleOrDefault(t => t.TrainingCourseId == 2); TrainingCourse trainingCourse3 = context.TrainingCourses.SingleOrDefault(t => t.TrainingCourseId == 3); TrainingCourse trainingCourse4 = context.TrainingCourses.SingleOrDefault(t => t.TrainingCourseId == 4); TrainingCourse trainingCourse5 = context.TrainingCourses.SingleOrDefault(t => t.TrainingCourseId == 5); context.Dogs.AddRange(new Dog() { Breed = "Akita", ChipNumber = "123456789", DateOfBirth = new DateTime(2017, 08, 10), Gender = "Male", Name = "Aki", TrainingCourseId = trainingCourse1.TrainingCourseId }, new Dog() { Breed = "Akita", ChipNumber = "123456389", DateOfBirth = new DateTime(2017, 08, 10), Gender = "Female", Name = "Boni", TrainingCourseId = trainingCourse2.TrainingCourseId }, new Dog() { Breed = "German Shepherd", ChipNumber = "120456789", DateOfBirth = new DateTime(2018, 06, 10), Gender = "Male", Name = "Leo", TrainingCourseId = trainingCourse3.TrainingCourseId }, new Dog() { Breed = "Belgian Malinois", ChipNumber = "190456789", DateOfBirth = new DateTime(2020, 03, 18), Gender = "Male", Name = "Rocky", TrainingCourseId = trainingCourse4.TrainingCourseId }, new Dog() { Breed = "Sarplaninac", ChipNumber = "110456789", DateOfBirth = new DateTime(2020, 01, 18), Gender = "Male", Name = "Yuriko", TrainingCourseId = trainingCourse5.TrainingCourseId } ); context.SaveChanges(); }
public IHttpActionResult GetTrainingCourse(int id) { TrainingCourse trainingCourse = db.Courses.Find(id); if (trainingCourse == null) { return(NotFound()); } return(Ok(trainingCourse)); }
/// <summary> /// To update training course service /// </summary> /// <param name="id">training course id</param> /// <param name="jobSeekerTrainingCourseObj">training course object</param> public void Put(string id, TrainingCourse jobSeekerTrainingCourseObj) { try { jobSeekerTrainingCourseObj.JobSeekerId = SkillsmartUser.GuidStr(HttpContext.Current.User); jobSeekerTrainingCourseObj.Id = new Guid(id); jobSeekerTrainingCourseObj.Id = new Guid(id); ServiceFactory.GetJobSeekerTrainingCourse().Update(jobSeekerTrainingCourseObj); } catch (Exception exp) {} }
private string ScheduleTask(DateTime notifyDate, DateTime studyDate, TrainingCourse course, SystemUser user, string messageBody = null) { var days = (studyDate - notifyDate).TotalDays; messageBody ??= $"in {days} at {studyDate.ToShortDateString()}"; var message = string.Format(STANDARD_MESSAGE, course.Title, messageBody); notifyDate = notifyDate.AddHours(8); var job = backgroundJobClient.Schedule <ISendEmailService>((x) => x.SendEmail(user.Email, SUBJECT, message), notifyDate); return(job); }
public ActionResult CreateCourse(TrainingCourse course) { if (!ModelState.IsValid) { return(View("NewCourse")); } _context.TrainingCourses.Add(course); _context.SaveChanges(); return(RedirectToAction("TrainingCourses", "Staff")); }
public IHttpActionResult PostTrainingCourse(TrainingCourse trainingCourse) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Courses.Add(trainingCourse); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = trainingCourse.Id }, trainingCourse)); }
public void RenderCourseRegistrationPopulatesViewWithCourseSelectionList() { string loginName = @"domain\alias"; SPWeb mockWeb = this.CreateMockSPWeb(true); MockCourseRegistrationView mockView = new MockCourseRegistrationView(); mockView.QueryString = new System.Collections.Specialized.NameValueCollection(); TrainingCourse course = new TrainingCourse() { Id = 1, Code = "TestCode" }; MockTrainingCourseRepository.TrainingCourseReturnedByGet = course; List <TrainingCourse> courses = new List <TrainingCourse>(); TrainingCourse course1 = new TrainingCourse() { Id = 1, Code = "TstCode1" }; TrainingCourse course2 = new TrainingCourse() { Id = 2, Code = "TstCode2" }; courses.Add(course1); courses.Add(course2); MockTrainingCourseRepository.TrainingCourseListReturnedByGet = courses; this.serviceLocator.Register <IRegistrationRepository>(typeof(MockRegistrationRepository)); this.serviceLocator.Register <ITrainingCourseRepository>(typeof(MockTrainingCourseRepository)); CourseRegistrationPresenter presenter = new CourseRegistrationPresenter(mockView); presenter.RenderCourseRegistrationView(mockWeb, loginName); Assert.AreEqual <string>("Course Registration", mockView.HeaderTitle); Assert.AreEqual <string>("Course Registration - New", mockView.PageTitle); Assert.AreEqual <string>("New", mockView.HeaderSubtitle); Assert.AreEqual <string>("Which course would you like to register for?", mockView.ContentMessage); Assert.IsNotNull(mockView.Courses); Assert.AreEqual(2, mockView.Courses.Count); Assert.AreEqual("TstCode1", mockView.Courses[0].Code); Assert.AreEqual("TstCode2", mockView.Courses[1].Code); Assert.IsTrue(mockView.ShowConfirmationControls); Assert.IsTrue(mockView.ShowCourseSelectionControls); Assert.AreEqual("http://localhost/training", mockView.SiteLink); MockManager.Verify(); }
public TrainingCourse GetCourseByTitle(string title) { TrainingCourse course = null; foreach (TrainingCourse tc in sampleData) { if (tc.Title == title) { course = tc; } } return(course); }
public TrainingCourse GetCourseByNumber(string number) { TrainingCourse course = null; foreach (TrainingCourse tc in sampleData) { if (tc.Number == number) { course = tc; } } return(course); }
private static void PerformRegistration(SPWeb web, TrainingCourse course, SPUser user) { Registration registration = new Registration(); registration.Title = String.Format("{0} - {1}", course.Code, user.Name); registration.CourseId = course.Id; registration.UserId = user.ID; registration.RegistrationStatus = "Pending"; IRegistrationRepository registrationRepository = ServiceLocator.GetInstance().Get <IRegistrationRepository>(); registrationRepository.Add(registration, web); }
private string ScheduleTaskForMonth(SystemUser user, TrainingCourse course, DateTime studyDate) { // no need to schedule task for one month if (studyDate.IsDateInCurrentMonth()) { return(null); } var notifyDate = studyDate.AddMonths(-1); var job = ScheduleTask(notifyDate, studyDate, course, user); return(job); }
public static TrainingCourse loadFromDataRow(DataRow r) { DataRowLoader a = new DataRowLoader(); IModelObject mo = new TrainingCourse(); a.DataSource = r; a.load(mo); return (TrainingCourse)mo; }
public static void saveTrainingCourse(DataRow dr, ref TrainingCourse mo) { if (mo == null) { mo = new TrainingCourse(); } foreach (DataColumn dc in dr.Table.Columns) { mo.setAttribute(dc.ColumnName, dr[dc.ColumnName]); } saveTrainingCourse(mo); }
/// <summary> /// Reload the TrainingCourse from the database /// </summary> /// <remarks> /// use this method when you want to relad the TrainingCourse /// from the database, discarding any changes /// </remarks> public static void reload(ref TrainingCourse mo) { if (mo == null) { throw new System.ArgumentNullException("null object past to reload function"); } mo = (TrainingCourse)new TrainingCourseDBMapper().findByKey(mo.Id); }
public void saveTrainingCourse(TrainingCourse mo) { base.save(mo); }
public static void deleteTrainingCourse(TrainingCourse TrainingCourseObj) { TrainingCourseDBMapper dbm = new TrainingCourseDBMapper(); dbm.delete(TrainingCourseObj); }