public async Task RemoveCarProfile(string ID) { var carProfile = CarProfiles.Find(ID); Entry(carProfile).State = EntityState.Detached; CarProfiles.Remove(carProfile); await SaveChangesAsync(); }
public async Task <List <CarProfile> > GetAllCars(User user) { var carProfiles = await CarProfiles .Where(c => c.Owner == user) .ToListAsync(); return(carProfiles); }
public async Task <List <PossibleToRentDay> > GetCarProfilePossibleToRentDayTask(string regnr) { var possibleToRentDays = await CarProfiles .Where(cp => cp.RegNr == regnr) .Select(cp => cp.PossibleToRentDays) .SingleOrDefaultAsync(); return(possibleToRentDays); }
public async Task <List <DayThatIsRented> > GetCarProfileRentedDaysTask(string regnr) { var rentedDays = await CarProfiles .Where(cp => cp.RegNr == regnr) .Select(cp => cp.DaysThatIsRented) .SingleOrDefaultAsync(); return(rentedDays); }
public async Task AddCarProfile(CarProfile carProfile) { if (Users.Find(carProfile.RegNr) != null) { throw new AuthenticationFailedException("The car already exists"); } await CarProfiles.AddAsync(carProfile); await SaveChangesAsync(); }
public async Task <CarProfile> GetCarProfileWithDays(string regnr) { var carprofile = new CarProfile(); carprofile = await CarProfiles.SingleAsync(e => e.RegNr == regnr); await Entry(carprofile).Collection(p => p.DaysThatIsRented).LoadAsync(); await Entry(carprofile).Collection(p => p.PossibleToRentDays).LoadAsync(); await Entry(carprofile).Reference(p => p.Owner).LoadAsync(); return(carprofile); }
public async Task <List <CarProfile> > GetAllCarProfiles() { var carProfiles = await CarProfiles .ToListAsync(); foreach (var carProfile in carProfiles) { await Entry(carProfile).Reference(c => c.Owner).LoadAsync(); } return(carProfiles); }
public async Task <List <CarProfile> > GetCarProfilesForSearchView(string filterEmail, int pageIndex, int itemsPerPage) { var carProfiles = await CarProfiles .Where(cp => cp.OwnerEmail != filterEmail) .Skip(pageIndex * itemsPerPage) .Take(itemsPerPage) .ToListAsync(); foreach (var carProfile in carProfiles) { await Entry(carProfile).Reference(c => c.Owner).LoadAsync(); } return(carProfiles); }
public async Task UpdateCarProfile(CarProfile carProfile) { var result = await CarProfiles.SingleOrDefaultAsync(b => b.RegNr == carProfile.RegNr); if (result == default(CarProfile)) { return; } Update(result); result.CarPicture = carProfile.CarPicture ?? result.CarPicture; result.Age = carProfile.Age; result.Brand = carProfile.Brand ?? result.Brand; result.CarDescription = carProfile.CarDescription ?? result.CarDescription; //result.CarEquipment = carProfile.CarEquipment ?? result.CarEquipment; result.StartLeaseTime = carProfile.StartLeaseTime; result.EndLeaseTime = carProfile.EndLeaseTime; result.FuelType = carProfile.FuelType ?? result.FuelType; result.Model = carProfile.Model ?? result.Model; result.RentalPrice = carProfile.RentalPrice; result.RegNr = carProfile.RegNr ?? result.RegNr; result.Seats = carProfile.Seats; await SaveChangesAsync(); }
public async Task <CarProfile> GetCarProfile(string regNr) { var carProfile = await CarProfiles.Include(cp => cp.Owner).FirstOrDefaultAsync(cp => cp.RegNr == regNr); return(carProfile); }
public async Task <int> GetCarProfilesCount() { return(await CarProfiles.CountAsync()); }