public async Task CreateAccountAsync(Taikhoan account, byte role) { if (account == null) { throw new ArgumentNullException(nameof(account)); } // Validate if (role != 2 && role != 3) { return; } // Create account _context.Taikhoans.Add(account); await _context.SaveChangesAsync(); // Get account Id var MaNd = await _context.Taikhoans.Where(p => p.Email == account.Email).Select(p => p.MaTk).FirstOrDefaultAsync(); // Create User _context.Nguoidungs.Add(new Nguoidung { Vaitro = role, MaNd = MaNd }); await _context.SaveChangesAsync(); }
public async Task CreateBusStationAsync(Benxe busStation) { if (busStation == null) { throw new ArgumentNullException(nameof(busStation)); } _context.Benxes.Add(busStation); await _context.SaveChangesAsync(); }
public async Task CreateGarageAsync(Nhaxe garage) { if (garage == null) { throw new ArgumentNullException(nameof(garage)); } _context.Nhaxes.Add(garage); await _context.SaveChangesAsync(); }
public async Task CreateTicketAsync(IEnumerable <Vexe> ticket) { if (ticket == null) { throw new ArgumentNullException(nameof(ticket)); } _context.Vexes.AddRange(ticket); await _context.SaveChangesAsync(); }
public async Task CreateBusTripAsync(Chuyenxe busTrip) { if (busTrip == null) { throw new ArgumentNullException(nameof(busTrip)); } _context.Chuyenxes.Add(busTrip); await _context.SaveChangesAsync(); }
public async Task CreateRevenueAsync(Doanhthungay dayliRevenue) { if (dayliRevenue == null) { throw new ArgumentNullException(nameof(dayliRevenue)); } _context.Doanhthungays.Add(dayliRevenue); await _context.SaveChangesAsync(); }
public async Task CreateBusAsync(Xe bus) { if (bus == null) { throw new ArgumentNullException(nameof(bus)); } _context.Xes.Add(bus); await _context.SaveChangesAsync(); }
public async Task CreateBusRouteAsync(Tuyenxe busRoute) { if (busRoute == null) { throw new ArgumentNullException(nameof(busRoute)); } var check = await _context.Tuyenxes.Where(p => p.MaBxden == busRoute.MaBxden && p.MaBxdi == busRoute.MaBxdi && p.MaNhaXe == busRoute.MaNhaXe) .Select(p => p.MaTuyenXe).FirstOrDefaultAsync(); if (check == 0) { _context.Tuyenxes.Add(busRoute); await _context.SaveChangesAsync(); } }
public async Task CreateReviewAsync(Danhgia review) { var ticket = await _context.Vexes.Where(p => p.MaVe == review.MaVe && p.MaKh == review.MaNd).Select(p => p.TrangThai).FirstOrDefaultAsync(); if (ticket == null || ticket == false) { return; } if (review == null) { throw new ArgumentNullException(nameof(review)); } _context.Danhgias.Add(review); await _context.SaveChangesAsync(); }
public async Task CreateHistoryAsync(Lichsutimkiem history) { if (history == null) { throw new ArgumentNullException(nameof(history)); } _context.Lichsutimkiems.Add(history); var count = await _context.Lichsutimkiems.Where(p => p.MaNd == history.MaNd).CountAsync(); if (count >= 5) { var oldestHistory = await _context.Lichsutimkiems.Where(p => p.MaNd == history.MaNd).FirstOrDefaultAsync(); _context.Lichsutimkiems.Remove(oldestHistory); } await _context.SaveChangesAsync(); }
public async Task UpdateUserAsync(Nguoidung user) { await _context.SaveChangesAsync(); }