Ejemplo n.º 1
0
 public IActionResult CreateEvent(EventDisplayViewModel model, string StartDateTime, string EndDateTime)
 {
     model.StartDateTime = Utilities.ConvertStringToDateTime(StartDateTime);
     model.EndDateTime   = Utilities.ConvertStringToDateTime(EndDateTime);
     _repos.CreateEvent(model.Title,
                        model.Note,
                        model.StartDateTime,
                        model.EndDateTime,
                        model.IsAllDay,
                        GetRecuringType(model.recurType));
     return(Redirect("Index"));
 }
Ejemplo n.º 2
0
        //public ActionResult Save(Event updatedEvent, FormCollection formData)
        //{
        //    var action = new DataAction(formData);

        //    try
        //    {
        //        switch (action.Type)
        //        {
        //            case DataActionTypes.Insert: // your Insert logic
        //                _db.Events.Add(updatedEvent);
        //                break;
        //            case DataActionTypes.Delete: // your Delete logic
        //                updatedEvent = _db.Events.SingleOrDefault(ev => ev.id == updatedEvent.id);
        //                _db.Events.Remove(updatedEvent);
        //                break;
        //            default:// "update" // your Update logic
        //                updatedEvent = _db.Events.SingleOrDefault(
        //                ev => ev.id == updatedEvent.id);
        //                UpdateModel(updatedEvent);
        //                break;
        //        }
        //        _db.SaveChanges();
        //        action.TargetId = updatedEvent.id;
        //    }
        //    catch (Exception e)
        //    {
        //        action.Type = DataActionTypes.Error;
        //    }
        //    return (new AjaxSaveResponse(action));
        //}
        // GET: Event


        public ActionResult _GoogleEvents()
        {
            var googleEventsDisplayModel = new GoogleEventsDisplayModel();

            string[]                 SCOPES              = { CalendarService.Scope.CalendarReadonly };
            const string             CALENDAR_ID         = "*****@*****.**";
            var                      eventsViewModelList = new List <EventDisplayViewModel>();
            var                      path = Server.MapPath(@"~/Content/GoogleCalendar/Kentucky HBPA Website Calendar-5072c6abaf14.json");
            ServiceAccountCredential credential;


            using (var stream =
                       new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                var credPath       = stream.Name;
                var json           = System.IO.File.ReadAllText(credPath);
                var serviceAccount = JsonConvert.DeserializeObject <GoogleCalendarServiceAccount>(json);

                credential = new ServiceAccountCredential
                             (
                    new ServiceAccountCredential.Initializer(serviceAccount.Client_email)
                {
                    Scopes = SCOPES
                }.FromPrivateKey(serviceAccount.Private_key)
                             );
            }

            var calendarService = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential
            });

            EventsResource.ListRequest request = calendarService.Events.List(CALENDAR_ID);
            request.TimeMin      = DateTime.Now;
            request.ShowDeleted  = false;
            request.SingleEvents = true;
            request.MaxResults   = 4;
            request.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;

            try
            {
                var events     = request.Execute();
                var jsonEvents = CreateJsonFromEventViewModels(events);

                var eventId = 0;

                if (events.Items != null && events.Items.Count > 0)
                {
                    foreach (var eventItem in events.Items)
                    {
                        eventId += 1;
                        var eventVM = new EventDisplayViewModel()
                        {
                            Title        = eventItem.Summary,
                            Description  = eventItem.Description,
                            StartDate    = eventItem.Start.Date,
                            StartTime    = ExtractDateTimeFromDateTimeRaw(eventItem.Start.DateTimeRaw),
                            Link         = eventItem.HtmlLink,
                            Location     = ParseLocationFromString(eventItem.Location),
                            IdForElement = eventId,
                            Url          = eventItem.HtmlLink
                        };

                        eventVM.StartTimeAmPm = eventVM.StartTime.ToString("h:mm tt");

                        if (eventItem.EndTimeUnspecified != null && eventItem.EndTimeUnspecified != false)
                        {
                            eventVM.EndDate = eventItem.End.Date;
                            eventVM.EndTime = eventItem.End.DateTime.ToString();
                        }

                        eventsViewModelList.Add(eventVM);
                    }
                }

                googleEventsDisplayModel.EventDisplayViewModels = eventsViewModelList;
                googleEventsDisplayModel.SchemaJson             = jsonEvents;

                return(View(googleEventsDisplayModel));
            }
            catch
            {
                return(View(new GoogleEventsDisplayModel()
                {
                    EventDisplayViewModels = null
                }
                            ));

                throw new Exception();
            }
        }