Beispiel #1
0
        public BookingEventModel(BookingEvent e)
        {
            Id               = e.Id;
            Name             = e.Name;
            Description      = e.Description;
            Schedules        = new List <ScheduleEventModel>();
            DeletedSchedules = new List <long>();

            EditMode     = false;
            EditAccess   = false;
            DeleteAccess = false;

            using (BookingEventManager em = new BookingEventManager())
            {
                //Get event again as not everything needed already fetched
                var event_ = em.GetBookingEventById(e.Id);


                foreach (Schedule s in event_.Schedules)
                {
                    ScheduleEventModel seM = new ScheduleEventModel(s);
                    seM.Index      = s.Index;
                    seM.EditMode   = false;
                    seM.EventId    = e.Id;
                    seM.Activities = new List <ActivityEventModel>();
                    s.Activities.ToList().ForEach(r => seM.Activities.Add(new ActivityEventModel(r)));
                    Schedules.Add(seM);
                }
            }
        }
Beispiel #2
0
        public void AddBooking(string roomId, string guestEmail, string fromDateStr, string toDateStr, int expectedStatusCode)
        {
            var ev = new BookingEvent
            {
                Resource = roomId,
                Text     = guestEmail,
                Start    = fromDateStr,
                End      = toDateStr,
            };

            _mockService.Setup(s => s.GetGuestByEmail(guestEmail)).Returns(
                Task.FromResult(new Guest {
                Id = 1, Email = guestEmail
            }));
            _mockService.Setup(s => s.AddBooking(It.IsAny <Booking>())).Returns(
                Task.FromResult(new Booking {
                Guest = new Guest {
                    Email = guestEmail
                }
            }));

            var response = _controller.AddBooking(ev).GetAwaiter().GetResult();

            // Assert
            var result = response.Result as ObjectResult;

            Assert.That(result.StatusCode == expectedStatusCode);
            var resultValue = result.Value as ServiceResponse <Booking>;

            Assert.That(resultValue.Data.RoomId.ToString(), Is.EqualTo(roomId));
        }
        public BookingEvent GetBookingEventById(long id)
        {
            BookingEvent e = EventRepo.Query(a => a.Id == id).FirstOrDefault();

            EventRepo.LoadIfNot(e.Schedules);

            return(e);
        }
Beispiel #4
0
        public async Task EnqueBookingEvent(BookingEvent bookingEvent)
        {
            var    queueClient = new QueueClient(_serviceBusConnectionString, QueueName);
            string messageBody = JsonConvert.SerializeObject(bookingEvent);
            var    message     = new Message(Encoding.UTF8.GetBytes(messageBody));

            Console.WriteLine($"Sending message");

            await queueClient.SendAsync(message);
        }
        public void Book(User user, BookingEvent bookingEvent)
        {
            var booking = new Booking
            {
                User         = user,
                BookingEvent = bookingEvent,
                BookingDate  = DateTime.UtcNow
            };

            _repository.Add(booking);
        }
        public async Task <MessageResult> Handle(CreateBooking message)
        {
            await semaphoreSlim.WaitAsync();

            try
            {
                // TODO validations etc.
                var startAt   = DateTime.Parse(message.StartAt);
                var serviceId = int.Parse(message.ServiceId);

                if (await unitOfWork.Exists <Booking>(b => b.StartAt == startAt && b.ServiceId == serviceId))
                {
                    throw new Domain.BookingAlreadyExists();
                }

                var createdUtc = DateTime.UtcNow;
                var booking    = new Booking
                {
                    Email            = message.Email,
                    Name             = message.Name,
                    Surname          = message.Surname,
                    Phone            = message.Phone,
                    BookingAt        = DateTime.Parse(message.BookingAt),
                    StartAt          = startAt,
                    ServiceId        = serviceId,
                    Quantity         = int.Parse(message.Quantity),
                    Price            = decimal.Parse(message.Price),
                    Comment          = message.Comment,
                    BookingCreatedAt = createdUtc,
                    Status           = (int)Domain.BookingStatus.Created
                };
                await unitOfWork.Add(booking);

                await unitOfWork.Save();

                var bookingCreated = new Domain.BookingCreated
                {
                    CreatedAt = createdUtc,
                    BookingId = booking.Id,
                };

                await unitOfWork.Add(BookingEvent.CreateFrom(bookingCreated));

                await unitOfWork.Save();

                return(new MessageResult(201, new { booking.Id }));
            }
            finally
            {
                semaphoreSlim.Release();
            }
        }
