public IHttpActionResult UpdateInstructor([FromBody] GroupInstructorDTO groupInstructor) { var entity = groupInstructorMapper.Map(groupInstructor); instructorService.Update(entity); return(Ok()); }
public void UpdateInstructor_WhereInstructorExists_UpdatesEntityWithoutError([Values(1, 2, 3)] int idOfInstructorToUpdate) { //Arrange var expected = _mockInstructorList.First(x => x.InstructorId == idOfInstructorToUpdate); expected.InstructorName = "UPDATED"; Mock.Arrange(() => _instructorService.Update(expected)).Returns(expected).OccursOnce(); var instructorController = new InstructorController(_instructorService) { Request = new HttpRequestMessage() { RequestUri = new Uri("http://localhost/api/instructor/create") } }; ////Act var actual = instructorController.Put(expected) as OkNegotiatedContentResult <InstructorDto>; var actualContent = actual.Content; //Assert Mock.Assert(_instructorService); Assert.That(actual, Is.Not.Null); Assert.That(actual, Is.TypeOf <OkNegotiatedContentResult <InstructorDto> >()); Assert.That(actualContent, Is.EqualTo(expected)); }
public IHttpActionResult Put(InstructorDto instructor) { using (_instructorService) { var response = _instructorService.Update(instructor); 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)); }
public InstructorViewModel Update(InstructorViewModel instructorViewModel) { var instructor = Mapper.Map <Instructor>(instructorViewModel); var instructorReturn = instructorService.Update(instructor); if (instructorReturn.ValidationResult.IsValid) { unitOfWork.Commit(); } instructorViewModel = Mapper.Map <InstructorViewModel>(instructorReturn); return(instructorViewModel); }
public async Task <object> UpdateInstructor(InstructorViewModel model, int id) { Instructor instructor = new SimpleAutoMapper <Instructor>().Map(model); instructor.ID = id; try { if (await CheckPermissionToCreateUpdateInstructor(instructor)) { Response response = await _service.Update(instructor); return(this.SendResponse(response)); } return(Forbid()); } catch (Exception e) { return(null); } }
public ActionResult Edit(int id, [Bind("id,Name,Email,Password,RG,cpf,Street,Neighborhood,idCity,idState,idUser,CreatedAt,UpdatedAt,DeletedAt")] VMInstructor payload) { try { if (id != payload.id) { var _msg = new VMMessages() { Css = "alert alert-danger", Text = "Um erro inseperado ocorreu" }; TempData["_mensagem"] = JsonConvert.SerializeObject(_msg); return(RedirectToAction(nameof(Index))); } if (ModelState.IsValid) { var result = _instructorService.Update(payload); if (result) { var _msg = new VMMessages() { Css = "alert alert-success", Text = "Editado com sucesso!" }; TempData["_mensagem"] = JsonConvert.SerializeObject(_msg); } else { var _msg = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; TempData["_mensagem"] = JsonConvert.SerializeObject(_msg); } return(RedirectToAction(nameof(Index))); } } catch (CustomHttpException ex) { _logger.Log(LogLevel.Error, ex.Message); TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = ex.ErrorMessage }; } catch (Exception ex) { _logger.Log(LogLevel.Error, ex.Message); TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; } ViewData["idCity"] = new SelectList(_cityService.GetCitiesByState(payload.idState), "Id", "Name", payload.idCity); ViewData["idState"] = new SelectList(_stateService.GetAll(), "Id", "Name", payload.idState); return(View(payload)); }
public IActionResult Update(int?id, string[] selectedCourses) { _service.Update(id, selectedCourses); return(NoContent()); }