/// <summary> /// This method shows the information of the selected ticket /// <example>tickets/Details/1</example> /// <example>tickets/Details/4</example> /// </summary> /// <param name="id">ID of the selected ticket</param> /// <returns>Details of the ticket which ID is given</returns> public ActionResult Details(int id) { ShowTicket showTicket = new ShowTicket(); //Get the current ticket from the database string url = "TicketData/FindTicket/" + id; HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { TicketDto SelectedTicket = response.Content.ReadAsAsync <TicketDto>().Result; showTicket.Ticket = SelectedTicket; //Get the user/owner of the selected ticket url = "TicketData/GetTicketUser/" + id; response = client.GetAsync(url).Result; ApplicationUserDto SelectedUser = response.Content.ReadAsAsync <ApplicationUserDto>().Result; showTicket.User = SelectedUser; //Get the parking spot of the selected ticket url = "TicketData/GetTicketSpot/" + id; response = client.GetAsync(url).Result; ParkingSpotDto SelectedSpot = response.Content.ReadAsAsync <ParkingSpotDto>().Result; showTicket.Spot = SelectedSpot; return(View(showTicket)); } else { return(RedirectToAction("Error")); } }
public ActionResult Details(int id) { //Model used to combine a Parking Spot object and its tickets ShowParkingSpot ViewModel = new ShowParkingSpot(); //Get the current ParkingSpot object string url = "ParkingSpotData/FindParkingSpot/" + id; HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { ParkingSpotDto SelectedSpots = response.Content.ReadAsAsync <ParkingSpotDto>().Result; ViewModel.Spot = SelectedSpots; } else { return(RedirectToAction("Error")); } //Get the tickets which are linked to the current Parking Spot object url = "ParkingSpotData/GetSpotTickets/" + id; response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { //Put data into ticket data transfer object IEnumerable <TicketDto> SelectedTickets = response.Content.ReadAsAsync <IEnumerable <TicketDto> >().Result; ViewModel.AllTickets = SelectedTickets; } else { return(RedirectToAction("Error")); } return(View(ViewModel)); }
public IHttpActionResult GetAllTickets() { //List of the tickets from the database List <Ticket> Tickets = db.Tickets.ToList(); //Data transfer object to show information about the ticket List <ShowTicket> TicketDtos = new List <ShowTicket> { }; foreach (var Ticket in Tickets) { ShowTicket ticket = new ShowTicket(); //Get the user to which the ticket belongs to ApplicationUser user = db.Users.Where(u => u.Tickets.Any(t => t.TicketId == Ticket.TicketId)).FirstOrDefault(); ApplicationUserDto parentUser = new ApplicationUserDto { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName }; //Get the parking spot of ticket ParkingSpot Spot = db.Spots.Where(s => s.Tickets.Any(t => t.TicketId == Ticket.TicketId)).FirstOrDefault(); ParkingSpotDto spot = new ParkingSpotDto { SpotId = Spot.SpotId, Zone = Spot.Zone, SpotNumber = Spot.SpotNumber, Status = Spot.Status }; TicketDto NewTicket = new TicketDto { TicketId = Ticket.TicketId, NumberPlate = Ticket.NumberPlate, EntryTime = Ticket.EntryTime, Duration = Ticket.Duration, Fees = 5 * Ticket.Duration, Id = Ticket.Id, SpotId = Ticket.SpotId }; ticket.Ticket = NewTicket; ticket.Spot = spot; ticket.User = parentUser; TicketDtos.Add(ticket); } return(Ok(TicketDtos)); }
public IHttpActionResult FindParkingSpot(int id) { ParkingSpot ParkingSpot = db.Spots.Find(id); if (ParkingSpot == null) { return(NotFound()); } //A data transfer object model used to show only most important information about the parking spot ParkingSpotDto TempSpot = new ParkingSpotDto { SpotId = ParkingSpot.SpotId, Zone = ParkingSpot.Zone, SpotNumber = ParkingSpot.SpotNumber, Status = ParkingSpot.Status }; return(Ok(TempSpot)); }
public IHttpActionResult GetTicketSpot(int id) { //Find the owner/user to which the current ticket belongs ParkingSpot Spot = db.Spots.Where(s => s.Tickets.Any(t => t.TicketId == id)).FirstOrDefault(); //In case this user does not exist if (Spot == null) { return(NotFound()); } ParkingSpotDto ParentSpot = new ParkingSpotDto { SpotId = Spot.SpotId, Zone = Spot.Zone, SpotNumber = Spot.SpotNumber, Status = Spot.Status }; return(Ok(ParentSpot)); }
public IHttpActionResult GetParkingSpots() { //Getting the list of parking spots objects from the databse List <ParkingSpot> ParkingSpots = db.Spots.ToList(); //Here a data transfer model is used to keep only the information to be displayed about a parking spot object List <ParkingSpotDto> ParkingSpotDtos = new List <ParkingSpotDto> { }; //Transfering parking spot to data transfer object foreach (var Spot in ParkingSpots) { ParkingSpotDto NewSpot = new ParkingSpotDto { SpotId = Spot.SpotId, Zone = Spot.Zone, SpotNumber = Spot.SpotNumber, Status = Spot.Status }; ParkingSpotDtos.Add(NewSpot); } return(Ok(ParkingSpotDtos)); }
public static bool IsAvailableDuring(this ParkingSpotDto spot, DateTime from, DateTime to) { return(!spot.Reservations.Any(r => DateTimeComparer.AreOverlapping(from, to, r.FromUtc, r.UntilUtc))); }