Beispiel #7
0
        public CalendarItemsModel(BookingEvent e)
        {
            using (var schManager = new ScheduleManager())
            {
                List <Schedule> schedules = schManager.GetAllSchedulesByEvent(e.Id);

                eventId = e.Id;
                title   = e.Name + " (" + e.Schedules.First().ByPerson.Person.DisplayName + ")";
                start   = (from d in schedules select d.StartDate).Min();
                end     = (from d in schedules select d.EndDate).Max();
                color   = "#3868c8"; // fix color, maybe later a other solution for the event color
            }
        }
Beispiel #8
0
        public ShowEventModel(BookingEvent eEvent)
        {
            //ScheduleManager schManager = new ScheduleManager();
            //List<Schedule> schedules = schManager.GetAllSchedulesByEvent(eEvent.Id);

            Schedules = new List <ScheduleEventModel>();

            foreach (Schedule s in eEvent.Schedules)
            {
                ScheduleEventModel rEventM = new ScheduleEventModel(s);
                Schedules.Add(rEventM);
            }

            //Activities = new List<ActivityModel>();
            //eEvent.Activities.ToList().ForEach(r => Activities.Add(new ActivityModel(r)));
        }
        public void CheckBookingEventExist_ExistedEventInfo_MatchedEvent()
        {
            // Setup dependency
            var settingsMock = new Mock<ISettings>();
            var uowMock = new Mock<IUnitOfWork>();
            var repositoryMock = new Mock<IRepository>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            Guid sourceUserId = Guid.NewGuid();
            Guid targetUserId = Guid.NewGuid();
            UserDto sourceUser = new UserDto { Id = sourceUserId };
            UserDto targetUser = new UserDto { Id = targetUserId };
            string shortDescription = "Test description";

            BookingEvent bookingEvent = new BookingEvent
            {
                Id = Guid.NewGuid(),
                SourceUser = new User
                {
                    Id = sourceUserId
                },
                TargetUser = new User
                {
                    Id = targetUserId
                },
                ShortDescription = shortDescription
            };

            BookingEvent[] bookingEvents = new BookingEvent[] { bookingEvent };
            repositoryMock.Setup(r => r.Query<BookingEvent>()).Returns(bookingEvents.AsQueryable());
            BookingEventDto actualBookingEventDto;

            // Act
            var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object);
            actualBookingEventDto = bookingService.CheckBookingEventExist(
                sourceUser, targetUser, shortDescription);

            // Assert
            Assert.AreEqual(bookingEvent.Id, actualBookingEventDto.Id);
        }
        public E.BookingEvent CreateBookingEvent(string name, string description, List <Activity> activities, DateTime minDate, DateTime maxDate)
        {
            BookingEvent newEvent = new BookingEvent()
            {
                Name        = name,
                Description = description,
                //Activities = activities,
                MinDate = minDate,
                MaxDate = maxDate
            };

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <E.BookingEvent> repo = uow.GetRepository <E.BookingEvent>();
                repo.Put(newEvent);
                uow.Commit();
            }

            return(newEvent);
        }
        public Schedule CreateSchedule(DateTime startDate, DateTime endDate, BookingEvent thisEvent, R.SingleResource resource, Person forPerson, Person byPerson, IEnumerable <long> activities, int quantity, int index)
        {
            Schedule schedule = new Schedule();

            schedule.Activities   = new List <Activity>();
            schedule.StartDate    = startDate.Date;
            schedule.EndDate      = endDate.Date;
            schedule.BookingEvent = thisEvent;
            schedule.Resource     = resource;
            //schedule.Activities = activities;
            schedule.Index    = index;
            schedule.Quantity = quantity;

            if (forPerson is PersonGroup)
            {
                PersonGroup pGroup = (PersonGroup)forPerson;
                schedule.ForPerson = pGroup;
            }
            else
            {
                IndividualPerson iPerson = (IndividualPerson)forPerson;
                schedule.ForPerson = iPerson;
            }

            IndividualPerson iPersonBy = (IndividualPerson)byPerson;

            schedule.ByPerson = iPersonBy;

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                //load activites

                activities.ToList().ForEach(a => schedule.Activities.Add(uow.GetReadOnlyRepository <Activity>().Get(a)));

                IRepository <Schedule> repo = uow.GetRepository <Schedule>();
                repo.Put(schedule);
                uow.Commit();
            }

            return(schedule);
        }
