public async Task <IActionResult> Create(BookingCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var booking = new Booking
                {
                    FirstName     = model.FirstName,
                    LastName      = model.LastName,
                    Mobile        = model.Mobile,
                    DateBooked    = model.DateBooked,
                    TimeBooked    = model.TimeBooked,
                    NumberinParty = model.NumberinParty,
                    Status        = model.Status,
                    Method        = model.Method,
                    TableNo       = model.TableNo,
                    DateCreated   = DateTime.Now,
                };

                await repository.AddAsync(booking);

                await unitOfWork.CompleteAsync();

                return(RedirectToAction("details", new { id = booking.Id }));
            }
            return(View());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Zeigt Benutzer eine Seite an, auf welcher er neue Buchungen erstellen kann.
        /// </summary>
        /// <param name="booking">Eine leere Buchung, oder sollte versucht werden eine Buchung erstellt zu werden, welche nicht den Richtlienen entspricht diese Buchung.</param>
        /// <returns>Eine Seite für das Erstellen der Buchungen.</returns>
        public IActionResult Create(Booking booking)
        {
            // Die Liste der Standorte wird aus dem Cache geladen.
            var cacheKey = CacheKeys.LOCATION;
            List <ILocation> locations = (List <ILocation>)cache.Get(cacheKey);

            if (locations == null)
            {
                locations = new List <ILocation>();
            }

            // Sollte die Buchung noch startzeiten mit 0 initialisiert haben wird die Startzeit und die endzeit auf die aktuelle Uhrzeit gestzt.
            if (booking.startTime == new DateTime() && booking.endTime == new DateTime())
            {
                DateTime now = DateTime.Now;
                now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute + 1, 0);
                booking.startTime = now;
                booking.endTime   = now;
            }

            // Erstellen des ViewModels für die Seite.
            BookingCreateViewModel viewmodel = new BookingCreateViewModel(locations, booking, booking.plugs.Contains(PlugType.CCS), booking.plugs.Contains(PlugType.TYPE2));

            return(View("Create", viewmodel));
        }
Exemplo n.º 3
0
        // GET: Booking
        public ActionResult Index()
        {
            BookingCreateViewModel viewModel = new BookingCreateViewModel();

            viewModel.CheckIn = DateTime.Now;

            viewModel.CheckOut = DateTime.Now.AddDays(1);

            viewModel.ListTypeRoom = _typeRoomSevice.GetBaseSelectListTypeRooms(_typeRoomSevice.GetList(true));

            return(View(viewModel));
        }
Exemplo n.º 4
0
        public void CreateTest_ShouldFailIfInvalidTimes()
        {
            BookingController      controller   = new BookingController();
            BookingCreateViewModel bookingToAdd = new BookingCreateViewModel()
            {
                Date = new DateTime(2018, 11, 29), End_DateTime = new DateTime(2018, 11, 29, 10, 0, 0), Start_DateTime = new DateTime(2018, 11, 29, 11, 0, 1)
            };

            var result = controller.CreateStep2(bookingToAdd) as ViewResult;

            Assert.IsTrue(!controller.ModelState.IsValid);
            Assert.IsTrue(controller.ViewData.ModelState.Count == 1,
                          "Please check start and end times. A meeting cannot end before it starts.");
        }
        public async Task <IActionResult> Create([Bind("Id,From,To,RoomSize,RoomType")] BookingCreateViewModel bookingView)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            if (ModelState.IsValid)
            {
                var availableRooms = BookingCheck.GetAvailableRooms(
                    _context,
                    bookingView.RoomSize,
                    bookingView.RoomType,
                    bookingView.From,
                    bookingView.To
                    ).ToList();

                if (!availableRooms.Any())
                {
                    ModelState.AddModelError("NoRoomsAvailable", "No rooms were available for that time period.");
                }
                else
                {
                    var room    = availableRooms.First();
                    var booking = new Booking
                    {
                        Id      = bookingView.Id,
                        From    = bookingView.From,
                        To      = bookingView.To,
                        RoomId  = room.Id,
                        Room    = room,
                        User    = user,
                        Payment = null,
                    };
                    _context.Add(booking);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(bookingView));
        }
