示例#1
0
 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."));
     }
 }
示例#2
0
        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());
        }
示例#3
0
        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"));
        }