Beispiel #12
0
        public async Task <ActionResult <ServiceResponse <Booking> > > AddBooking([FromBody] BookingEvent toAddEvent)
        {
            var response = new ServiceResponse <Booking>();

            Int32.TryParse(toAddEvent.Resource, out int roomId);
            DateTime.TryParse(toAddEvent.Start, out DateTime fromDate);
            DateTime.TryParse(toAddEvent.End, out DateTime toDate);
            var guest = (await _service.GetGuestByEmail(toAddEvent.Text));

            if (guest == null)
            {
                try
                {
                    guest = await _service.AddGuest(toAddEvent.Text, "");
                }
                catch (System.Exception e)
                {
                    return(StatusCode(500, e.Message));
                }
            }

            try
            {
                var booking = new Booking
                {
                    RoomId   = roomId,
                    GuestId  = guest.Id,
                    FromDate = fromDate,
                    ToDate   = toDate
                };
                var dbBooking = await _service.AddBooking(booking);

                response.Data = booking;
                return(CreatedAtAction(nameof(GetBookingById), new { id = booking.Id }, response));
            }
            catch (Exception e)
            {
                response.Message = e.Message;
                return(BadRequest(response));
            }
        }
        public void GetByBookingAndShortDescription_UsingBookingIdAndShortDescription()
        {
            var settingsMock = new Mock<ISettings>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(r => r.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);

            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange data
            string description = "Test description";
            Guid id = Guid.NewGuid();
            BookingDto bookingDto = new BookingDto
            {
                Id = id
            };
            Booking booking = new Booking
            {
                Id = id
            };

            BookingEvent bookingEvent = new BookingEvent
            {
                Id = id,
                Booking = booking,
                ShortDescription = description
            };

            List<BookingDto> listBookingDto = new List<BookingDto>();
            listBookingDto.Add(bookingDto);
            List<string> descriptions = new List<string>();
            descriptions.Add(description);

            BookingEvent[] bookingEvents = new BookingEvent[] { bookingEvent };
            repositoryMock.Setup(r => r.Query<BookingEvent>()).Returns(bookingEvents.AsQueryable());
            List<BookingEventDto> bookingEventDtos = new List<BookingEventDto>();

            // Act
            var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object);
            bookingEventDtos = bookingService
                .GetByBookingAndShortDescription(listBookingDto, descriptions);

            // Assert
            repositoryMock.Verify(r => r.Query<BookingEvent>());
            Assert.AreEqual(id, bookingEventDtos[0].Id);
        }
Beispiel #14
0
        public async Task <ActionResult <ServiceResponse <BookingEvent> > > UpdateBooking(int bookingId, [FromBody] BookingEvent toUpdateBooking)
        {
            var dbBooking = await _service.GetBookingById(bookingId);

            if (dbBooking == null || !dbBooking.Id.ToString().Equals(toUpdateBooking.Id))
            {
                return(BadRequest());
            }
            DateTime.TryParse(toUpdateBooking.Start, out DateTime fromDate);
            DateTime.TryParse(toUpdateBooking.End, out DateTime toDate);
            int.TryParse(toUpdateBooking.Resource, out int toUpdateRoomId);
            var booking = new Booking
            {
                Id       = dbBooking.Id,
                RoomId   = toUpdateRoomId,
                FromDate = fromDate,
                ToDate   = toDate,
            };

            if (dbBooking.RoomId == toUpdateRoomId)
            {
                await _service.UpdateBookingDate(booking);

                return(Ok());
            }
            else
            {
                await _service.UpdateBookingRoom(booking);

                return(Ok());
            }
        }