Beispiel #1
0
        public async Task GetAllShouldReturnCorrectCount()
        {
            var service = new EventsService(this._dbContext, this._mapper, this._moviesService, this._peopleService);
            await service.CreateEvent(new CreateEventViewModel());

            await service.CreateEvent(new CreateEventViewModel());

            var allEvents = await service.GetAll();

            var count = allEvents.Count();

            Assert.Equal(2, count);
        }
Beispiel #2
0
        public async Task CreateEventShouldReturnOne()
        {
            var service = new EventsService(this._dbContext, this._mapper, this._moviesService, this._peopleService);

            var result = await service.CreateEvent(new CreateEventViewModel());

            Assert.Equal(1, result);
        }
Beispiel #3
0
        // Create an event.
        // This snippet creates an hour-long event three days from now.
        public async Task <ActionResult> CreateEvent()
        {
            ResultsViewModel results = new ResultsViewModel();

            try
            {
                // Create the event.
                results.Items = await eventsService.CreateEvent();
            }
            catch (ServiceException se)
            {
                if ((se.InnerException as AuthenticationException)?.Error.Code == Resource.Error_AuthChallengeNeeded)
                {
                    HttpContext.Request.GetOwinContext().Authentication.Challenge();
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(View("Events", results));
        }
        // Create an event.
        // This snippet creates an hour-long event three days from now.
        public async Task <ActionResult> CreateEvent()
        {
            ResultsViewModel results = new ResultsViewModel();

            try
            {
                // Initialize the GraphServiceClient.
                GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

                // Create the event.
                results.Items = await eventsService.CreateEvent(graphClient);
            }
            catch (ServiceException se)
            {
                if (se.Error.Message == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }

                // Personal accounts that aren't enabled for the Outlook REST API get a "MailboxNotEnabledForRESTAPI" or "MailboxNotSupportedForRESTAPI" error.
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(View("Events", results));
        }
Beispiel #5
0
        public async Task TestCreateEventError1()
        {
            var start     = DateTime.Now;
            var end       = new DateTime(2015, 1, 25);
            var close     = start.AddDays((end - start).TotalDays / 2);
            var accountId = Guid.Empty;

            CreateEventResponse response = await _eventsService.CreateEvent(new CreateEventRequest
            {
                AccountId = accountId,
                Title     = "a a 2015",
                ImageUri  = "localhost",
                StartDate = start,
                EndDate   = end,
                CloseDate = close,
                ExpectedEventCondition = "a a a a a 2015",
                EventRelationType      = EventRelationType.MenyVsMeny,
                ArbiterAccountIds      = new[] { accountId },
                AlgorithmType          = AlgorithmType.Exponential,
                StartRate    = 100,
                LocusRage    = 1,
                EndRate      = 0,
                CurrencyType = CurrencyType.Reputation
            });
        }
        public async Task <ActionResult> Create([Bind(Include = "Subject,EventDate,EventStart,EventEnd")] EventsItem eventsItem)
        {
            EventsItem results = new EventsItem();
            // Initialize the GraphServiceClient.
            GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();
            var userDetails = await eventsService.GetMyDetails(graphClient);

            try
            {
                var subject        = Request.Form["Subject"];
                var eventDate      = Request.Form["EventDate"];
                var eventStartTime = Request.Form["EventStart"];
                var eventEndTime   = Request.Form["EventEnd"];

                var eventdatetime = DateTime.Parse(eventDate);
                var startTimespan = DateTime.ParseExact(eventStartTime,
                                                        "hh:mm tt", CultureInfo.InvariantCulture);
                var endTimespan = DateTime.ParseExact(eventEndTime,
                                                      "hh:mm tt", CultureInfo.InvariantCulture);
                var s = eventsItem;

                OfficeSchedule officeSchedule = new OfficeSchedule
                {
                    end_time = new DateTime(eventdatetime.Year, eventdatetime.Month, eventdatetime.Day, endTimespan.Hour,
                                            endTimespan.Minute, endTimespan.Second),
                    start_time = new DateTime(eventdatetime.Year, eventdatetime.Month, eventdatetime.Day, startTimespan.Hour,
                                              startTimespan.Minute, startTimespan.Second),
                    Subject = subject,
                    Email   = userDetails.Mail ?? userDetails.UserPrincipalName,
                };

                //var mail = await eventsService.GetMyEmailAddress(graphClient);

                try
                {
                    db.officeSchedule.Add(officeSchedule);
                    db.SaveChanges();
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.)
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }

                results = new EventsItem()
                {
                    Subject   = subject,
                    StartTime = new DateTimeTimeZone
                    {
                        DateTime = new DateTime(eventdatetime.Year, eventdatetime.Month, eventdatetime.Day, startTimespan.Hour,
                                                startTimespan.Minute, startTimespan.Second).ToString("o"),
                        TimeZone = TimeZoneInfo.Local.Id
                    },
                    EndTime = new DateTimeTimeZone
                    {
                        DateTime = new DateTime(eventdatetime.Year, eventdatetime.Month, eventdatetime.Day, endTimespan.Hour,
                                                endTimespan.Minute, endTimespan.Second).ToString("o"),
                        TimeZone = TimeZoneInfo.Local.Id
                    },
                };

                // Create the event.
                results = await eventsService.CreateEvent(graphClient, results);
            }
            catch (ServiceException se)
            {
                if (se.Error.Message == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }

                // Personal accounts that aren't enabled for the Outlook REST API get a "MailboxNotEnabledForRESTAPI" or "MailboxNotSupportedForRESTAPI" error.
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(RedirectToAction("Index", "Events").Success("Event Created"));
        }