public async Task <AddResult> AddAsync(Flight flight) { FlightEntity flightDal = _mapper.Map <FlightEntity>(flight); AirportEntity toAirport = await _airportRepository.GetByIdAsync(flightDal.ToAirportId); AirportEntity fromAirport = await _airportRepository.GetByIdAsync(flightDal.FromAirportId); if (toAirport == null || fromAirport == null) { return(new AddResult(ResultTypes.NotFound, null)); } AirplaneEntity airplane = await _airplaneRepository.GetByIdAsync(flightDal.AirplaneId); if (airplane == null) { return(new AddResult(ResultTypes.NotFound, null)); } if (flight.ArrivalTime <= flight.DepartureTime) { return(new AddResult(ResultTypes.InvalidData, null)); } int addedFlightId = await _flightRepository.AddAsync(flightDal); return(new AddResult(ResultTypes.Ok, addedFlightId)); }
public async Task <bool> CheckDuplicateAsync(AirportEntity item) { AirportEntity duplicate = _airportsData.FirstOrDefault(x => x.Name == item.Name && x.CityId == item.CityId); return(duplicate != null); }
public async Task <AddAirportResult> Handle(AddAirportCommand request, CancellationToken cancellationToken) { var country = await _unitOfWork.Countries.GetByIdAsync(request.CountryId, cancellationToken); var airportType = await _unitOfWork.AirportTypes.GetByIdAsync(request.TypeId, cancellationToken); var size = await _unitOfWork.AirportSizes.GetByIdAsync(request.SizeId, cancellationToken); var status = await _unitOfWork.AirportStatuses.GetByIdAsync(request.StatusId, cancellationToken); var airport = new AirportEntity { Id = Guid.NewGuid(), Iata = request.Iata, Name = request.Name, Country = country, Type = airportType, Size = size, Status = status, Lon = request.Lon, Lat = request.Lat }; await _unitOfWork.Airports.CreateAsync(airport, cancellationToken); await _unitOfWork.SaveChanges(cancellationToken); return(new AddAirportResult(airport.Id)); }
public bool AddNewAirport(AirportEntity ae) { int result; string sql = "INSERT INTO airport([code], [name], [city], [state], [country], [utc_time],[deleted], [openning]) "; sql += "VALUES(@code, @name, @city, @state, @country, @utc_time,@deleted, @openning)"; ParameterPair[] p = new ParameterPair[8]; p[0] = new ParameterPair("@code", ae.Code); p[1] = new ParameterPair("@name", ae.Name); p[2] = new ParameterPair("@city", ae.City); p[3] = new ParameterPair("@state", ae.State); p[4] = new ParameterPair("@country", ae.Country); p[5] = new ParameterPair("@utc_time", ae.UtcTime); p[6] = new ParameterPair("@deleted", ae.Deleted.ToString()); p[7] = new ParameterPair("@openning", ae.Openning.ToString()); result = _dbconnection.ExecuteNonQuery(sql, p); if (result > 0) { return(true); } else { return(false); } }
public async Task <ResultTypes> UpdateAsync(Flight newFlight) { FlightEntity flightDal = _mapper.Map <FlightEntity>(newFlight); AirportEntity toAirport = await _airportRepository.GetByIdAsync(flightDal.ToAirportId); AirportEntity fromAirport = await _airportRepository.GetByIdAsync(flightDal.FromAirportId); if (toAirport == null || fromAirport == null) { return(ResultTypes.NotFound); } AirplaneEntity airplane = await _airplaneRepository.GetByIdAsync(flightDal.AirplaneId); if (airplane == null) { return(ResultTypes.NotFound); } if (newFlight.ArrivalTime <= newFlight.DepartureTime) { return(ResultTypes.InvalidData); } await _flightRepository.UpdateAsync(flightDal); return(ResultTypes.Ok); }
public AirportEntity InsertAirportEntity(AirportEntity airport) { AirportEntity pass = context.Airports.Add(airport); context.SaveChanges(); return(pass); }
public void UpdateAirport(Guid airportId, AirportFormUpdate airportFormUpdate) { AirportEntity entity = _context.Airports.SingleOrDefault(a => a.Id == airportId); _mapper.Map(airportFormUpdate, entity); _context.SaveChanges(); }
public AirportDto toDto(AirportEntity airport) { AirportDto airportDto = new AirportDto(); airportDto.AirportId = airport.AirportId; airportDto.City = airport.City; return(airportDto); }
public AirportEntity toEntity(AirportDto airportDto) { AirportEntity airport = new AirportEntity(); airport.AirportId = airportDto.AirportId; airport.City = airportDto.City; return(airport); }
public async Task UpdateAsync(AirportEntity airport) { using SqlConnection db = new SqlConnection(_dalSettings.ConnectionString); await db.ExecuteAsync( "UpdateAirport", new { id = airport.Id, name = airport.Name, cityId = airport.CityId }, commandType : CommandType.StoredProcedure); }
public async Task <bool> CheckDuplicateAsync(AirportEntity airport) { using SqlConnection db = new SqlConnection(_dalSettings.ConnectionString); return(await db.ExecuteScalarAsync <bool>( "CheckAirportDuplicate", new { name = airport.Name, cityId = airport.CityId }, commandType : CommandType.StoredProcedure)); }
public async Task <int> AddAsync(AirportEntity airport) { using SqlConnection db = new SqlConnection(_dalSettings.ConnectionString); return(await db.QuerySingleOrDefaultAsync <int>( "AddAirport", new { name = airport.Name, cityId = airport.CityId }, commandType : CommandType.StoredProcedure)); }
public void DeleteAirportEntity(int id) { AirportEntity pass = new AirportEntity() { AirportId = id }; context.Airports.Attach(pass); context.Airports.Remove(pass); context.SaveChanges(); }
public AirportEntity GetAirportEntityByID(int Id) { AirportEntity airport = null; using (var context = new TUIAssessmentDALContext(_options)) { airport = context.Airports.Single(a => a.Id == Id); } return(airport); }
public Airport GetAirportById(Guid id) { AirportEntity entity = _context.Airports.SingleOrDefault(a => a.Id == id); if (entity == null) { return(null); } return(_mapper.Map <Airport>(entity)); }
public void DeleteAirport(Guid airportId) { AirportEntity entity = _context.Airports.SingleOrDefault(a => a.Id == airportId); if (entity == null) { return; } _context.Remove(entity); _context.SaveChanges(); }
private async Task <bool> Update(AirportEntity airport) { try { _context.Update(airport); return(await _context.SaveChangesAsync() > 0); } catch (Exception e) { Console.WriteLine(e); return(false); } }
private void btnAdd_Click(object sender, EventArgs e) { if (btnAdd.Text.Equals("Add")) { btnAdd.Text = "Save"; LockControls(false); ClearBindingControls(); ClearControls(); } else if (btnAdd.Text.Equals("Save")) { AirportEntity ae = new AirportEntity(); ae.Code = txtCode.Text; ae.Name = txtName.Text; ae.City = txtCity.Text; ae.State = txtState.Text; ae.Country = txtCountry.Text; ae.UtcTime = txtUTCTime.Text; ae.Openning = chkClosed.Checked; ae.Deleted = false; AirportDAL ado = new AirportDAL(); if (!ado.AddNewAirport(ae)) { MessageBox.Show("Can not insert new Airport. Please check again.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } else { DataRow newRow = dsAirport.Tables["Airport"].NewRow(); newRow["code"] = ae.Code; newRow["name"] = ae.Name; newRow["city"] = ae.City; newRow["state"] = ae.State; newRow["country"] = ae.Country; newRow["utc_time"] = ae.UtcTime; newRow["openning"] = ae.Openning; newRow["deleted"] = ae.Deleted; dsAirport.Tables["Airport"].Rows.Add(newRow); BindingControls(); ClearControls(); LockControls(true); // LoadAirportList(lsbCountry.GetItemText(lsbCountry.SelectedItem)); } } }
public async Task <bool> Add(AirportEntity airport) { try { await _context.Airports.AddAsync(airport); return(await _context.SaveChangesAsync() > 0); } catch (Exception e) { Console.WriteLine(e); return(false); } }
public Airport CreateAirport(AirportFormCreate airportFormCreate) { AirportEntity entity = _mapper.Map <AirportEntity>(airportFormCreate); entity.Id = Guid.NewGuid(); _context.Airports.Add(entity); var created = _context.SaveChanges(); if (created < 1) { throw new InvalidOperationException("Could not create new airport."); } return(_mapper.Map <Airport>(entity)); }
public List <AirportEntity> GetAirportList() { List <AirportEntity> list = new List <AirportEntity>(); string sql = "SELECT [code], [name], [city], [state], [country], [utc_time],[deleted], [openning] "; sql += " FROM airport "; SqlDataReader dr = _dbconnection.ExecuteReader(sql); AirportEntity ae; while (dr.Read()) { ae = new AirportEntity(dr["code"].ToString(), dr["name"].ToString(), dr["city"].ToString(), dr["state"].ToString(), dr["country"].ToString(), dr["utc_time"].ToString(), bool.Parse(dr["deleted"].ToString()), bool.Parse(dr["openning"].ToString())); list.Add(ae); } return(list); }
public AirportEntity GetAirportByCode(string code) { string sql = "SELECT [code], [name], [city], [state], [country], [utc_time],[deleted], [openning] "; sql += " FROM airport WHERE [code]=@CODE"; SqlDataReader dr = _dbconnection.ExecuteReader(sql, new ParameterPair[] { new ParameterPair("@CODE", code) }); AirportEntity ae; if (dr.Read()) { ae = new AirportEntity(dr["code"].ToString(), dr["name"].ToString(), dr["city"].ToString(), dr["state"].ToString(), dr["country"].ToString(), dr["utc_time"].ToString(), bool.Parse(dr["deleted"].ToString()), bool.Parse(dr["openning"].ToString())); return(ae); } else { return(null); } }
public static Airport ToModel(this AirportEntity model) => Mapper.Map <Airport>(model);
public async Task <int> AddAsync(AirportEntity item) { return(0); }
public async Task UpdateAsync(AirportEntity item) { // implementation }
public AirportDto AddAirport(AirportDto airportDto) { AirportEntity airportEntity = AirportRepository.InsertAirportEntity(AirportMapper.toEntity(airportDto)); return(AirportMapper.toDto(airportEntity)); }
public void UpdateAirportEntity(AirportEntity airport) { throw new NotImplementedException(); }
public async Task Update(AirportEntity entity) { using IDbConnection db = _configuration.GetConnection(); await db.ExecuteAsync("UpdateAirport", entity, commandType : CommandType.StoredProcedure); }