public async Task <bool> AddCarReservationAsync(CarReservation reservation) { var carReservation = await context.CarReservations.FirstOrDefaultAsync(item => item.Id == reservation.Id); if (carReservation is object) { return(false); } var car = await context.Cars.FirstOrDefaultAsync(item => item.Id == reservation.ReservedCarId); //var user = await context.User.FirstOrDefaultAsync(item => item.Email == reservation.OwnerEmail); car.IsReserved = true; if (reservation.Discount > 0) { var costPerDay = (reservation.To - reservation.From).Value.TotalDays * car.CostPerDay; reservation.CostForRange = costPerDay - (costPerDay * (reservation.Discount / 100)); } reservation.ReservedCar = car; //reservation.Owner = user; await context.CarReservations.AddAsync(reservation); await context.SaveChangesAsync(); return(true); }
public async Task <IActionResult> PutCar(Guid id, Car car) { if (id != car.Id) { return(BadRequest()); } _context.Entry(car).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <bool> AddAsync(Branch branch) { var b = await context.FindAsync <Branch>(branch.Id); if (b is object) { return(false); } await context.AddAsync(branch); await context.SaveChangesAsync(); return(true); }
public async Task <bool> AddAsync(Core.Entities.RentACar rentACar) { var r = await context.FindAsync <Core.Entities.RentACar>(rentACar.Id); if (r is object) { return(false); } await context.AddAsync(rentACar); await context.SaveChangesAsync(); return(true); }
public async Task <bool> AddAsync(Car car) { var c = await context.FindAsync <Car>(car.Id); if (c is object) { return(false); } await context.AddAsync(car); await context.SaveChangesAsync(); return(true); }
public async Task <bool> AddAsync(RatingModel ratingModel) { var rating = await context.Ratings.FirstOrDefaultAsync(item => item.Id == ratingModel.Id) ?? new Rating() { Value = ratingModel.Value }; if (rating.Id != 0) { // ako je pronašao rating da vec postoji return(false); } rating.RatingGiverEmail = ratingModel.UserId; rating.CarId = ratingModel.CarId; if (rating.CarId != 0) { var carReservation = await context.CarReservations.FirstOrDefaultAsync(item => item.Id == ratingModel.ReservationId); carReservation.Rating = rating.Value; } // ovde dodaješ pronalaženje dodatnih polja ako ih dodaš u rating model await context.Ratings.AddAsync(rating); await context.SaveChangesAsync(); return(true); }
public async Task Remove(int id, CancellationToken cancellationToken = default) { var objDomain = await _context.Set <TDatabase>().FindAsync(id); _context.Set <TDatabase>().Remove(objDomain); await _context.SaveChangesAsync(cancellationToken); }