Exemplo n.º 6
0
        public ActionResult Index(BookingCreateViewModel modelView)
        {
            if (ModelState.IsValid)
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    Booking bk = new Booking();

                    bk.NamePartner = modelView.NamePartner;
                    bk.Email       = modelView.Email;
                    bk.CheckIn     = modelView.CheckIn;
                    bk.CheckOut    = modelView.CheckOut;
                    bk.Adukts      = modelView.Adukts;
                    bk.Adolescent  = modelView.Adolescent;
                    bk.Children    = modelView.Children;
                    bk.Phone       = modelView.Phone;
                    bk.TypeRoom_Id = modelView.TypeRoom_Id;

                    try
                    {
                        _bookingSevice.Add(bk);

                        unitOfWork.Commit();

                        return(RedirectToAction("Ok"));
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LoggingService.Error(ex);

                        ViewBag.Message = new GenericMessageViewModel
                        {
                            Message     = LocalizationService.GetResourceString("Booking.Error"),
                            MessageType = GenericMessages.warning
                        };
                    }
                }
            }

            modelView.ListTypeRoom = _typeRoomSevice.GetBaseSelectListTypeRooms(_typeRoomSevice.GetList(true));
            return(View(modelView));
        }
        public IActionResult Create(BookingCreateViewModel model)
        {
            if (!TempData.ContainsKey(ApplicationConstants.TempDataHomeIdKey))
            {
                return(this.NotFound());
            }

            var homeId = int.Parse(this.TempData[ApplicationConstants.TempDataHomeIdKey].ToString());

            if (!this.homes.Exists(homeId))
            {
                return(this.NotFound());
            }

            this.TempData.Keep(ApplicationConstants.TempDataHomeOwnerNameKey);
            this.TempData.Keep(ApplicationConstants.TempDataHomeIdKey);

            if (model.CheckOutDate <= model.CheckInDate)
            {
                ModelState.AddModelError("CheckOutDate", "Check Out Date must be after Check In Date");
            }

            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            this.bookings.Create(
                this.userManager.GetUserId(this.User),
                homeId,
                model.CheckInDate.Value,
                model.CheckOutDate.Value);

            TempData[ApplicationConstants.TempDataSuccessMessageKey] =
                $"Booking request for {TempData[ApplicationConstants.TempDataHomeOwnerNameKey]}'s home sent!";

            return(RedirectToAction(nameof(this.Pending)));
        }
        public async Task Create_WhenCalled_CreateNewBookingAndRedirectToIndex()
        {
            // Arrange
            var model = new BookingCreateViewModel
            {
                FirstName     = "Joseph",
                LastName      = "A",
                Mobile        = "123456789",
                DateBooked    = new DateTime(2020, 12, 21),
                TimeBooked    = "13:30",
                NumberinParty = 3,
                Status        = 1,
                Method        = 2,
                TableNo       = 1,
            };

            // Act
            var result = await controller.Create(model) as RedirectToActionResult;

            // Assert
            Assert.That(result.RouteValues.Count, Is.EqualTo(1));
            Assert.That(result.ActionName, Is.EqualTo("details"));
        }
