public async Task <IHttpActionResult> Put(InstructorDTO instructorDTO, int id) // object - cuerpo pero si es prmitivo por la url { if (!ModelState.IsValid) { return(BadRequest(ModelState)); // status code 400 } if (instructorDTO.ID != id) { return(BadRequest()); } var flag = await instructorService.GetById(id); if (flag == null) { return(NotFound()); // status code 404 } try { var instructor = mapper.Map <Instructor>(instructorDTO); instructor = await instructorService.Update(instructor); return(Ok(instructor)); //Sastus code 200 //return Ok(courseDTO); //Sastus code 200 } catch (Exception ex) { return(InternalServerError(ex)); //Status code 500 } }
public async Task <ActionResult <InstructorDTO> > Post(InstructorDTO model) { try { if (model == null) { return(BadRequest("No entity provided")); } var id = await _adminService.CreateAsync <InstructorDTO, Instructor>(model); var dto = await _adminService.SingleAsync <Instructor, InstructorDTO>(instr => instr.Id.Equals(id)); if (dto == null) { return(BadRequest("Unable to add entity")); } var uri = _linkGenerator.GetPathByAction("Get", "Instructors", new { id }); return(Created(uri, dto)); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to add the entity")); } }
private void listInstructor() { string messageEmpty = String.Empty; if (txtSearchInstructors.Text != String.Empty) { dtgListInstructors.DataSource = InstructorDTO.getAllInstructorsToDisplay(txtSearchInstructors.Text); messageEmpty = "Não há monitor com esse critério!"; } else { dtgListInstructors.DataSource = InstructorDTO.getAllInstructorsToDisplay(); messageEmpty = "Não há monitor cadastrado!"; } if (dtgListInstructors.Columns.Count > 0) { dtgListInstructors.Columns[0].Visible = false; dtgListInstructors.Visible = true; lblListInstructorsEmpty.Visible = false; } else { dtgListInstructors.Visible = false; lblListInstructorsEmpty.Text = messageEmpty; lblListInstructorsEmpty.Visible = true; } }
public async Task <IHttpActionResult> Put(InstructorDTO instructorDTO, int id)//objet -> body / primitivo -> url { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (instructorDTO.ID != id) { return(BadRequest()); } var flag = await instructorService.GetById(id); if (flag == null) { return(NotFound()); //status code 404 } try { var instructor = mapper.Map <Instructor>(instructorDTO); instructor = await instructorService.Update(instructor); return(Ok(instructorDTO));//status code 200 } catch (System.Exception ex) { return(InternalServerError(ex));//status code 500 } }
public async Task <ActionResult <InstructorDTO> > Post(InstructorDTO model) { try { if (model == null) { return(BadRequest("No entity provided")); } var id = await _db.CreateAsync <InstructorDTO, Instructor>(model); var dto = await _db.SingleAsync <Instructor, InstructorDTO>(s => s.Id.Equals(id)); if (dto == null) { return(BadRequest("Unable to add the entity")); } var uri = _linkGenerator.GetPathByAction("Get", "Instructors", new { id }); return(Created(uri, dto)); } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to add the entity")); } }
public async Task <ActionResult <InstructorDTO> > Put(int id, InstructorDTO model) { try { if (model == null) { return(BadRequest("No entity provided")); } if (!id.Equals(model.Id)) { return(BadRequest("Differing ids")); } var exists = await _db.AnyAsync <Instructor>(a => a.Id.Equals(id)); if (!exists) { return(NotFound("Could not find entity")); } if (await _db.UpdateAsync <InstructorDTO, Instructor>(model)) { return(NoContent()); } } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to update the entity")); } return(BadRequest("Unable to update the entity")); }
public void Add() { InstructorDTO instructor = new InstructorDTO { FirstName = "Seyda", LastName = "Kurtdere", MobilePhone = "05348754962", EmailAddress = "*****@*****.**", RecordStatusId = 1, CreatedDate = DateTime.Now, CreatedBy = 1, }; instructor.InstructorCoursList = new System.Collections.Generic.List <InstructorCoursDTO>(); InstructorCoursDTO instructorCours1 = new InstructorCoursDTO { CourseId = 1 }; InstructorCoursDTO instructorCours2 = new InstructorCoursDTO { CourseId = 2 }; instructor.InstructorCoursList.Add(instructorCours1); instructor.InstructorCoursList.Add(instructorCours2); var result = instructorService.Add(instructor); Assert.IsNotNull(result); }
public async Task <ActionResult <InstructorDTO> > PutInstructor(int id, InstructorDTO model) { try { if (model == null) { return(BadRequest("No entity provided")); } if (!id.Equals(model.Id)) { return(BadRequest("Differing Ids")); } if (await _crudService.UpdateAsync <InstructorDTO, Instructor>(model)) { return(NoContent()); } } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to add the entity")); } return(BadRequest("Cannot update")); }
public void GetInstructorTest_One_Class() { const int EXPECTED_COURSE_COUNT = 1; var course1 = CourseTest.CreateTestCourse(Repository); var targetUnderTest = new InstructorDTO(); targetUnderTest.FirstName = "Test"; targetUnderTest.LastName = "Subject"; targetUnderTest.Courses = new List <CourseDTO>(); targetUnderTest.Courses.Add(course1); try { //Add the courses. Make sure they add correctly. targetUnderTest = Repository.CreateInstructor(targetUnderTest); Assert.AreEqual(EXPECTED_COURSE_COUNT, Repository.GetCoursesByInstructor(targetUnderTest.InstructorID).Count()); var allData = Repository.GetAllInstructors().Where(x => x.InstructorID == targetUnderTest.InstructorID).First(); Assert.IsNotNull(allData); Assert.IsNotNull(allData.Courses); Assert.AreEqual(EXPECTED_COURSE_COUNT, allData.Courses.Count()); } catch (Exception ex) { throw ex; } finally { InstructorsTest.DeleteTestInstructor(targetUnderTest, Repository); CourseTest.DeleteTestObject(course1, Repository); Repository.DeleteDepartment(course1.DepartmentID); } }
public async Task <IHttpActionResult> Put(InstructorDTO instructorDTO, int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (instructorDTO.ID != id) { return(BadRequest()); } var flag = await instructorService.GetById(id); if (flag == null) { return(NotFound()); } try { var instructor = mapper.Map <Instructor>(instructorDTO); instructor = await instructorService.Update(instructor); return(Ok(instructor)); } catch (Exception ex) { return(InternalServerError(ex)); } }
/// <summary> /// This static void transform an instructor to an instructorDTO for the ApiService /// </summary> /// <param name="instructor"></param> /// <returns>instructorDTO</returns> public static InstructorDTO TransformInstructorToInstructorDTO(Instructor instructor) { InstructorDTO instructorDTO = new InstructorDTO(); List <LessonDTO> lessonsDTO = new List <LessonDTO>(); if (instructor.Lessons != null) { foreach (Lesson lesson in instructor.Lessons) { LessonDTO lessonDTO = new LessonDTO(); lessonDTO.courseId = lesson.CourseID; lessonDTO.day = lesson.Day.ToString().ToLower(); lessonDTO.startHour = lesson.StartHour.ToString("HH'h'mm"); lessonDTO.duration = lesson.EndHour.Subtract(lesson.StartHour).TotalMinutes.ToString(); lessonsDTO.Add(lessonDTO); } } instructorDTO.instructorId = instructor.ID; instructorDTO.schedule = lessonsDTO; return(instructorDTO); }
public async Task <IActionResult> Put(int id, InstructorDTO model) { try { if (model == null) { return(BadRequest("No entity provided")); } if (!id.Equals(model.Id)) { return(BadRequest("Differing ids")); } var exist = await _adminService.AnyAsync <Instructor>(instr => instr.Id.Equals(id)); if (!exist) { return(NotFound("Could not find entity")); } if (await _adminService.UpdateAsync <InstructorDTO, Instructor>(model)) { return(NoContent()); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to update the entity")); } return(BadRequest("Unable to update the entity")); }
private InstructorItemViewModel ToInstructorItemViewModel(InstructorDTO instructorDTO) => new InstructorItemViewModel { ID = instructorDTO.ID, LastName = instructorDTO.LastName, FirstMidName = instructorDTO.FirstMidName, HireDate = instructorDTO.HireDate };
public async Task <IHttpActionResult> Post(InstructorDTO instructorDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState));//status code 400 } //var instructor = new InstructorDTO //{ // ID = instructorDTO.ID, // LastName = instructorDTO.LastName, // FirstMidName = instructorDTO.FirstMidName, // HireDate = instructorDTO.HireDate //}; try { var instructor = mapper.Map <Instructor>(instructorDTO); instructor = await instructorService.Insert(instructor); return(Ok(instructorDTO));//status code 200 } catch (Exception ex) { return(InternalServerError(ex));//status code 500 } }
public void AddInstructor_Test_two_courses() { const int EXPECTED_COURSE_COUNT = 2; var currentPeopleCount = Repository.GetAllInstructors().Count(); var course1 = CourseTest.CreateTestCourse(Repository); var course2 = CourseTest.CreateTestCourse(Repository); var targetUnderTest = new InstructorDTO(); targetUnderTest.FirstName = "Test"; targetUnderTest.LastName = "Subject"; targetUnderTest.Courses = new List <CourseDTO>(); targetUnderTest.Courses.Add(course1); targetUnderTest.Courses.Add(course2); try { targetUnderTest = Repository.CreateInstructor(targetUnderTest); Assert.IsTrue(Repository.GetAllInstructors().Count() > currentPeopleCount); Assert.AreEqual(EXPECTED_COURSE_COUNT, Repository.GetCoursesByInstructor(targetUnderTest.InstructorID).Count()); } catch (Exception ex) { throw ex; } finally { InstructorsTest.DeleteTestInstructor(targetUnderTest, Repository); CourseTest.DeleteTestObject(course1, Repository); CourseTest.DeleteTestObject(course2, Repository); Repository.DeleteDepartment(course1.DepartmentID); Repository.DeleteDepartment(course2.DepartmentID); } }
public async Task <IHttpActionResult> Post(InstructorDTO instructorDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); // status code 400 } //var course = new CourseDTO //{ // CourseId = courseDTO.CourseId, // Title = courseDTO.Title, // Credits = courseDTO.Credits //}; //Ctrl + K + S Redondear el codigo try { var instructor = mapper.Map <Instructor>(instructorDTO); //var course = mapper.Map<Course>(courseDTO); //course = await courseService.Insert(course); //return Ok(courseDTO); //Sastus code 400 instructor = await instructorService.Insert(instructor); return(Ok(instructorDTO)); //Sastus code 200 } catch (Exception ex) { return(InternalServerError(ex)); //Status code 500 } }
public EditInstructorViewModel(InstructorDTO instructor) { this.instructor = instructor; this.instructorService = new InstructorService(); this.SaveCommand = new Command(async() => await EditInstructor()); this.IsRunning = false; this.IsEnabled = true; }
public async Task <IActionResult> InsertInstructor(InstructorDTO instructorDTO) { var instructor = _mapper.Map <Instructor>(instructorDTO); await _instructorService.InsertInstructor(instructor); instructorDTO = _mapper.Map <InstructorDTO>(instructor); var response = new APIResponse <InstructorDTO>(instructorDTO); return(Ok(response)); }
public async Task <IActionResult> Edit(InstructorDTO instructorDTO) { if (ModelState.IsValid) { var instructor = mapper.Map <Instructor>(instructorDTO); instructor = await instructorService.Update(instructor); return(RedirectToAction(nameof(Index))); } return(View(instructorDTO)); }
// // GET: /Instructor/Delete/5 public ActionResult Delete(int?id) { InstructorDTO instructorDto = _instructorService.GetItem(id); var departmentDto = _depatrmentService.GetItem(instructorDto.DepartmentId); ViewBag.Departments = departmentDto.DepartmentName; var instructor = Mapper.Map <InstructorDTO, InstructorViewModel>(instructorDto); return(View(instructor)); }
public InstructorDetail(string id) { InitializeComponent(); this.CenterToScreen(); instructorToEdit = InstructorDTO.getInstructors(new Dictionary <string, string> { { "id", id } })[0]; setFields(); setLabels(); }
public async Task <IActionResult> Create(InstructorDTO instructorDto) { if (ModelState.IsValid) { var instructorId = await _apiService.CreateAsync <Instructor, InstructorDTO>(instructorDto); return(RedirectToAction(nameof(Index))); } return(View(instructorDto)); }
public async Task <IActionResult> Put(long Id, InstructorDTO instructorDTO) { var instructor = _mapper.Map <Instructor>(instructorDTO); instructor.Id = Id; var result = await _instructorService.UpdateInstructor(instructor); instructorDTO = _mapper.Map <InstructorDTO>(instructor); var response = new APIResponse <InstructorDTO>(instructorDTO); return(Ok(response)); }
public async Task <IActionResult> Create(InstructorDTO instructorDTO) { if (ModelState.IsValid) { var instructor = _mapper.Map <Instructor>(instructorDTO); instructor = await _instructorService.Insert(instructor); var id = instructor.ID; return(RedirectToAction("Index")); } return(View(instructorDTO)); }
public ActionResult <InstructorDTO> Post(InstructorDTO instructor) { if (instructor == null) { //return 400 bad reqeust. return(BadRequest()); } instructor = Repository.CreateInstructor(instructor); return(instructor); }
async Task EditInstructor() { try { if (string.IsNullOrEmpty(this.Instructor.LastName)) { await Application.Current.MainPage.DisplayAlert("Error", "You must enter the field LastName", "Cancel"); return; } this.IsRunning = true; this.IsEnabled = false; var connection = await instructorService.CheckConnection(); if (!connection) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert("Error", "No internet connection", "Cancel"); return; } var instructorDTO = new InstructorDTO { ID = this.Instructor.ID, LastName = this.Instructor.LastName, FirstMidName = this.Instructor.FirstMidName, HireDate = this.Instructor.HireDate }; await instructorService.Update(Endpoints.PUT_INSTRUCTORS, this.Instructor.ID, instructorDTO); this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert("Message", "The process is successful", "Cancel"); this.Instructor.ID = this.Instructor.ID = 0; this.Instructor.LastName = string.Empty; this.Instructor.FirstMidName = string.Empty; this.Instructor.HireDate = DateTime.Now; await Application.Current.MainPage.Navigation.PopAsync(); } catch (Exception ex) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Cancel"); } }
public async Task <ActionResult> Edit(InstructorDTO instructorDTO) { if (ModelState.IsValid) { var instructorService = new InstructorService(new InstructorRepository(UniversityContext)); var instructor = mapper.Map <Instructor>(instructorDTO); instructor = await instructorService.Update(instructor); return(RedirectToAction("Index", "Instructors")); } return(View(instructorDTO)); }
async Task CreateInstructor() { try { if (string.IsNullOrEmpty(this.LastName)) { await Application.Current.MainPage.DisplayAlert("Error", "You must enter the field LastName", "Cancel"); return; } this.IsRunning = true; this.IsEnabled = false; var connection = await instructorService.CheckConnection(); if (!connection) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert("Error", "No internet connection", "Cancel"); return; } var instructorDTO = new InstructorDTO { LastName = this.LastName, FirstMidName = this.FirstMidName, HireDate = this.HireDate }; await instructorService.Create(Endpoints.POST_Instructor, instructorDTO); this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert("Message", "The process is successful", "Cancel"); this.InstructorID = 0; this.LastName = this.FirstMidName = string.Empty; //this.HireDate = DateTime.Now; //Application.Current.MainPage = new NavigationPage(new CoursesPage()); } catch (Exception ex) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Cancel"); } }
/// <summary>Adds courses to the list of instructors.</summary> /// <param name="instructors">The instructors.</param> /// <returns></returns> private InstructorDTO AddCourses(InstructorDTO instructor) { if (instructor == null) { return(instructor); } //make sure the courses exist. var allCourses = GetAllCourses().ToList(); if (allCourses == null || allCourses.Count() <= 0) { return(instructor); } foreach (var c in instructor.Courses) { if (!allCourses.Any(x => x.CourseID == c.CourseID)) { throw new KeyNotFoundException($"The course ID {c.CourseID} was not found in the system."); } } //hooray, the courses exist! //make sure the courses are not already assigned. var instructorCourses = GetCoursesByInstructor(instructor.InstructorID); var coursesToAdd = instructor.Courses; if (instructorCourses != null && instructorCourses.Count() > 0) { foreach (var ic in instructorCourses) { if (instructor.Courses.Any(x => x.CourseID == ic.CourseID)) { coursesToAdd.Remove(coursesToAdd.Where(x => x.CourseID == ic.CourseID).First()); } } } //All new courses should be in the coursesToAdd object. Save just those. foreach (var i in coursesToAdd) { AddInstructorCourse(instructor.InstructorID, i.CourseID); } instructor.Courses = GetCoursesByInstructor(instructor.InstructorID).ToList(); return(instructor); }
private bool AddNewInstructor() { return(InstructorDTO.AddNewInstructor(new Instructor( 0, txtNameInstructor.Text, txtCpfInstructor.Text, txtPasswordInstructor.Text, txtEmailInstructor.Text, txtProntuarioInstructor.Text, txtTipoInstructor.Text, Convert.ToInt32(txtCargaInstructor.Value), DateTime.Today ))); }