/// <summary> /// Deletes user by id (Tz) /// </summary> /// <param name="tz"></param> /// <returns></returns> public bool DeleteUser(int tz) { CarRentals rentals = new CarRentals(); List <CarRentals> carRentalsList = new List <CarRentals>(); carRentalsList = rentals.GetRentalByUser(tz); if (carRentalsList != null) { foreach (var rental in carRentalsList) { rentals.DeleteRental(rental.RentalId); } } bool isDeleted = false; User user = db.Users.FirstOrDefault(t => t.TZ == tz); try { db.Users.Remove(user); db.SaveChanges(); isDeleted = true; } catch (Exception msg) { Console.WriteLine(msg); isDeleted = false; } return(isDeleted); }
/// <summary> /// Get rental by car license /// </summary> /// <param name="license"></param> /// <returns></returns> public CarRentals GetRental(int license) { CarRentals carRentals = new CarRentals(); Rental getRental = rentalCardb.Rentals.FirstOrDefault(carLicencse => carLicencse.Cars_for_Rent.License == license); carRentals.RentalId = getRental.Rental_Id; carRentals.RentalStart = getRental.Start_Rental_Date; carRentals.RentalEnd = getRental.End_Rental_Date; carRentals.RentCost = (int)getRental.RentCost; carRentals.User = getRental.User.TZ; carRentals.ActualReturn = getRental.Actual_Date_Returned; carRentals.CarRented = getRental.Cars_for_Rent.License; return(carRentals); }