Пример #1
0
 public async Task <IActionResult> Get()
 {
     try
     {
         var model = new GetFormResponseModel <UserListViewModel>
         {
             Model = new UserListViewModel
             {
                 Users = await _unitOfWork.UserRepository.Query
                         .Select(x => new UserViewModel
                 {
                     Id                   = x.Id,
                     Surname              = x.Surname,
                     Name                 = x.Name,
                     BirthDate            = x.BirthDate,
                     DrivingLicenseNumber = x.DrivingLicenseNumber
                 })
                         .ToArrayAsync()
             }
         };
         return(model.CreateSucceededResult());
     }
     catch (Exception e)
     {
         _logger.LogError(e, "api/Users GET technical error");
         return(new GetFormResponseModel <UserListViewModel>().CreateFailedResult("Sorry there was a technical error. Try to retry the request or contact technical support."));
     }
 }
Пример #2
0
        public async Task <IActionResult> Get(int id)
        {
            try
            {
                var isNewOrder = id == 0;

                OrderViewModel orderViewModel;
                if (isNewOrder)
                {
                    orderViewModel = new OrderViewModel();
                }
                else
                {
                    orderViewModel = await _unitOfWork.OrderRepository.Query
                                     .Select(x => new OrderViewModel
                    {
                        Id              = x.Id,
                        UserId          = x.UserId,
                        CarId           = x.CarId,
                        RentalStartDate = x.RentalStartDate,
                        RentalEndDate   = x.RentalEndDate,
                        Comment         = x.Comment
                    })
                                     .SingleOrDefaultAsync(x => x.Id == id);

                    if (orderViewModel == null)
                    {
                        return(new GetFormResponseModel <OrderViewModel, OrderViewBag>().CreateFailedResult($"Order {id} not found"));
                    }
                }

                var usersBag = await _unitOfWork.UserRepository.Query
                               .Select(x => new SelectItemViewModel {
                    Value = x.Id.ToString(), Text = x.ToString()
                })
                               .ToArrayAsync();

                var carsBag = await _unitOfWork.CarRepository.Query
                              .Select(x => new SelectItemViewModel {
                    Value = x.Id.ToString(), Text = x.ToString()
                })
                              .ToArrayAsync();

                var model = new GetFormResponseModel <OrderViewModel, OrderViewBag>
                {
                    Model = orderViewModel,
                    Bag   = new OrderViewBag
                    {
                        Users = usersBag,
                        Cars  = carsBag
                    }
                };
                return(model.CreateSucceededResult());
            }
            catch (Exception e)
            {
                _logger.LogError(e, "api/Orders/{id} GET technical error");
                return(new GetFormResponseModel <OrderViewModel, OrderViewBag>().CreateFailedResult("Sorry there was a technical error. Try to retry the request or contact technical support."));
            }
        }
Пример #3
0
 public async Task <IActionResult> Get()
 {
     try
     {
         var model = new GetFormResponseModel <CarListViewModel>
         {
             Model = new CarListViewModel
             {
                 Cars = await _unitOfWork.CarRepository.Query
                        .Select(x => new CarViewModel
                 {
                     Id                 = x.Id,
                     Brand              = x.Brand,
                     Model              = x.Model,
                     Class              = x.Class,
                     IssueYear          = (ushort)x.IssueYear,
                     RegistrationNumber = x.RegistrationNumber,
                 })
                        .ToArrayAsync()
             }
         };
         return(model.CreateSucceededResult());
     }
     catch (Exception e)
     {
         _logger.LogError(e, "api/Cars GET technical error");
         return(new GetFormResponseModel <CarListViewModel>().CreateFailedResult("Sorry there was a technical error. Try to retry the request or contact technical support."));
     }
 }
Пример #4
0
 public async Task <IActionResult> Get()
 {
     try
     {
         var model = new GetFormResponseModel <OrderListViewModel>
         {
             Model = new OrderListViewModel
             {
                 Orders = await _unitOfWork.OrderRepository.Query
                          .Include(x => x.User)
                          .Include(x => x.Car)
                          .Select(x => new OrderViewModel
                 {
                     Id              = x.Id,
                     UserId          = x.UserId,
                     UserName        = x.User.ToString(),
                     CarId           = x.CarId,
                     CarName         = x.Car.ToString(),
                     RentalStartDate = x.RentalStartDate,
                     RentalEndDate   = x.RentalEndDate,
                     Comment         = x.Comment
                 })
                          .ToArrayAsync()
             }
         };
         return(model.CreateSucceededResult());
     }
     catch (Exception e)
     {
         _logger.LogError(e, "api/Orders GET technical error");
         return(new GetFormResponseModel <OrderListViewModel>().CreateFailedResult("Sorry there was a technical error. Try to retry the request or contact technical support."));
     }
 }