Exemplo n.º 9
0
 public ActionResult CreateStep2(BookingCreateViewModel vm)
 {
     if (vm == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     //check valid times
     if (vm.InvalidStartAndEnd())
     {
         ModelState.AddModelError("", "Please check start and end times. A meeting cannot end before it starts.");
     }
     else if (ModelState.IsValid)
     {
         //find available rooms!
         List <MeetingRoom> availableRooms = FindAvailableRooms(vm.Date, vm.Start_DateTime, vm.End_DateTime);
         if (availableRooms.Count == 0)
         {
             ModelState.AddModelError("", "Sorry, there is no available room at the specified date and time.");
         }
         else
         {
             Booking newBooking = new Booking
             {
                 Date           = vm.Date,
                 Start_DateTime = vm.Start_DateTime,
                 End_DateTime   = vm.End_DateTime,
             };
             ViewBag.Username       = User.Identity.GetUserName();
             ViewBag.AvailableRooms = availableRooms;
             ViewBag.RoomId         = new SelectList(availableRooms, "RoomId", "Name");
             return(View(newBooking));
         }
     }
     PopulateStartTimeDropDownList(vm.Start_DateTime);
     PopulateEndTimeDropDownList(vm.End_DateTime);
     return(View("Create", vm));
 }
Exemplo n.º 10
0
        /// <summary>
        /// Methode für das Bearbeiten bestehender Buchungen.
        /// Entfernt die Buchung aus dem Cache.
        /// </summary>
        /// <param name="bookingID"> ID der Buchung, welche bearbeitet werden soll.</param>
        /// <returns> Eine Seite für das Bearbeiten der Buchung.</returns>
        public IActionResult Edit(string bookingID)
        {
            // Die Buchungen werden aus dem Cache geladen.
            var cacheKey = CacheKeys.BOOKING;

            if (!cache.TryGetValue(cacheKey, out bookings))
            {
                bookings = new List <IBooking>();
            }

            // Herausfiltern der Buchung, welche die übergebene Id hat.
            Booking booking = bookings.Find(x => x.id.Equals(bookingID)) as Booking;


            // Die Liste der Standorte wird aus dem Cache geladen.
            List <ILocation> locations;

            if (!cache.TryGetValue(CacheKeys.LOCATION, out locations))
            {
                locations = new List <ILocation>();
            }

            // Anlegen des ViewModels für die Seite.
            BookingCreateViewModel viewmodel = new BookingCreateViewModel(locations, booking, false, false);

            if (booking.plugs.Contains(PlugType.CCS))
            {
                viewmodel.ccs = true;
            }
            if (booking.plugs.Contains(PlugType.TYPE2))
            {
                viewmodel.type2 = true;
            }

            return(View("Create", viewmodel));
        }
Exemplo n.º 11
0
        public IActionResult Post(string id, BookingCreateViewModel viewmodel)
        {
            IBooking booking = viewmodel.booking;

            booking.id = id;
            // Die Liste der Standorte wird aus dem Cache geladen.
            List <ILocation> locations = (List <ILocation>)cache.Get(CacheKeys.LOCATION);

            if (locations == null)
            {
                locations = new List <ILocation>();
            }

            // Sollte der Benutzer kein ASSISTANCE sein wird seine E-Mail als die E-Mail des Benutzers gestzt.

            if (booking.priority == UserType.EMPLOYEE && !this.HttpContext.Session.GetString("role").Equals(UserType.PLANER.ToString()))
            {
                booking.user = this.HttpContext.Session.GetString("email");
            }

            // Filtern des richtigen Standorts aus der Liste der Standorte.
            booking.location = locations.Find(x => x.id.Equals(viewmodel.locationId));

            // Befüllen der Liste an Stecker, welche zum Auto des Benutzers passen.
            List <PlugType> plugs = new List <PlugType>();

            if (viewmodel.ccs)
            {
                plugs.Add(PlugType.CCS);
            }
            if (viewmodel.type2)
            {
                plugs.Add(PlugType.TYPE2);
            }
            booking.plugs = plugs;

            bool test = ModelState.IsValid;

            // Validierung der Buchung, bei Fehlschlag wird an die Create Methode weitergeleited.
            if (!TryValidateModel(booking, nameof(booking)))
            {
                return(RedirectToAction("Create", "Booking", booking));
            }

            // Die Buchungen werden aus dem Cache geladen.
            var cacheKey = CacheKeys.BOOKING;

            if (!cache.TryGetValue(cacheKey, out bookings))
            {
                bookings = new List <IBooking>();
            }

            // Im Edit Fall wird die Buchung, welche editiert wurde entfernt.
            foreach (Booking b in bookings)
            {
                if (b.id.Equals(booking.id))
                {
                    if (!this.HttpContext.Session.GetString("role").Equals(UserType.ASSISTANCE.ToString()))
                    {
                        booking.priority = b.priority;
                        booking.user     = b.user;
                    }
                    bookings.Remove(b);

                    break;
                }
            }

            // Sollte der Benutzer eine Adhoc Buchung vornehmen und VIP sein, wird diese erstellt befüllt, verteilt, dem Cache hinzugefügt und es wird zur Index Methode weitergeleited.
            if (booking.startTime.Date == DateTime.Now.Date)
            {
                if (booking.priority != UserType.VIP)
                {
                    return(RedirectToAction("Create", "Booking", booking));
                }
                Adhoc adhoc = new Adhoc(false)
                {
                    capacity  = booking.capacity,
                    plugs     = booking.plugs,
                    socStart  = booking.socStart,
                    socEnd    = booking.socEnd,
                    user      = booking.user,
                    startTime = booking.startTime,
                    endTime   = booking.endTime,
                    active    = booking.active,
                    location  = booking.location,
                    priority  = booking.priority
                };
                bookings.Add(adhoc);
                cache.Set(cacheKey, bookings);
                adhoc.triggerBookingDistribution();
                return(RedirectToAction("Index", "Booking"));
            }

            // Hinzufügen der Buchung zum Cache.
            bookings.Add(booking);
            cache.Set(cacheKey, bookings);

            return(RedirectToAction("Index", "Booking"));
        }