Example #1
0
        public async Task <ActionResult <IEnumerable <Apartment> > > GetAllApartments(decimal fromPrice, decimal toPrice, string address, int numberOfRooms)
        {
            var paginationFilter = new PaginationFilter();
            var validFilter      = new PaginationFilter(paginationFilter.PageNumber, paginationFilter.PageSize);
            IEnumerable <Apartment> apartments;

            if (fromPrice == 0 && toPrice == 0 && address == null && numberOfRooms == 0)
            {
                apartments = await _apartmentService.GetAllApartments();
            }
            else
            {
                apartments = await _apartmentService.GetAllApartments(fromPrice, toPrice, address, numberOfRooms);
            }
            var route        = Request.Path.Value;
            var totalRecords = await _apartmentService.GetAllApartmentsCount();

            var apartmentResources = _mapper.Map <IEnumerable <Apartment>, IEnumerable <ApartmentResource> >(apartments);
            var pagedResponse      = PaginationHelper.CreatePagedResponse <IEnumerable <ApartmentResource> >(apartmentResources, validFilter, totalRecords, _uriService, route);

            return(Ok(pagedResponse));
        }
        public ActionResult Index()
        {
            try
            {
                bookingService.CancelAllOverDueBills();
                var alerts = bookingService.GetUserUnpaidBills(User.Identity.GetUserId()).Count;
                ViewBag.Alerts = alerts;
                var bills      = bookingService.GetUserBills(User.Identity.GetUserId());
                var bookings   = bookingService.GetUserBookings(User.Identity.GetUserId());
                var apartments = apartmentService.GetAllApartments().ToList();
                List <BookingViewModel> userBookings = new List <BookingViewModel>();

                foreach (var b in bookings)
                {
                    var currentBill      = bills.Find(bill => bill.Id == b.BillId);
                    var currentApartment = apartments.Find(ap => ap.Id == b.ApartmentId);

                    userBookings.Add(new BookingViewModel
                    {
                        Id               = b.Id,
                        BookingDate      = b.BookingDate,
                        DateOfArrival    = b.DateOfArrival,
                        DaysOfArrival    = b.DaysOfArrival,
                        Price            = currentBill.Price,
                        NumberOfPlaces   = currentApartment.NumberOfPlaces,
                        ApartmentClassId = currentApartment.ApartmentClassId,
                        IsCanceled       = b.IsCanceled,
                        IsConfirmed      = b.IsConfirmed
                    });
                }

                return(View(userBookings));
            }
            catch (ValidationException ex)
            {
                // Залогировать эксепшн
            }

            return(View("Error"));
        }
Example #3
0
        public ActionResult Index()
        {
            var apartments = Mapper.Map <IEnumerable <ApartmentDTO>, IEnumerable <ApartmentViewModel> >(apartmentService.GetAllApartments());
            var bookings   = bookingService.GetBookings();

            foreach (var a in apartments)
            {
                if (apartmentService.IsApartmentHasBookingsInFuture(a.Id))
                {
                    a.Closeable = false;
                }
                else
                {
                    a.Closeable = true;
                }
            }

            return(View(apartments));
        }
Example #4
0
 public IActionResult GetApartments()
 {
     return(Ok(_apartmentService.GetAllApartments()));
 }