public async Task <IActionResult> PutVol(int id, Vol vol) { if (id != vol.ID_VOL) { return(BadRequest()); } _context.Entry(vol).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VolExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutBagage(int id, Bagage bagage) { if (id != bagage.ID_BAGAGE) { return(BadRequest()); } _context.Entry(bagage).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BagageExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public virtual async Task <int> Create(TEntity entity) { DbContext.SetOf <TEntity>().Add(entity); await DbContext.SaveChangesAsync(); return(entity.Id); }
public async Task <IActionResult> PutFlight([FromRoute] int id, [FromBody] Flight flight) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != flight.FlightId) { return(BadRequest()); } _context.Entry(flight).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FlightExists(id)) { return(NotFound()); } else { throw; //var reloadFlight = await _context.Flights.FindAsync(id); //_context.Entry(flight).State = EntityState.Modified; //await _context.SaveChangesAsync(); } } return(NoContent()); }
public async Task <object> CreateAsync(TEntity entity) { await _ctx.Set <TEntity>().AddAsync(entity); // make save to get created entity id await _ctx.SaveChangesAsync(); return(entity.Id); }
public async Task <object> CreateAsync(Flight entity) { await _ctx.Flights.AddAsync(entity); // make save to get created entity id await _ctx.SaveChangesAsync(); return(entity.Number); }
public async Task <UserDTO> Authentificate(string nickname, string password) { if (string.IsNullOrEmpty(nickname) || string.IsNullOrEmpty(password)) { throw new ArgumentNullException("Username or password can not be empty"); } var user = (await context.Set <User>().SingleOrDefaultAsync(u => u.Login == nickname)); if (user == null || !VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt)) { throw new ArgumentException("Wrong email or password"); } await context.SaveChangesAsync(); return(mapper.Map <User, UserDTO>(user)); }
public virtual async Task <TEntity> AddAsync(TEntity entity) { if (entity == null) { throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null"); } try { EntityEntry <TEntity> entry = await AirportContext.AddAsync(entity); await AirportContext.SaveChangesAsync(); return(entry.Entity); } catch (DbUpdateException dbEx) { throw new DbUpdateException($"Issue while saving to DB: {dbEx.Message}"); } catch (Exception ex) { throw new Exception($"{nameof(entity)} could not be saved: {ex.Message}"); } }
public async Task Update(Crew entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } Crew temp = await context.Crews.FindAsync(entity.Id); if (temp != null) { temp.Pilot = entity.Pilot; temp.Stewardesses = entity.Stewardesses; context.Crews.Update(temp); await context.SaveChangesAsync(); } }
public async Task Update(Stewardess entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } Stewardess temp = await context.Stewardesses.FindAsync(entity.Id); if (temp != null) { temp.FirstName = entity.FirstName; temp.LastName = entity.LastName; temp.DateOfBirth = entity.DateOfBirth; temp.CrewId = entity.CrewId; context.Stewardesses.Update(temp); await context.SaveChangesAsync(); } }
public async Task Create(Flight flight) { await data.Flights.AddAsync(flight); await data.SaveChangesAsync(); }
public async Task SaveAsync() { await context.SaveChangesAsync(); }
public async Task Create(Aviator aviator) { await data.Aviators.AddAsync(aviator); await data.SaveChangesAsync(); }
public async Task SaveChanges() { await _airportContext.SaveChangesAsync(); }
public async Task Create(Stewardess stewardess) { await data.Stewardesses.AddAsync(stewardess); await data.SaveChangesAsync(); }
public async Task Create(Departure departure) { await data.Departures.AddAsync(departure); await data.SaveChangesAsync(); }
public async Task Create(Ticket ticket) { await data.Tickets.AddAsync(ticket); await data.SaveChangesAsync(); }
public async Task <Exception> Save() { try { await DB.SaveChangesAsync(); } catch (Exception ex) { return(ex); } return(null); }
public async Task Create(Plane plane) { await data.Planes.AddAsync(plane); await data.SaveChangesAsync(); }
public async Task Create(Crew crew) { await data.Crews.AddAsync(crew); await data.SaveChangesAsync(); }
public async Task Create(TypePlane typePlane) { await data.TypesPlane.AddAsync(typePlane); await data.SaveChangesAsync(); }
public Task <int> SaveChangesAsync() { return(context.SaveChangesAsync()); }
static public async Task Initialize(AirportContext context) { await context.Database.MigrateAsync(); if (context.Flights.Any()) { return; //already seeded } List <Pilot> pilots = new List <Pilot>() { new Pilot() { Name = "PName1", Surname = "PSurname1", Experience = 3 }, new Pilot() { Name = "PName2", Surname = "PSurname2", Experience = 4 }, new Pilot() { Name = "PName3", Surname = "PSurname3", Experience = 9 }, }; List <Stewardess> stewardesses = new List <Stewardess>() { new Stewardess() { Name = "SName1", Surname = "SSurname1", DateOfBirth = new DateTime(1992, 10, 11) }, new Stewardess() { Name = "SName2", Surname = "SSurname2", DateOfBirth = new DateTime(1991, 10, 11) }, new Stewardess() { Name = "SName3", Surname = "SSurname3", DateOfBirth = new DateTime(1993, 10, 11) }, new Stewardess() { Name = "SName4", Surname = "SSurname4", DateOfBirth = new DateTime(1994, 10, 11) }, new Stewardess() { Name = "SName5", Surname = "SSurname5", DateOfBirth = new DateTime(1993, 11, 15) } }; await context.Pilots.AddRangeAsync(pilots); List <Crew> crews = new List <Crew>() { new Crew() { Pilot = pilots[1], Stewardesses = new List <Stewardess> { stewardesses[1], stewardesses[3] } }, new Crew() { Pilot = pilots[0], Stewardesses = new List <Stewardess> { stewardesses[0], stewardesses[2] } }, new Crew() { Pilot = pilots[2], Stewardesses = new List <Stewardess> { stewardesses[4], } } }; await context.Stewardesses.AddRangeAsync(stewardesses); await context.Crews.AddRangeAsync(crews); List <PlaneType> planeTypes = new List <PlaneType>() { new PlaneType() { Model = "Model1", NumberOfSeats = 150, LoadCapacity = 1000 }, new PlaneType() { Model = "Model2", NumberOfSeats = 125, LoadCapacity = 985 }, new PlaneType() { Model = "Model1", NumberOfSeats = 189, LoadCapacity = 1010 } }; await context.PlaneTypes.AddRangeAsync(planeTypes); List <Plane> planes = new List <Plane>() { new Plane() { PlaneType = planeTypes[1], ReleaseDate = new DateTime(2008, 11, 18) }, new Plane() { PlaneType = planeTypes[2], ReleaseDate = new DateTime(2012, 2, 25) }, new Plane() { PlaneType = planeTypes[1], ReleaseDate = new DateTime(2011, 5, 10) }, new Plane() { PlaneType = planeTypes[0], ReleaseDate = new DateTime(2010, 8, 7) } }; await context.Planes.AddRangeAsync(planes); List <Ticket> tickets = new List <Ticket>() { new Ticket() { FlightNumber = 2, Price = 258 }, new Ticket() { FlightNumber = 1, Price = 257 }, new Ticket() { FlightNumber = 2, Price = 256 }, new Ticket() { FlightNumber = 3, Price = 255 } }; await context.Tickets.AddRangeAsync(tickets); List <Flight> flights = new List <Flight>() { new Flight() { Tickets = new List <Ticket>() { tickets[1] }, DepartureFrom = "Kyiv", Destination = "Tokio", ArrivalTime = new DateTime(2018, 02, 03), TimeOfDeparture = new DateTime(2018, 02, 02), }, new Flight() { Tickets = new List <Ticket>() { tickets[0], tickets[2] }, DepartureFrom = "Dublin", Destination = "Paris", ArrivalTime = new DateTime(2017, 02, 03), TimeOfDeparture = new DateTime(2017, 02, 02), }, new Flight() { Tickets = new List <Ticket>() { tickets[3] }, DepartureFrom = "Odesa", Destination = "Ternopil", ArrivalTime = new DateTime(2016, 02, 03), TimeOfDeparture = new DateTime(2016, 02, 02), }, }; await context.Flights.AddRangeAsync(flights); List <Departure> departures = new List <Departure>() { new Departure() { Crew = crews[1], Flight = flights[1], Plane = planes[2], TimeOfDeparture = new DateTime(2017, 02, 03) }, new Departure() { Crew = crews[2], Flight = flights[0], Plane = planes[1], TimeOfDeparture = new DateTime(2018, 02, 03) }, new Departure() { Crew = crews[0], Flight = flights[2], Plane = planes[0], TimeOfDeparture = new DateTime(2016, 02, 03) } }; await context.Departures.AddRangeAsync(departures); await context.SaveChangesAsync(); }
public async Task CommitAsync() { await context.SaveChangesAsync(); }
public async Task <int> SaveChangesAsync(CancellationToken ct = default(CancellationToken)) { return(await dbContext.SaveChangesAsync(ct)); }
public async Task AddRangeAsync(List <Crew> crews) { await _ctx.Crews.AddRangeAsync(crews); await _ctx.SaveChangesAsync(); }
public async Task <int> SaveChangesAsync() { return(await db.SaveChangesAsync()); }
public Task SaveAsync() { return(_context.SaveChangesAsync()); }