Exemplo n.º 1
0
        public void CreateNewBooking()
        {
            //Arrange
            var newBooking = new NewBookingViewModel()
            {
                FlightNumber = "BB124",
                Person       = new PersonViewModel()
                {
                    Address   = "123 street",
                    DateBirth = new DateTime(1985, 5, 5),
                    Email     = "testyahoo.com",
                    Gender    = GenderType.Male,
                    Name      = "Adam lalana"
                }
            };

            bookingServiceMock.Setup(a => a.Create(It.IsAny <string>(), It.IsAny <Person>())).Returns(new Booking()
            {
                DateBooking = DateTime.Now,
                Id          = 5200,
                Number      = "BB124"
            });
            // Act
            IHttpActionResult actionResult = objController.Post(newBooking);
            var contentResult = actionResult as OkNegotiatedContentResult <BookingViewModel>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            bookingServiceMock.Verify(a => a.Create(It.IsAny <string>(), It.IsAny <Person>()), Times.Once);
        }
Exemplo n.º 2
0
        public IActionResult Reservation(NewBookingViewModel bookingModel)
        {
            var userId = Guid.Parse(Request.HttpContext.Session.GetString(SessionConstants.SessionActiceUserID));
            int hour   = (int)bookingModel.SelectTime / 60;
            int min    = (int)bookingModel.SelectTime - (hour * 60);

            var selectedDate = new DateTime(
                bookingModel.SelectedDate.Year,
                bookingModel.SelectedDate.Month, bookingModel.SelectedDate.Day, hour, min, 0);

            if (selectedDate < DateTime.Now)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var booking = new WashBooking
            {
                Booking   = selectedDate,
                UserID    = userId,
                CarWashID = bookingModel.SelectedCarWashID,
            };

            _carWashBookingService.AddBooking(booking);
            bookingModel.SelectedCarWash = _carWashBookingService.ReadCarWash(bookingModel.SelectedCarWashID).Result;
            bookingModel.SelectedDate    = selectedDate;
            SendEmail(bookingModel);
            return(RedirectToAction("Index", "Home"));
        }
        public async Task <IActionResult> PostAsync([FromBody] NewBookingViewModel newBooking)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState.SelectMany(x => x.Value.Errors)));
                }

                if (!_flights.IsFlightExist(newBooking.FlightNumber))
                {
                    return(BadRequest("Incorrect flight number"));
                }

                if (_bookings.IsFlightBooked(newBooking.FlightNumber, newBooking.PassengersName))
                {
                    return(BadRequest("This passanger has already booked on this flight"));
                }

                var createdBooking = await _bookings.BookFlightAsync(newBooking.PassengersName, newBooking.FlightNumber);

                var result = _mapper.Map <BookingViewModel>(createdBooking);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.LogError("Error during the booking the passanger", ex);
                throw;
            }
        }
