예제 #1
0
        public async Task <IActionResult> Add([FromBody] AppointmentRequestDto requestDto)
        {
            m_Logger.Information($"{nameof(Add)} Invoked");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var  request = m_Mapper.Map <AppointmentDto>(requestDto);
                bool result  = await m_AppointmentManager.AddAppointmentAsync(request).ConfigureAwait(false);

                if (result)
                {
                    return(Ok(result));
                }
            }
            catch (Exception ex)
            {
                m_Logger.Error(ex, "Error caught in the controller class.");
            }
            return(BadRequest(HttpStatusCode.BadRequest));
        }
        public ActionResult GetAppointment([FromBody] AppointmentRequestDto request)
        {
            var appointment = service.LoadAppointments(configuration, request);

            return(Ok(appointment));
        }
예제 #3
0
        public AppointmentResponseDto LoadAppointments(IConfiguration configuration, AppointmentRequestDto request)
        {
            AppointmentResponseDto response = new AppointmentResponseDto();
            List <AppointmentDto>  appts    = new List <AppointmentDto>();
            string secretkey = "";

            try
            {
                //Todo: verify SecretKey before the response
                secretkey = configuration.GetSection("SecretKey").Get <string>();
                if (string.Compare(secretkey, request.SecretKey, false) != 0)
                {
                    throw new Exception("Client Secret Key did not match!");
                }

                password = configuration.GetSection("Password").Get <string>();
                username = "";
                var roomlist = configuration.GetSection("RoomList:Rooms").Get <List <RoomDto> >().Where(r => r.RoomId == request.RoomId).ToList();
                if (roomlist.Count > 0)
                {
                    username = roomlist[0].RoomEmail;
                }
                DateTime startDate = DateTime.Now;
                DateTime endDate   = DateTime.Parse(configuration.GetSection("ToTime").Get <string>());
                //startDate = DateTime.Parse("2018-07-01 08:00:00");

                CalendarFolder calendar = FindNamedCalendarFolder("Calendar");  // or FindDefaultCalendarFolder()
                CalendarView   cView    = new CalendarView(startDate, endDate, 50);
                cView.PropertySet = new PropertySet(AppointmentSchema.Id);
                FindItemsResults <Appointment> appointments = calendar.FindAppointments(cView);

                Service.LoadPropertiesForItems(appointments, new PropertySet(AppointmentSchema.Body,
                                                                             AppointmentSchema.RequiredAttendees, AppointmentSchema.Duration,
                                                                             AppointmentSchema.Location, AppointmentSchema.Subject, AppointmentSchema.Organizer,
                                                                             AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.OptionalAttendees, AppointmentSchema.IsMeeting
                                                                             , AppointmentSchema.LastModifiedName, AppointmentSchema.LastModifiedTime));
                foreach (Appointment apt in appointments)
                {
                    //apt.Body.Text = "The meeting has been updated";
                    //apt.Update(ConflictResolutionMode.AutoResolve, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);

                    AppointmentDto dto = new AppointmentDto(apt.Id, apt.Subject, apt.Start.ToString(),
                                                            apt.End.ToString(), apt.Duration.Minutes, apt.Location);
                    dto.Attendee = new List <AttendeeDto>();
                    foreach (Attendee attendee in apt.RequiredAttendees)
                    {
                        dto.Attendee.Add(new AttendeeDto(attendee.Address, attendee.Name));
                    }
                    appts.Add(dto);
                }
                appts.OrderBy(a => a.Start);
                response.IsSuccessful = true;
                response.Appointments = appts;
            }
            catch (Exception ex)
            {
                response.IsSuccessful = false;
                response.Message      = ex.Message;
            }

            return(response);
        }