Example #1
0
 public static async Task RentToPersonAsync(Guid carId, Person person)
 {
     using (var context = new RentalCarsContext())
     {
         var result = context.Cars.Where(c => c.CarId == carId).FirstOrDefault();
         if (result != null)
         {
             result.Person = person;
             result.Rented = true;
         }
         var historyResult = context.Histories.Where(h => h.CNP == person.CNP).FirstOrDefault();
         if (historyResult == null)
         {
             History h = History.Create(person.FirstName, person.LastName, person.CNP,
                                        person.FromDate, person.ToDate);
             context.Histories.Add(h);
         }
         else
         {
             historyResult.Counter += 1;
             historyResult.FromDate = person.FromDate;
             historyResult.ToDate   = person.ToDate;
         }
         await context.SaveChangesAsync();
     }
 }
Example #2
0
 public static async Task SavePersonAsync(Person person)
 {
     using (var context = new RentalCarsContext())
     {
         context.People.Add(person);
         await context.SaveChangesAsync();
     }
 }
Example #3
0
 public static async Task SaveUserAsync(User user)
 {
     using (var context = new RentalCarsContext())
     {
         context.Users.Add(user);
         await context.SaveChangesAsync();
     }
 }
Example #4
0
 public static async Task SaveCarAsync(Car car)
 {
     using (var context = new RentalCarsContext())
     {
         context.Cars.Add(car);
         await context.SaveChangesAsync();
     }
 }
Example #5
0
        public static async Task FreeCar(Guid carId)
        {
            using (var context = new RentalCarsContext())
            {
                var result       = context.Cars.Where(c => c.CarId == carId).FirstOrDefault();
                var personResult = context.People.Where(p => p.Car.CarId == carId).FirstOrDefault();

                if (result != null)
                {
                    result.Person = null;
                    result.Rented = false;
                    //context.People.Remove(result.Person);
                    personResult.Car = null;
                    await context.SaveChangesAsync();
                }
            }
        }