/// <summary> /// Deletes the car from the database. /// </summary> /// <param name="carId">The car which is wanted to delete from database.</param> /// <returns>Boolean value whether the transaction is happened or not.</returns> public static bool DeleteCar(string carId) { bool result = CarPersistence.DeleteCar(carId); result = CommentPersistence.DeleteCommentFromCarID(carId); return(result); }
/// <summary> /// Returns all the cars in the database. /// </summary> /// <returns>All cars that are in the database.</returns> public static Car[] GetAllCars() { List <Car> cars = CarPersistence.GetAllCars(); if (cars != null) { return(CarPersistence.GetAllCars().ToArray()); } else { return(new Car[0]); } }
public ActionResult DeleteCar(string carId) { bool result = CarManager.DeleteCar(carId); if (result) { ViewBag.message = "Car successfully deleted."; } else { ViewBag.message = "Car could not be deleted."; } return(View(CarPersistence.GetUserCar(Session["UserId"].ToString()))); }
/// <summary> /// Gathers the two cars from the database and and returns the view where you can see these two cars. /// </summary> /// <param name="Car1">First car.</param> /// <param name="Car2">Second car.</param> /// <returns></returns> public ActionResult Compare(string Car1, string Car2) { int index1 = Car1.IndexOf(':'); // We are doing this because the string has the form: "carId: Brand Model" and we want only the carId. int index2 = Car2.IndexOf(':'); string car1Id, car2Id; car1Id = Car1.Substring(0, index1); car2Id = Car2.Substring(0, index2); Car car1 = CarPersistence.getCar(Int32.Parse(car1Id)); Car car2 = CarPersistence.getCar(Int32.Parse(car2Id)); Car[] cars = { car1, car2 }; return(View(cars)); }
/// <summary> /// Adds the desired car into the favourites list. /// </summary> /// <param name="carId">Car that wanted to add to favourites.</param> /// <param name="userId">User that we will add user's car into favourites table.</param> /// <returns>Boolean value whether the transaction is happened or not.</returns> internal static bool AddToFavourites(string carId, string userId) { bool result = CarPersistence.CheckFavCar(carId, userId); // Check if the car is already in the favourites list. if (result) { int res = CarPersistence.AddToFavourites(carId, userId); if (res == 1) { return(true); } else { return(false); } } else { return(false); } }
/// <summary> /// Calculates the statistics and puts them into the array. /// </summary> /// <returns>An integer of length 5 which contains the count of count of the number of users (total, active, and inactive), records, ///and comments, in this order. ///</returns> public static int[] GetStatistics() { int[] stats = new int[5]; for (int i = 0; i < 5; i++) { stats[i] = 0; } User[] users = UserPersistence.GetAllUsers(); List <Car> cars = CarPersistence.GetAllCars(); for (int i = 0; i < users.Length; i++) // Counts for the users that are active, inactive and total. { if (users[i].status == "A") { stats[1]++; } else { stats[2]++; } stats[0]++; } for (int i = 0; i < cars.Count; i++) // Counts the cars in the database. { stats[3]++; } List <Comment> comments = CommentPersistence.GetAllComments(); for (int i = 0; i < comments.Count; i++) // Counts the comments in the system. { stats[4]++; } return(stats); }
public ActionResult DeleteCar() { return(View(CarPersistence.GetUserCar(Session["UserId"].ToString()))); }
/// <summary> /// Updates the desired car value with the new one. /// </summary> /// <param name="value">New value which is wanted to change.</param> /// <param name="carId">Car that is wanted to update.</param> /// <param name="option">The value (Ranged from 1 to 11) to determine which field will be changed.</param> /// <returns>Boolean value whether the transaction is happened or not.</returns> public static bool ChangeCar(string value, string carId, int option) { bool result = CarPersistence.UpdateCar(value, option, carId); return(result); }
/// <summary> /// Adds the car into the database. /// </summary> /// <param name="newCar">Car that wanted to be added.</param> /// <returns>Boolean value whether the transaction is happened or not.</returns> public static bool AddNewCar(Car newCar) { return(CarPersistence.AddCar(newCar)); }
/// <summary> /// Returns the user's cars. /// </summary> /// <param name="UserId">ID that we will use to find it in the database.</param> /// <returns>All cars that belongs to the user.</returns> public static Car[] GetUserCars(string UserId) { Car[] cars = CarPersistence.GetUserCar(UserId); return(cars); }
/// <summary> /// Returns the cars that are in the favourite list on the user. /// </summary> /// <param name="userId">User that we will look for his/her favourite cars.</param> /// <returns>Cars that are added to favourite by the user.</returns> public static Car[] GetFavouriteCars(string userId) { Car[] cars = CarPersistence.GetFavCars(userId); return(cars); }
/// <summary> /// Return the car that is desired. /// </summary> /// <param name="carId">The car ID which we will return the car.</param> /// <returns>Car that is desired by user.</returns> public static Car GetCar(int carId) { Car car = CarPersistence.GetCar(carId); return(car); }
/// <summary> /// Makes a search in the car database with the keyword that is entered by the user. /// </summary> /// <param name="value">Value that user entered to search.</param> /// <param name="userId">User that makes the search.</param> /// <param name="option">The value (Ranged from 1 to 10) to determine which field will be searched.</param> /// <returns>Cars that matches to the query.</returns> public static Car[] SearchCar(string value, string userId, int option) { Car[] cars = CarPersistence.SearchCar(value, userId, option); return(cars); }