Esempio n. 1
0
        public async Task <ActionResult> CreateEvent(CreateEventModel model, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                List <Location> locationList = model.Location;
                locationList.RemoveAll(o => o.LocationName.Equals("Remove Location"));
                //add location to database
                var listLocation = LocationHelpers.Instance.AddNewLocation(locationList);

                //Adding new event with given infomation to database
                var newEvent = EventDatabaseHelper.Instance.AddNewEvent(model, file, UserHelpers.GetCurrentUser(Session).UserID);

                //Add event place to database
                var listEventPlaces = EventDatabaseHelper.Instance.AddEventPlace(listLocation, newEvent);

                LiveStreamingModel liveModel = new LiveStreamingModel {
                    eventID = newEvent.EventID, Title = newEvent.EventName
                };
                TempData["LiveModel"] = liveModel;
                HttpCookie newEventID = new HttpCookie("CreateEventID");
                newEventID.Value   = newEvent.EventID.ToString();
                newEventID.Expires = DateTime.Now.AddDays(1);
                Response.Cookies.Add(newEventID);
                NotificationDataHelpers.Instance.SendNotifyNewEventToFollower(UserHelpers.GetCurrentUser(Session).UserID, newEvent.EventID);
                return(RedirectToAction("Details", "Event", new{ id = newEvent.EventID }));
            }
            // If we got this far, something failed, redisplay form
            ViewBag.CategoryID       = new SelectList(db.Categories, "CategoryId", "CategoryName");
            TempData["errorTitle"]   = "Error";
            TempData["errorMessage"] = "Please select location from suggestion!";
            return(View("Create", model));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult AddLiveStream(long eventID, string eventName)
        {
            List <EventPlace> listPlace = new List <EventPlace>();

            listPlace = EventDatabaseHelper.Instance.GetEventPlaceByEvent(eventID);
            TempData["EventPlace"] = listPlace;
            //cookie eventModel
            LiveStreamingModel model = new LiveStreamingModel {
                eventID = eventID, Title = eventName
            };

            return(PartialView(model));
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult AddLiveStream(LiveStreamingModel model)
        {
            List <EventPlace> listPlace = new List <EventPlace>();

            TempData["errorTitle"]   = TempData["errorTitle"];
            TempData["errorMessage"] = TempData["errorMessage"];
            if (Request.Cookies["CreateEventID"] != null)
            {
                model.eventID = long.Parse(Request.Cookies["CreateEventID"].Value);
                model.Title   = EventDatabaseHelper.Instance.GetEventByID(model.eventID).EventName;
            }
            listPlace = EventDatabaseHelper.Instance.GetEventPlaceByEvent(model.eventID);
            TempData["EventPlace"] = listPlace;
            //cookie eventModel

            return(PartialView(model));
        }
Esempio n. 4
0
        /// <summary>
        /// View detail of event
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Details(long?id)
        {
            User user = UserHelpers.GetCurrentUser(Session);

            if (user == null)
            {
                if (Request.Cookies["userName"] != null && Request.Cookies["password"] != null)
                {
                    string userName = Request.Cookies["userName"].Value;
                    string password = Request.Cookies["password"].Value;
                    if (UserDatabaseHelper.Instance.ValidateUser(userName, password))
                    {
                        user = UserDatabaseHelper.Instance.GetUserByUserName(userName);
                        if (UserDatabaseHelper.Instance.isLookedUser(user.UserName))
                        {
                            TempData["errorTitle"]   = "Locked User";
                            TempData["errorMessage"] = "Your account is locked! Please contact with our support";

                            return(RedirectToAction("Index", "Home"));
                        }
                        UserHelpers.SetCurrentUser(Session, user);
                    }
                }
            }

            if (id == null)
            {
                TempData["errorTitle"]   = "Failed to load event";
                TempData["errorMessage"] = "Event not avaiable!";
                return(RedirectToAction("Index", "Home"));
            }
            Event evt = EventDatabaseHelper.Instance.GetEventByID(id);

            if (evt == null)
            {
                TempData["errorTitle"]   = "Failed to load event";
                TempData["errorMessage"] = "Event not avaiable!";
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                if (evt.Privacy == EventZoneConstants.privateEvent || evt.Status == EventZoneConstants.Lock)
                {
                    if (user != null && (EventDatabaseHelper.Instance.IsEventOwnedByUser(id, user.UserID) || user.UserRoles == EventZoneConstants.Mod))
                    {
                    }
                    else
                    {
                        TempData["errorTitle"]   = "Failed to load event";
                        TempData["errorMessage"] = "This event is set to private or has been locked!";
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }

            ViewDetailEventModel viewDetail = new ViewDetailEventModel();

            viewDetail.createdBy = EventDatabaseHelper.Instance.GetAuthorEvent(evt.EventID);
            viewDetail.eventId   = evt.EventID;
            viewDetail.eventName = evt.EventName;

            viewDetail.eventAvatar      = EventDatabaseHelper.Instance.GetImageByID(evt.Avatar).ImageLink;
            viewDetail.numberView       = evt.View;
            viewDetail.isVerified       = evt.IsVerified;
            viewDetail.eventDescription = evt.EventDescription;
            viewDetail.StartTime        = evt.EventStartDate;
            viewDetail.EndTime          = evt.EventEndDate;
            viewDetail.isOwningEvent    = false;
            viewDetail.NumberLike       = EventDatabaseHelper.Instance.CountLike(evt.EventID);
            viewDetail.NumberDisLike    = EventDatabaseHelper.Instance.CountDisLike(evt.EventID);
            viewDetail.NumberFowllower  = EventDatabaseHelper.Instance.CountFollowerOfEvent(evt.EventID);
            viewDetail.eventLocation    = EventDatabaseHelper.Instance.GetEventLocation(evt.EventID);
            viewDetail.eventVideo       = EventDatabaseHelper.Instance.GetEventVideo(evt.EventID);
            viewDetail.eventComment     = EventDatabaseHelper.Instance.GetListComment(evt.EventID);
            viewDetail.Category         = EventDatabaseHelper.Instance.GetEventCategory(evt.EventID);
            viewDetail.FindLike         = new LikeDislike();
            viewDetail.FindLike.Type    = EventZoneConstants.NotRate;
            viewDetail.FindLike.EventID = evt.EventID;
            LiveStreamingModel liveModel = new LiveStreamingModel {
                eventID = evt.EventID, Title = evt.EventName
            };

            TempData["LiveModel"] = liveModel;
            if (user != null)
            {
                viewDetail.isOwningEvent = EventDatabaseHelper.Instance.IsEventOwnedByUser(evt.EventID, user.UserID);
                if (viewDetail.isOwningEvent)
                {
                    viewDetail.eventImage = EventDatabaseHelper.Instance.GetEventImage(evt.EventID);
                }
                else
                {
                    viewDetail.eventImage = EventDatabaseHelper.Instance.GetEventApprovedImage(evt.EventID);
                }
                viewDetail.FindLike = UserDatabaseHelper.Instance.FindLike(user.UserID, evt.EventID);
                if (viewDetail.FindLike == null)
                {
                    viewDetail.FindLike      = new LikeDislike();
                    viewDetail.FindLike.Type = EventZoneConstants.NotRate;
                }
                viewDetail.isFollowing = UserDatabaseHelper.Instance.IsFollowingEvent(user.UserID, evt.EventID);
            }
            else
            {
                viewDetail.eventImage = EventDatabaseHelper.Instance.GetEventApprovedImage(evt.EventID);
            }
            viewDetail.Privacy = evt.Privacy;
            if (TempData["EventDetailTask"] == null)
            {
                ViewData["EventDetailTask"] = "EventDetail";
                if (user == null || EventDatabaseHelper.Instance.GetAuthorEvent(evt.EventID).UserID != user.UserID)
                {
                    EventDatabaseHelper.Instance.AddViewEvent(evt.EventID);
                    viewDetail.numberView = evt.View;
                }
                return(View(viewDetail));
            }
            else
            {
                ViewData["EventDetailTask"] = "EditEvent";
                return(View(viewDetail));
            }
        }
Esempio n. 5
0
        public async Task <ActionResult> IndexAsync(LiveStreamingModel liveModel, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                JavaScriptSerializer objJavascript = new JavaScriptSerializer();
                liveModel = objJavascript.Deserialize <LiveStreamingModel>(Request.Cookies["liveModel"].Value);
            }
            else
            {
                if (liveModel.Quality != null)
                {
                    HttpCookie newModel = new HttpCookie("liveModel");
                    newModel.Value   = new JavaScriptSerializer().Serialize(liveModel);
                    newModel.Expires = DateTime.Now.AddHours(10);
                    Response.Cookies.Add(newModel);
                }
            }
            var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).
                         AuthorizeAsync(cancellationToken);


            if (result.Credential != null)
            {
                var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = result.Credential,
                    ApplicationName       = Assembly.GetExecutingAssembly().GetName().Name
                });
                LiveBroadcastSnippet broadcastSnippet = new LiveBroadcastSnippet();
                broadcastSnippet.Title = liveModel.Title;
                broadcastSnippet.ScheduledStartTime = liveModel.StartTimeYoutube.CompareTo(DateTime.Now) < 0 ? (DateTime.Now) : liveModel.StartTimeYoutube;
                broadcastSnippet.ScheduledEndTime   = liveModel.EndTimeYoutube;
                // Set the broadcast's privacy status to "private". See:
                // https://developers.google.com/youtube/v3/live/docs/liveBroadcasts#status.privacyStatus
                LiveBroadcastStatus status = new LiveBroadcastStatus();
                if (liveModel.PrivacyYoutube == EventZoneConstants.publicEvent)
                {
                    status.PrivacyStatus = "public";
                }
                else if (liveModel.PrivacyYoutube == EventZoneConstants.unlistedEvent)
                {
                    status.PrivacyStatus = "unlisted";
                }
                else
                {
                    status.PrivacyStatus = "private";
                }

                //Set LiveBroadcast
                LiveBroadcast broadcast       = new LiveBroadcast();
                LiveBroadcast returnBroadcast = new LiveBroadcast();
                broadcast.Kind    = "youtube#liveBroadcast";
                broadcast.Snippet = broadcastSnippet;
                broadcast.Status  = status;
                LiveBroadcastsResource.InsertRequest liveBroadcastInsert = youtubeService.LiveBroadcasts.Insert(broadcast, "snippet,status");
                try
                {
                    returnBroadcast = liveBroadcastInsert.Execute();
                }
                catch (Exception ex) {
                    TempData["errorTitle"]   = "Error";
                    TempData["errorMessage"] = ex.Message;
                    result.Credential.RevokeTokenAsync(CancellationToken.None).Wait();
                    return(RedirectToAction("Details", "Event", liveModel.eventID));
                }

                //Set LiveStream Snippet
                LiveStreamSnippet streamSnippet = new LiveStreamSnippet();
                streamSnippet.Title = liveModel.Title + "Stream Title";
                CdnSettings cdnSettings = new CdnSettings();
                cdnSettings.Format        = liveModel.Quality;
                cdnSettings.IngestionType = "rtmp";

                //Set LiveStream
                LiveStream streamLive = new LiveStream();
                streamLive.Kind    = "youtube#liveStream";
                streamLive.Snippet = streamSnippet;
                streamLive.Cdn     = cdnSettings;
                LiveStream returnLiveStream = youtubeService.LiveStreams.Insert(streamLive, "snippet,cdn").Execute();
                LiveBroadcastsResource.BindRequest liveBroadcastBind = youtubeService.LiveBroadcasts.Bind(returnBroadcast.Id, "id,contentDetails");
                liveBroadcastBind.StreamId = returnLiveStream.Id;
                try
                {
                    returnBroadcast = liveBroadcastBind.Execute();
                }
                catch (Exception ex)
                {
                    TempData["errorTitle"]   = "Error";
                    TempData["errorMessage"] = ex.Message;
                    result.Credential.RevokeTokenAsync(CancellationToken.None).Wait();
                    return(RedirectToAction("Details", "Event", liveModel.eventID));
                }

                //Return Value
                String streamName       = returnLiveStream.Cdn.IngestionInfo.StreamName;
                String primaryServerUrl = returnLiveStream.Cdn.IngestionInfo.IngestionAddress;
                String backupServerUrl  = returnLiveStream.Cdn.IngestionInfo.BackupIngestionAddress;
                String youtubeUrl       = "https://www.youtube.com/watch?v=" + returnBroadcast.Id;

                //youtubeReturnModel model = new youtubeReturnModel { streamName = streamName, primaryServerUrl = primaryServerUrl,backupServerUrl=backupServerUrl,youtubeUrl=youtubeUrl };
                Video video = new Video {
                    EventPlaceID  = liveModel.EventPlaceID,
                    VideoLink     = youtubeUrl,
                    PrimaryServer = primaryServerUrl,
                    StartTime     = liveModel.StartTimeYoutube,
                    Privacy       = liveModel.PrivacyYoutube,
                    EndTime       = liveModel.EndTimeYoutube,
                    BackupServer  = backupServerUrl,
                    StreamName    = streamName
                };
                EventDatabaseHelper.Instance.AddVideo(video);

                HttpCookie newEventID = new HttpCookie("CreateEventID");
                newEventID.Expires = DateTime.Now.AddDays(-1);
                Request.Cookies.Add(newEventID);
                HttpCookie newModel = new HttpCookie("liveModel");
                newModel.Value   = new JavaScriptSerializer().Serialize(liveModel);
                newModel.Expires = DateTime.Now.AddHours(-1);
                Response.Cookies.Add(newModel);
                result.Credential.RevokeTokenAsync(CancellationToken.None).Wait();
                return(RedirectToAction("Details", "Event", new { id = EventDatabaseHelper.Instance.GetEventPlaceByID(liveModel.EventPlaceID).EventID }));
            }
            else
            {
                return(new RedirectResult(result.RedirectUri));
            }
        }