public async Task <IActionResult> Edit(AirplaneViewModel airplaneViewModel) { if (ModelState.IsValid) { try { var path = string.Empty; if (airplaneViewModel.ImageFile != null && airplaneViewModel.ImageFile.Length > 0) { path = await _imageHelper.UpLoadImageAsync(airplaneViewModel.ImageFile, "Airplaines"); } var airplaine = _converterHelper.ToAirplane(airplaneViewModel, path, false); // TODO: change for logged user airplaine.User = await _userHelper.GetUserByEmailAsync(User.Identity.Name); await _repository.UpDateAsync(airplaine); // Método Update já grava as alterações } catch (DbUpdateConcurrencyException) { if (!await _repository.ExistsAsync(airplaneViewModel.Id)) { return(new NotFoundViewResult("MyNotFound")); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(airplaneViewModel)); }
public async Task Create_ShouldCreateNewAirplane() { // Arrange var viewModel = new AirplaneViewModel() { Name = "Name1", KeroseneConsumption = 6, Speed = 800 }; var airplane = new Airplane() { Name = "Name1", KeroseneConsumption = 6, Speed = 800 }; _unitOfWorkMock .Setup(uof => uof.AirplaneRepository .Add(It.IsAny <Airplane>())); // Act var result = await _airplanesController.Create(viewModel); // Assert var redirect = Assert.IsType <RedirectToActionResult>(result); _unitOfWorkMock.Verify(uof => uof.AirplaneRepository.Add(It.Is <Airplane>(a => a.Name == airplane.Name && a.KeroseneConsumption == airplane.KeroseneConsumption && a.Speed == airplane.Speed))); }
public void Atualizar(AirplaneViewModel registro) { //var item = _repository.PesquisarPorId(registro.id); //item.codigo_do_aviao = registro.codigo_do_aviao; //item.modelo = registro.modelo; //item.qtd_passageiros = registro.qtd_passageiros; _repository.Atualizar(registro); }
public async Task <int> AddAirplaneAsync(AirplaneViewModel model) { var airplane = _mapper.Map <Airplane>(model); _context.Airplanes.Add(airplane); await _context.SaveChangesAsync(); return(airplane.Id); }
public async Task <ActionResult <Response <string> > > UpdateAirport(int id, [FromBody] AirplaneViewModel model) { Response <string> updateResult = await _airplaneService.UpdateAirplaneAsync(id, model); if (updateResult.Success == false) { return(BadRequest(updateResult)); } return(Ok(updateResult)); }
public async Task <ActionResult <AirplaneViewModel> > Add([FromBody] AirplaneViewModel airplaneViewModel) { if (!ModelState.IsValid) { return(CustomReponse(ModelState)); } await _dbAirplane.Add(_mapper.Map <Airplane>(airplaneViewModel)); return(CustomResponse(airplaneViewModel)); }
public IActionResult AirplaneEdit([FromBody] AirplaneViewModel model) { if (!ModelState.IsValid) { NotificarErroModelInvalida(); return(Response(model)); } _airplaneService.Editar(_mapper.Map <AirplaneModel>(model)); return(Response()); }
public IActionResult Put([FromBody] AirplaneViewModel airplaneViewModel) { if (!ModelState.IsValid) { NotificarErroModelInvalida(); return(Response()); } _airplaneAppService.Update(airplaneViewModel); return(Response(airplaneViewModel)); }
public async Task <ActionResult <AirplaneViewModel> > Post(AirplaneViewModel airplane) { var response = await _airplaneService.Create(airplane.ToModel()); if (response != BusinessLogic.Enums.StatusCode.Created) { _logger.LogError($"Airplane {airplane.Name} not Created."); } return(response == BusinessLogic.Enums.StatusCode.Created ? (ActionResult <AirplaneViewModel>)Ok() : Conflict()); }
public IActionResult Put([FromBody] AirplaneViewModel airplaneViewModel) { if (!ModelState.IsValid) { NotificarErroModelInvalida(); return(Response()); } var updateAirplane = _mapper.Map <AirplaneUpdateCommand>(airplaneViewModel); _bus.SendCommand(updateAirplane); return(Response(updateAirplane)); }
public async Task <IActionResult> Create(AirplaneViewModel model) { //TODO: use automapper and remove this code from here var newAirplane = new Airplane { Name = model.Name, KeroseneConsumption = model.KeroseneConsumption, Speed = model.Speed }; _unitOfWork.AirplaneRepository.Add(newAirplane); await _unitOfWork.SaveAsync(); return(RedirectToAction("Index")); }
public ResponseResult <int> Add(AirplaneViewModel model) { using (_unitOfWork) { var map = _mapper.Map <AirplaneModel>(model); var result = _airplaneService.Add(map); if (result.IsValid) { _unitOfWork.Commit(); return(new ResponseResult <int>(result.Data.Id)); } else { return(new ResponseResult <int>(result.ValidationResult)); } } }
public IActionResult Put([FromBody] AirplaneViewModel airplaneView) { try { Airplane airplane = new Airplane(airplaneView.Model, airplaneView.NumberOfPassenger, airplaneView.CreatedDate, airplaneView.Id); _service.Put <AirplaneValidator>(airplane); return(new ObjectResult(airplane)); } catch (ArgumentNullException ex) { return(NotFound(ex)); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <Response <string> > UpdateAirplaneAsync(int id, AirplaneViewModel model) { var airplane = await _context.Airplanes.FindAsync(id); if (airplane == null) { return(new Response <string> { Success = false, Message = "There is no such airplane" }); } _mapper.Map(model, airplane); await _context.SaveChangesAsync(); return(new Response <string> { Success = true, Message = "Aiplane was succesfully updated" }); }
public async Task <IActionResult> Create(AirplaneViewModel airplaneViewModel) { if (ModelState.IsValid) { var path = string.Empty; if (airplaneViewModel.ImageFile != null) { path = await _imageHelper.UpLoadImageAsync(airplaneViewModel.ImageFile, "Airplanes"); } var airplane = _converterHelper.ToAirplane(airplaneViewModel, path, true); airplane.User = await _userHelper.GetUserByEmailAsync(User.Identity.Name); await _repository.CreateAsync(airplane); return(RedirectToAction(nameof(Index))); } return(View(airplaneViewModel)); }
public void Inserir(AirplaneViewModel registro) { registro.dt_criacao_registro = DateTime.Now; _repository.Inserir(registro); }
public async Task <ActionResult <int> > PostAirplane([FromBody] AirplaneViewModel model) { int newAirportId = await _airplaneService.AddAirplaneAsync(model); return(Ok(newAirportId)); }
public IActionResult Add([FromBody] AirplaneViewModel model) { var result = _airplaneAppService.Add(model); return(ProcessResponseResult(result)); }
public void Insert([FromBody] AirplaneViewModel airplaneViewModel) { var airplane = _mapper.Map <Airplane>(airplaneViewModel); _airplaneService.Adicionar(airplane); }
public void Update(AirplaneViewModel airplaneViewModel) { var command = _mapper.Map <UpdateAirplaneCommand>(airplaneViewModel); _bus.SendCommand(command); }
public void Add(AirplaneViewModel airplaneViewModel) { var command = _mapper.Map <AddAirplaneCommand>(airplaneViewModel); _bus.SendCommand(command); }
public static Airplane ToModel(this AirplaneViewModel model) => Mapper.Map <Airplane>(model);
public void Put([FromBody] AirplaneViewModel airplaneViewModel) { var airplane = _mapper.Map <Airplane>(airplaneViewModel); _airplaneService.Atualizar(airplane); }
public async Task <ActionResult <AirplaneViewModel> > Update([FromRoute] Guid id, [FromBody] AirplaneViewModel airplaneViewModel) { if (id != airplaneViewModel.Id) { NotifyError("ID diferente do ID informado no objeto"); return(CustomResponse(airplaneViewModel)); } await _dbAirplane.Update(_mapper.Map <Airplane>(airplaneViewModel)); return(CustomResponse(airplaneViewModel)); }