public IDataResult <CarDetailsDto> GetCarDetails(int id) { using (CarRentalContext context = new CarRentalContext()) { var result = from c in context.Cars join b in context.Brands on c.BrandId equals b.Id join co in context.Colors on c.ColorId equals co.Id where c.Id == id select new CarDetailsDto { Id = c.Id, BrandName = b.BrandName, ColorName = co.ColorName, CarName = c.CarName, ModelYear = c.ModelYear, DailyPrice = c.DailyPrice, Description = c.Description }; CarDetailsDto carDTO = result.FirstOrDefault(); if (carDTO == null) { return(new ErrorDataResult <CarDetailsDto>("İstenilen öge bulunamadığı için araba detayları listelenemedi.")); } return(new SuccessDataResult <CarDetailsDto>(carDTO, "İstenilen öge bulunamadığı için araba detayları listelenemedi.")); } }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } _logger.LogInformation(LoggingEvents.GetItem, "Get Car {ID}", id); Car = await _carService.GetCarDetailsDto(id); if (Car == null) { _logger.LogInformation(LoggingEvents.GetItemNotFound, "Get Car {ID} NOT FOUND", id); return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } _logger.LogInformation(LoggingEvents.GetItem, "Get Car {ID}", id); Car = await _carService.GetCarDetailsDto(id); if (Car != null) { if (!Car.HasReservation) { await _carService.DeleteCar(id); _logger.LogInformation(LoggingEvents.DeleteItem, "Admin Deleted Car {ID}", id); } } return(RedirectToPage("./Index")); }