Exemplo n.º 4
0
        // GET: Bookings/Create
        public ActionResult Create()
        {
            var viewModel = new NewBookingViewModel();

            viewModel.Customers = db.Customers.ToList();
            viewModel.Employees = db.Employees.ToList();
            return(View(viewModel));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Index()
        {
            DateTime selectDate   = DateTime.Now;
            int      selectedTime = selectDate.Hour * 60;
            int      min          = 0;

            if (selectDate.Minute < 20)
            {
                min = 20;
            }
            else if (selectDate.Minute < 40)
            {
                min = 40;
            }
            else
            {
                min = 60;
            }
            selectedTime += min;

            var userId = Request.HttpContext.Session.GetString(SessionConstants.SessionActiceUserID);

            // hent brugers sidste hal og vask.
            var washHalls = await _carWashBookingService.CarWashGetAll();

            if (washHalls.Count == 0)
            {
                return(View("NoWashHall"));
            }
            var latest = await _carWashBookingService.LatestCarWash(Guid.Parse(userId));

            // for meget logik her
            var washHall = (latest == null) ? washHalls[0]: latest;

            var reserved = await _carWashBookingService.Reserved(washHall.ID, selectDate);

            var availibleTimes = _carWashBookingService.AvailibleTimes(washHall.ID, selectDate);
            int selectDateNext = availibleTimes.Result.Keys.FirstOrDefault(w => selectedTime >= w);

            if (selectDateNext > 0)
            {
                selectedTime = selectDateNext;
            }

            var booking = new NewBookingViewModel
            {
                SelectedCarWash   = washHall,
                CarWashes         = washHalls,
                SelectedDate      = selectDate,
                SelectedCarWashID = washHall.ID,
                SelectTime        = selectedTime,
                AvailibleTimes    = availibleTimes.Result,
                UserName          = User.Identity.Name
            };

            return(View("Index", booking));
        }
Exemplo n.º 6
0
        public async Task <ActionResult> Edit(NewBookingViewModel booking)
        {
            if (ModelState.IsValid)
            {
                db.Entry(booking.Bookings).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(booking));
        }
Exemplo n.º 7
0
        //  https://www.c-sharpcorner.com/blogs/drop-down-list-selected-index-changed-event-in-mvc

        public async Task <PartialViewResult> ReadCarWash(int selectedID)
        {
            var carWash = await _carWashBookingService.ReadCarWash(selectedID);

            var booking = new NewBookingViewModel()
            {
                SelectedCarWash = carWash
            };

            return(PartialView("_CarWashPartial", booking));
        }
Exemplo n.º 8
0
        public async Task <ActionResult> Create(NewBookingViewModel booking)
        {
            if (ModelState.IsValid)
            {
                //formatando data para uo formato do banco de dados.
                //booking.Bookings.DtAgendamento = booking.Bookings.DtAgendamento.ToUniversalTime();
                booking.Bookings.DtRegistro = DateTime.Now;
                db.Bookings.Add(booking.Bookings);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(booking));
        }
Exemplo n.º 9
0
        public async Task PostAsyncWithValidationErrorsReturnsBadRequest()
        {
            // Arrange
            var newBooking = new NewBookingViewModel()
            {
                PassengersName = "PersonName"
            };

            _controller.ModelState.AddModelError("FlightNumber", "The FlightNumber field is required.");

            // Act
            var result = await _controller.PostAsync(newBooking);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
Exemplo n.º 10
0
        // GET: Bookings/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Booking booking = await db.Bookings.FindAsync(id);

            if (booking == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new NewBookingViewModel();

            viewModel.Customers = db.Customers.ToList();
            viewModel.Employees = db.Employees.ToList();
            viewModel.Bookings  = booking;
            return(View(viewModel));
        }
Exemplo n.º 11
0
        public async Task PostAsyncReturnsBadRequest()
        {
            // Arrange
            var newBooking = new NewBookingViewModel()
            {
                FlightNumber   = "TS123",
                PassengersName = "PersonName"
            };

            _mockFlightService.Setup(x => x.IsFlightExist(It.IsAny <string>())).Returns(true);
            _mockBookingService.Setup(x => x.IsFlightBooked(It.IsAny <string>(), It.IsAny <string>())).Returns(true);

            // Act
            var result = await _controller.PostAsync(newBooking);

            // Assert
            var objectResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.Equal("This passanger has already booked on this flight", objectResult.Value);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Posts the specified booking.
        /// </summary>
        /// <param name="booking">The booking.</param>
        /// <returns></returns>
        /// <exception cref="IdOrNumberNotValidException"></exception>
        public IHttpActionResult Post([FromBody] NewBookingViewModel booking)
        {
            try
            {
                //create new Booking
                var bookingObj = _bookingService.Create(booking.FlightNumber, Mapper.Map <Person>(booking.Person));

                var result = Mapper.Map <BookingViewModel>(bookingObj);

                return(Ok(result));
            }
            catch (FligtNotExistException)
            {
                // throw new IdNotValidException();
                throw new IdOrNumberNotValidException();
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 13
0
        public async Task PostAsyncReturnsNewBooking()
        {
            // Arrange
            var newBooking = new NewBookingViewModel()
            {
                FlightNumber   = "TS123",
                PassengersName = "Person Name"
            };
            var booking = new Booking
            {
                Id     = 1,
                Number = "WO-123456",
                Flight = new Flight
                {
                    Number = "TS123"
                },
                Customer = new Person
                {
                    Name = "Person Name"
                }
            };

            _mockFlightService.Setup(x => x.IsFlightExist(newBooking.FlightNumber)).Returns(true);
            _mockBookingService.Setup(x => x.IsFlightBooked(newBooking.FlightNumber, newBooking.PassengersName)).Returns(false);
            _mockBookingService.Setup(x => x.BookFlightAsync(newBooking.PassengersName, newBooking.FlightNumber)).Returns(Task.FromResult(booking));

            // Act
            var result = await _controller.PostAsync(newBooking);

            // Assert
            var objectResult = Assert.IsType <OkObjectResult>(result);

            var viewModel = Assert.IsType <BookingViewModel>(objectResult.Value);

            Assert.Equal(newBooking.FlightNumber, viewModel.FlightNumber);
            Assert.Equal(newBooking.PassengersName, viewModel.Customer.Name);
        }
Exemplo n.º 14
0
        private void SendEmail(NewBookingViewModel booking)
        {
            string message = $"Hej \nHusk din bilvask {booking.DisplayDate }  {booking.DisplayTime} på adresse {booking.SelectedCarWash.Adresse }";

            _emailService.SendEmail("*****@*****.**", User.Identity.Name, "Booking af bilvask", message).Wait();
        }
Exemplo n.º 15
0
        //Getting the NewBookings Data
        public BookingNewViewModel  GetNewBookings(string id)
        {
            List <NewBookingViewModel> lst = new List <NewBookingViewModel>();
            List <ProjectDetails>      lstProjectDetails         = new List <ProjectDetails>();
            List <ProjectDetails>      lstRejProjectDetails      = new List <ProjectDetails>();
            List <ProjectDetails>      lstbookedProjectDetails   = new List <ProjectDetails>();
            List <ProjectDetails>      lstSelfProjectDetails     = new List <ProjectDetails>();
            List <ProjectDetails>      lstadbookedProjectDetails = new List <ProjectDetails>();
            List <ProjectDetails>      lstRejectesProjectDetails = new List <ProjectDetails>();
            var admins = _context.AdminDetails.Where(x => x.AdminUUID == id).FirstOrDefault();
            BookingNewViewModel ObjModel = new BookingNewViewModel();

            if (admins != null)
            {
                if (!string.IsNullOrEmpty(admins.BlockedUnits))
                {
                    lstSelfProjectDetails = JsonSerializer.Deserialize <List <ProjectDetails> >(admins.BlockedUnits);
                    foreach (var projectData in lstSelfProjectDetails)
                    {
                        foreach (var unit in projectData.UnitsData)
                        {
                            NewBookingViewModel agentDetails = new NewBookingViewModel();
                            agentDetails.AdminId            = admins.AdminUUID;
                            agentDetails.AgentName          = "SarkProject";
                            agentDetails.UnitSize           = unit.UnitSize;
                            agentDetails.CreatedDate        = unit.CreatedDate;
                            agentDetails.UnitNumber         = unit.UnitNumber;
                            agentDetails.Facing             = unit.Facing;
                            agentDetails.ProjectId          = projectData.ProjectId;
                            agentDetails.ProjectName        = projectData.ProjectName;
                            agentDetails.Status             = unit.Status;
                            agentDetails.StatusConfiredDate = unit.StatusConfiredDate;
                            agentDetails.customerName       = unit.customerName;
                            agentDetails.AgentId            = unit.AgentId;
                            agentDetails.customerName       = unit.customerName;
                            lst.Add(agentDetails);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(admins.RejectedUnits))
                {
                    lstRejectesProjectDetails = JsonSerializer.Deserialize <List <ProjectDetails> >(admins.RejectedUnits);
                    foreach (var projectData in lstRejectesProjectDetails)
                    {
                        foreach (var unit in projectData.UnitsData)
                        {
                            NewBookingViewModel agentDetails = new NewBookingViewModel();
                            agentDetails.AgentId      = admins.AdminUUID;
                            agentDetails.AgentName    = "SarkProject";
                            agentDetails.UnitSize     = unit.UnitSize;
                            agentDetails.CreatedDate  = unit.CreatedDate;
                            agentDetails.UnitNumber   = unit.UnitNumber;
                            agentDetails.Facing       = unit.Facing;
                            agentDetails.ProjectId    = projectData.ProjectId;
                            agentDetails.ProjectName  = projectData.ProjectName;
                            agentDetails.Status       = unit.Status;
                            agentDetails.customerName = unit.customerName;
                            lst.Add(agentDetails);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(admins.BookingConfirmed))
                {
                    lstadbookedProjectDetails = JsonSerializer.Deserialize <List <ProjectDetails> >(admins.BookingConfirmed);
                    foreach (var projectData in lstadbookedProjectDetails)
                    {
                        foreach (var unit in projectData.UnitsData)
                        {
                            NewBookingViewModel agentDetails = new NewBookingViewModel();
                            agentDetails.AgentId            = admins.AdminUUID;
                            agentDetails.AgentName          = "SarkProject";
                            agentDetails.UnitSize           = unit.UnitSize;
                            agentDetails.CreatedDate        = unit.CreatedDate;
                            agentDetails.UnitNumber         = unit.UnitNumber;
                            agentDetails.Facing             = unit.Facing;
                            agentDetails.ProjectId          = projectData.ProjectId;
                            agentDetails.ProjectName        = projectData.ProjectName;
                            agentDetails.StatusConfiredDate = unit.StatusConfiredDate;
                            agentDetails.customerName       = unit.customerName;
                            agentDetails.Status             = unit.Status;
                            lst.Add(agentDetails);
                        }
                    }
                }
            }
            var agents = _context.AgentRegistration.ToList();

            foreach (var agent in agents)
            {
                if (!string.IsNullOrEmpty(agent.BlockedUnits))
                {
                    lstProjectDetails = JsonSerializer.Deserialize <List <ProjectDetails> >(agent.BlockedUnits);
                    foreach (var projectData in lstProjectDetails)
                    {
                        foreach (var unit in projectData.UnitsData)
                        {
                            NewBookingViewModel agentDetails = new NewBookingViewModel();
                            agentDetails.AgentId            = agent.AgentId;
                            agentDetails.AgentName          = agent.AgetName;
                            agentDetails.UnitSize           = unit.UnitSize;
                            agentDetails.CreatedDate        = unit.CreatedDate;
                            agentDetails.UnitNumber         = unit.UnitNumber;
                            agentDetails.Facing             = unit.Facing;
                            agentDetails.ProjectId          = projectData.ProjectId;
                            agentDetails.ProjectName        = projectData.ProjectName;
                            agentDetails.StatusConfiredDate = unit.StatusConfiredDate;
                            agentDetails.customerName       = unit.customerName;
                            agentDetails.Status             = unit.Status;
                            lst.Add(agentDetails);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(agent.RejectedUnits))
                {
                    lstRejProjectDetails = JsonSerializer.Deserialize <List <ProjectDetails> >(agent.RejectedUnits);
                    foreach (var projectData in lstRejProjectDetails)
                    {
                        foreach (var unit in projectData.UnitsData)
                        {
                            NewBookingViewModel agentDetails = new NewBookingViewModel();
                            agentDetails.AgentId            = agent.AgentId;
                            agentDetails.AgentName          = agent.AgetName;
                            agentDetails.UnitSize           = unit.UnitSize;
                            agentDetails.CreatedDate        = unit.CreatedDate;
                            agentDetails.UnitNumber         = unit.UnitNumber;
                            agentDetails.Facing             = unit.Facing;
                            agentDetails.ProjectId          = projectData.ProjectId;
                            agentDetails.ProjectName        = projectData.ProjectName;
                            agentDetails.StatusConfiredDate = unit.StatusConfiredDate;
                            agentDetails.Status             = unit.Status;
                            agentDetails.customerName       = unit.customerName;
                            lst.Add(agentDetails);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(agent.BookingConfirmed))
                {
                    lstbookedProjectDetails = JsonSerializer.Deserialize <List <ProjectDetails> >(agent.BookingConfirmed);
                    foreach (var projectData in lstbookedProjectDetails)
                    {
                        foreach (var unit in projectData.UnitsData)
                        {
                            NewBookingViewModel agentDetails = new NewBookingViewModel();
                            agentDetails.AgentId            = agent.AgentId;
                            agentDetails.AgentName          = agent.AgetName;
                            agentDetails.UnitSize           = unit.UnitSize;
                            agentDetails.CreatedDate        = unit.CreatedDate;
                            agentDetails.UnitNumber         = unit.UnitNumber;
                            agentDetails.Facing             = unit.Facing;
                            agentDetails.ProjectId          = projectData.ProjectId;
                            agentDetails.ProjectName        = projectData.ProjectName;
                            agentDetails.StatusConfiredDate = unit.StatusConfiredDate;
                            agentDetails.customerName       = unit.customerName;
                            agentDetails.Status             = unit.Status;
                            lst.Add(agentDetails);
                        }
                    }
                }
            }
            ObjModel.lstBookings = lst;
            return(ObjModel);
        }
Exemplo n.º 16
0
 public NewBookingView(NewBookingViewModel viewmodel)
 {
     DataContext = viewmodel;
     InitializeComponent();
 }