コード例 #1
0
        public ReserveMeetingRoomOutput ProcessInterview(
            DateTime reservationDateTime,
            string name,
            string surname,
            string phone,
            string email,
            bool reserveMeetingRoom,
            string adminEmail)
        {
            var retVal = new ReserveMeetingRoomOutput();

            var googleCredPath = _env.ContentRootPath + "/google/Google.Apis.Auth.OAuth2.Responses.TokenResponse-user";

            try
            {
                if (reserveMeetingRoom)
                {
                    retVal = ReserveMeetingRoom(reservationDateTime, $"{name} {surname}");
                }

                if (retVal.MeetingRoom == null)
                {
                    SendCouldNotReserveMeetingRoomMail($"{name} {surname}", adminEmail);

                    _googleCalendarClient.CreateEvent(
                        reservationDateTime, "NA!", $"{name} {surname}", phone, email, googleCredPath);

                    return(retVal);
                }

                _googleCalendarClient.CreateEvent(
                    reservationDateTime, retVal.MeetingRoom.Name, $"{name} {surname}", phone, email, googleCredPath);
            }
            catch (Exception ex)
            {
                SendExceptionMail(ex.ToString(), adminEmail);
            }

            return(retVal);
        }
コード例 #2
0
        private ReserveMeetingRoomOutput ReserveMeetingRoom(DateTime reservationDateTime, string fullName)
        {
            var retVal = new ReserveMeetingRoomOutput();

            var myRange = new TimeRange(reservationDateTime, reservationDateTime.AddHours(1));

            var bearerToken = _koplanetClient.GetToken();

            //ilgili tarihte odaların kayıtlarını getir
            var meetingRoomData = _koplanetClient.GetMeetingRoomData(
                bearerToken,
                reservationDateTime.Date);

            var availableMeetingRooms = meetingRoomData
                                        .Where(r => !r.Reservations.Any(t => new TimeRange(reservationDateTime.Date.Add(t.Time), t.Duration).HasInside(myRange)))
                                        .ToList();

            MeetingRoom reservedMeetingRoom = null;

            foreach (var roomName in _koplanetClient.RoomNamesOrderedByPriority)
            {
                reservedMeetingRoom = availableMeetingRooms.FirstOrDefault(r => r.Name.Contains(roomName));
                if (reservedMeetingRoom != null)
                {
                    var newReservation = _koplanetClient.ReserveMeetingRoom(
                        bearerToken, reservedMeetingRoom.Id, reservationDateTime, $"Interview - {fullName}");

                    if (newReservation != null && newReservation.Id > 0)
                    {
                        retVal.MeetingRoom   = reservedMeetingRoom;
                        retVal.ReservationId = newReservation.Id;
                        break;
                    }
                }
            }

            return(retVal);
        }