public void Put(int id, [FromBody] AirplaneDTO airplane) { if (ModelState.IsValid) { service.Update(id, airplane); } }
public async Task PutAirplane_ReturnsAirplane_IfModelValid() { Guid id = new Guid("9e17af7b-df05-4c69-94b8-586659c7152f"); Airplane fakeAirplane = airplaneList.FirstOrDefault(c => c.Id == id); AirplaneDTO newAirplane = new AirplaneDTO { Name = "BA2490", Type = "Boeing 737 MIN", TotalSeats = 200 }; mockAirplaneRepo.Setup(repo => repo.GetAsyncByGuid(It.IsAny <Guid>())).Returns(Task.FromResult(fakeAirplane)); mockAirplaneRepo.Setup(repo => repo.GetAirplaneByName(It.IsAny <string>())).Returns(Task.FromResult(fakeAirplane)); mockAirplaneRepo.Setup(repo => repo .Update(It.IsAny <Airplane>(), It.IsAny <Guid>())) .Returns(Task.FromResult(mapper.Map <AirplaneDTO, Airplane>(newAirplane))); mockAirplaneRepo.Verify(); var actionResult = await APIcontroller.PutAirplane(id, newAirplane); var createdResult = (OkObjectResult)actionResult.Result; Assert.IsNotNull(createdResult); //null Assert.IsInstanceOfType(createdResult, typeof(OkObjectResult)); //type Assert.IsInstanceOfType(createdResult.Value, typeof(AirplaneDTO)); Assert.AreEqual(200, createdResult.StatusCode); //statuscode }
public void Post([FromBody] AirplaneDTO airplane) { if (ModelState.IsValid) { service.Create(airplane); } }
public IActionResult Put(Guid id, AirplaneDTO airplane) { var newAirplaneCommand = new NewAirplaneCommand(airplane); _updatehandler.Handle(newAirplaneCommand); return(Response(newAirplaneCommand)); }
public IActionResult Put(AirplaneDTO airplaneDTO) { var airplaneEntity = _mapper.Map <AirplaneEntity>(airplaneDTO); _baseAirplaneService.Atualizar(airplaneEntity); return(Ok(airplaneEntity)); }
public IActionResult Post(AirplaneDTO airplane) { var newAirplaneCommand = new NewAirplaneCommand(airplane); _handler.Handle(newAirplaneCommand); return(Response(newAirplaneCommand)); }
public List <AirportDTO> LoadDataAirport() { List <AirportDTO> list = new List <AirportDTO>(); using (var db = new TravelAirportContext()) { var query = from b in db.Airports orderby b.Name select b; foreach (var item in query) { AirportDTO p = new AirportDTO(); p.Name = item.Name; p.GPS = item.GPS; p.listAirplane = new List <AirplaneDTO>(); foreach (var airplaneitem in item.Airplanes) { AirplaneDTO airplane = new AirplaneDTO(); airplane.AirplaneId = airplaneitem.AirplaneId; airplane.FuelConsumption = airplaneitem.FuelConsumption; airplane.TakeoffEffort = airplaneitem.TakeoffEffort; airplane.Title = airplaneitem.Title; p.listAirplane.Add(airplane); } list.Add(p); } } return(list); }
public async Task Update(int id, AirplaneDTO modelDTO) { var source = uow.Airplanes.Get(id); var dest = mapper.Map <AirplaneDTO, Airplane>(modelDTO); await uow.Airplanes.Update(dest); await uow.SaveAsync(); }
public FlightDTO CreateDTO(Flight entity) { AirplaneDTO airplaneDto = new AirplaneDTO(); Flight flight = (Flight)entity; FlightDTO FlightDTO = DTOFactory.CreateFlightDTO(flight.plane, flight.price, flight.departure, flight.arrival, flight.loc_departure, flight.loc_arrival); return(FlightDTO); }
public async Task <IActionResult> Get(int id) { AirplaneDTO plane = await service.GetById(id); if (plane == null) { return(NotFound()); } return(Ok(plane)); }
public static Airplane Mapp(AirplaneDTO entity, IUnitOfWork data) { var airplanes = data.Set <AirplaneType>().Get(); Mapper.Initialize(cfg => cfg.CreateMap <AirplaneDTO, Airplane>() .ForMember("Type", opt => opt.MapFrom(c => airplanes.FirstOrDefault(a => a.Model == c.TypeModel)))); var res = Mapper.Map <AirplaneDTO, Airplane>(entity); return(res); }
public void AddAirplane(AirplaneDTO dto) { var airplane = new Airplane { Distance = dto.Distance, Model = dto.Model, LiftingCapacity = dto.LiftingCapacity, PassengerCapacity = dto.PassengerCapacity }; _db.Add(airplane); _db.SaveChanges(); }
public async Task Create(AirplaneDTO item) { var model = mapper.Map <AirplaneDTO, Airplane>(item); var validationResult = validator.Validate(model); if (validationResult.IsValid) { await uow.Airplanes.Create(model); await uow.SaveAsync(); } throw new ValidationException(validationResult.Errors); }
public AddFlightForm(ICollection <CityDTO> cities, ICollection <AirplaneDTO> airplanes, ICollection <FlightDTO> flights) { InitializeComponent(); var emptyCity = new CityDTO { Id = -1, Name = "Не выбрано" }; var emptyAirplane = new AirplaneDTO { Id = -1, Model = "Не выбрано" }; cities.Add(emptyCity); airplanes.Add(emptyAirplane); _cities = cities.OrderBy(x => x.Id).ToArray(); _airplanes = airplanes.OrderBy(x => x.Id).ToArray(); _flights = flights.ToArray(); FlightCityComboBox.DisplayMember = "Name"; FlightCityComboBox.ValueMember = "Id"; FlightCityComboBox.DataSource = _cities; FlightAirplaneComboBox.DisplayMember = "Model"; FlightAirplaneComboBox.ValueMember = "Id"; FlightAirplaneComboBox.DataSource = _airplanes; RegistryNumberComboBox.DataSource = new object[] { "Не выбрано", 1, 2, 3, 4 }; FlightCityComboBox.SelectedItem = emptyCity; FlightAirplaneComboBox.SelectedItem = emptyAirplane; RegistryNumberComboBox.SelectedIndex = 0; SoldTicketsAmountNumeric.Controls[0].Hide(); FlightAirplaneComboBox.Enabled = false; SoldTicketsAmountNumeric.Enabled = false; }
public IEnumerable <AirplaneDTO> GetAirplanes() { IEnumerable <Airplane> airplanes; try { airplanes = airplaneRepository.GetAll(); logger.LogInformation("Successfully retrieved airplanes"); } catch (Exception e) { logger.LogError(e, "Issue with getting airplanes from DB."); airplanes = Enumerable.Empty <Airplane>(); } return(airplanes.Select(a => AirplaneDTO.FromDBModel(a))); }
public void UpdateAirplane(AirplaneDTO dto) { var airplane = _db.Airplanes.FirstOrDefault(x => x.Id == dto.Id); if (airplane == null) { return; } airplane.Distance = dto.Distance; airplane.Model = dto.Model; airplane.LiftingCapacity = dto.LiftingCapacity; airplane.PassengerCapacity = dto.PassengerCapacity; _db.Airplanes.Update(airplane); _db.SaveChanges(); }
public async Task <IActionResult> Post([FromBody] AirplaneDTO modelDTO) { if (modelDTO == null) { ModelState.AddModelError("", "Plane structure is wrong!!!"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await service.Create(modelDTO); return(Created("api/Airplanes", modelDTO)); }
public async Task <IActionResult> Put(int id, [FromBody] AirplaneDTO modelDTO) { if (modelDTO == null) { ModelState.AddModelError("", "Plane structure is wrong!!!"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await service.Update(id, modelDTO); return(Ok(modelDTO)); }
public List <AirplaneDTO> LoadDataAirplane() { List <AirplaneDTO> list = new List <AirplaneDTO>(); using (var db = new TravelAirportContext()) { var query = from b in db.Airplanes orderby b.Title select b; foreach (var item in query) { AirplaneDTO p = new AirplaneDTO(); p.Title = item.Title; p.TakeoffEffort = item.TakeoffEffort; p.FuelConsumption = item.FuelConsumption; list.Add(p); } } return(list); }
public async Task PostAirplane_ReturnsAirplane_IfModelValid() { AirplaneDTO newAirplane = new AirplaneDTO { Name = "BA2490", Type = "Boeing 737 MAX", TotalSeats = 200 }; mockAirplaneRepo.Setup(repo => repo.Create(It.IsAny <Airplane>())).Returns(Task.FromResult(mapper.Map <AirplaneDTO, Airplane>(newAirplane))); mockAirplaneRepo.Verify(); var actionResult = await APIcontroller.PostAirplane(newAirplane); var createdResult = (OkObjectResult)actionResult.Result; Assert.IsNotNull(createdResult); //null Assert.IsInstanceOfType(createdResult, typeof(OkObjectResult)); //type Assert.IsInstanceOfType(createdResult.Value, typeof(AirplaneDTO)); Assert.AreEqual(200, createdResult.StatusCode); //statuscode }
private void AddAirplaneButton_Click(object sender, EventArgs e) { if (IsValidForm()) { AirplaneDTO = new AirplaneDTO { Model = AirplaneModelTextBox.Text, Distance = (int)AirplaneDistanceNumeric.Value, PassengerCapacity = (int)PassengerCapacityNumeric.Value, LiftingCapacity = (int)LiftingCapacityNumeric.Value }; DialogResult = DialogResult.OK; } else { var errorTextBuilder = new StringBuilder(); errorTextBuilder.AppendJoin("\n", _errorMessagesList).ToString(); errorTextBuilder.AppendLine("\n\nПроверьте вводимые значения и попробуйте еще раз."); var errorText = errorTextBuilder.ToString(); MessageBox.Show(errorText, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); _errorMessagesList = new List <string>(); } }
public async Task <ActionResult <Airplane> > Post([FromServices] IAirplaneAppServico app, AirplaneDTO airplaneDTO) { airplaneDTO.Validate(); if (airplaneDTO.Invalid) { return(BadRequest(new RetornoDTO() { Success = false, Message = "Não foi possível cadastrar o airplane", Data = airplaneDTO.Notifications })); } try { await app.InsertAsync(_mapper.Map <Airplane>(airplaneDTO)); return(Ok(new RetornoDTO() { Success = true, Message = "Airplane cadastrado com sucesso", Data = airplaneDTO })); } catch (Exception) { throw; } }
public void Create(AirplaneDTO entity) { var mappAirplane = AirplaneMapp.Mapp(entity, data); data.Set <Airplane>().Create(mappAirplane); }
private void CancelAirplaneButton_Click(object sender, EventArgs e) { AirplaneDTO = null; _errorMessagesList = new List <string>(); DialogResult = DialogResult.Cancel; }
public void Update(int id, AirplaneDTO entity) { var mappAirplane = AirplaneMapp.Mapp(entity, data); data.Set <Airplane>().Update(id, mappAirplane); }
public async Task <IActionResult> Put([FromServices] IAirplaneAppServico app, AirplaneDTO airplaneDTO) { airplaneDTO.Validate(); if (airplaneDTO.Invalid) { return(BadRequest(new RetornoDTO() { Success = false, Message = "Não foi possível editar airplane", Data = airplaneDTO.Notifications })); } try { app.Update(_mapper.Map <Airplane>(airplaneDTO)); } catch (DbUpdateConcurrencyException) { if (!app.Exists(x => x.Id == airplaneDTO.Id)) { return(NotFound()); } else { throw; } } return(Ok(new RetornoDTO() { Success = true, Message = "Airplane editado com sucesso", Data = airplaneDTO })); }
public async Task Update(AirplaneDTO modelDTO) { var dest = mapper.Map <AirplaneDTO, Airplane>(modelDTO); await uow.Airplanes.Update(dest); }
public NewAirplaneCommand(AirplaneDTO airplane) { Airplane = airplane; }
public UpdateAirplaneCommand(AirplaneDTO airplane) { Airplane = airplane; }