Example #1
0
        public async Task <Comment> SaveComment(string senderUsername, string receiverUsername, string message, string parentId, string streamId)
        {
            try
            {
                var sender = await Get <Profile>(SQLQueries.GetUserWithUsername, senderUsername);

                var receiver = await Get <Profile>(SQLQueries.GetUserWithUsername, receiverUsername);

                Comment comment = new Comment
                {
                    Id                   = Guid.NewGuid().ToString(),
                    SenderName           = sender.Name,
                    SenderUsername       = sender.Username,
                    SenderProfilePicture = sender.ProfilePicture,
                    ReceiverName         = receiver.Name,
                    ReceiverUsername     = receiver.Username,
                    Message              = MiscHelperMethods.URLIFY(MiscHelperMethods.RemoveAllStyleTags(message)),
                    ParentId             = parentId,
                    Date                 = DateTime.UtcNow,
                    StreamId             = streamId,
                    ProfileColor         = sender.ProfileColor,
                };

                await Save(comment.Id, comment);

                return(comment);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in SaveComment " + e.Message);
                return(null);
            }
        }
Example #2
0
        public async Task SendMessageToChatRoom(string chatId, string userName, string name, string message, string profilePicture, string chatColor, int offset)
        {
            var    date            = DateTime.UtcNow;
            string archivedVideoId = (await storageService.Get <Channel>(SQLQueries.GetUserChannelWithUsername, chatId)).ArchivedVideoId;

            message = MiscHelperMethods.URLIFY(MiscHelperMethods.RemoveAllStyleTags(message));
            string chat = Serialize(chatId, userName, name, message, profilePicture, date, offset, chatColor, archivedVideoId);
            await Clients.Group(chatId).SendAsync("ReceiveMessage", chat);

            await SaveMessage(chatId, userName, name, message, profilePicture, date, offset, chatColor, archivedVideoId);
        }
Example #3
0
        private static void Main()
        {
            var provider = LanguageVendors.Microsoft.GetVisualBasicLanguage().GetMyProvider(VisualBasicVersion.Version11);
            var timeTest = MiscHelperMethods.CreateActionOfTime <ILanguageProvider <IVisualBasicLanguage, IMyVisualBasicProvider> >(Test);
            var time1    = timeTest(provider);
            var time2    = timeTest(provider);

            Console.WriteLine("Took {0}ms to process the first time (Includes JIT Overhead).", time1);
            Console.WriteLine("Took {0}ms to process the second time.", time2);
            //database.Name = "TestDatabase";
        }
Example #4
0
        public async Task OnPostSignUpTutor()
        {
            string id = Guid.NewGuid().ToString();

            if (Request.Form.ContainsKey("Token"))
            {
                await SignUpOauth(Request, id, "tutor");
            }
            else
            {
                if (!await VerifyRequest(Request)) //TOM this wont work with google ouath. The email wont be populated becasue it gets it from an api call LOOK at SignUpOauth
                {
                    // JavaScript checks seeem to have been ignored!
                    // Potential attack detected. Aborting.
                    return;
                }

                Profile user = new Profile
                {
                    Id                    = id,
                    Name                  = Request.Form["FirstName"] + "|" + Request.Form["LastName"],
                    EmailAddress          = Request.Form["EmailAddress"],
                    Username              = Request.Form["Username"],
                    Password              = encryptionService.EncryptPassword(Request.Form["Password"]),
                    ProfileType           = "tutor",
                    College               = Request.Form["SchoolName"],
                    NotificationSubscribe = "True",
                    Expiration            = DateTime.UtcNow,
                    PayPalAddress         = Request.Form["PayPalAddress"],
                    AcceptedTutor         = false,
                    LastLogin             = DateTime.UtcNow,
                    ProfileColor          = MiscHelperMethods.GetRandomColor(),
                    ProfileSince          = DateTime.UtcNow,
                    ProfilePicture        = MiscHelperMethods.defaultProfilePicture,
                    ProfileBanner         = MiscHelperMethods.defaultBanner,
                    TimeZone              = MiscHelperMethods.GetTimeZoneBasedOfOffset(Request.Form["Time"])
                };

                await storageService.Save(user.Id, user);
                await AddUs5AsFollowers(user.Id);

                await cookieService.SignIn(Request.Form["Username"], encryptionService.DecryptPassword(user.Password, Request.Form["Password"]));
            }

            await CreateChannel(Request.Form["Username"]);

            topicService.TutorTopics(Request.Form["Username"], GetAllSelectedTopics(Request.Form["Topics"].ToString().Split('|')));

            await emailService.SendTemplateToStreamwork("tutorSignUp", await storageService.Get <Profile>(SQLQueries.GetUserWithUsername, Request.Form["Username"]), Request.Form.Files);
        }
Example #5
0
 public void TutorTopics(string username, List <string> topics)
 {
     topics.ForEach(async x => {
         string guid = Guid.NewGuid().ToString();
         await storage.Save(guid, new TopicTutor
         {
             Id         = guid,
             Tutor      = username,
             Topic      = x,
             Since      = DateTime.UtcNow,
             TopicColor = MiscHelperMethods.GetCorrespondingStreamColor(x)
         });
     });
 }
Example #6
0
        public async Task <List <Profile> > GetAllNonFollowees(string followerId) //all users that arent follwing the followee
        {
            var listOfFollowees = await GetList <Follow>(SQLQueries.GetAllFollowersWithId, new string[] { followerId });

            if (listOfFollowees.Count != 0)
            {
                List <string> idList = new List <string>();
                foreach (var followee in listOfFollowees)
                {
                    idList.Add(followee.FolloweeId);
                }
                return(await GetList <Profile>(SQLQueries.GetAllTutorsNotInTheList, MiscHelperMethods.FormatQueryString(idList)));
            }

            return(await GetList <Profile>(SQLQueries.GetAllApprovedTutors, null));
        }
Example #7
0
        public async Task <IActionResult> OnGet(string id, string commentId)
        {
            if (!cookieService.Authenticated)
            {
                return(Redirect(cookieService.Url("/Home/SignIn/" + encryptionService.EncryptString("/Stream/Archive/" + id + "/" + commentId))));
            }

            CurrentUserProfile = await cookieService.GetCurrentUser();

            Video = await storageService.Get <Video>(SQLQueries.GetArchivedStreamsWithStreamId, id);

            UserProfile = await storageService.Get <Profile>(SQLQueries.GetUserWithUsername, Video.Username);

            UserChannel = await storageService.Get <Channel>(SQLQueries.GetUserChannelWithUsername, Video.Username);

            UserChannel.StreamSubjectIcon = MiscHelperMethods.GetCorrespondingSubjectThumbnail(Video.StreamSubject);
            ChatInfo    = encryptionService.EncryptString(Video.Id);
            FollowValue = await followService.IsFollowingFollowee(CurrentUserProfile.Id, UserProfile.Id);

            UserVideos = await storageService.GetList <Video>(SQLQueries.GetArchivedStreamsWithUsername, new string[] { UserProfile.Username });

            OtherVideos = await storageService.GetList <Video>(SQLQueries.GetRandomArchivedStreams, new string[] { });

            RelatedTutors = (await storageService.GetList <Profile>(SQLQueries.GetAllTutorsNotInTheList, new string[] { UserProfile.Id })).GetRange(0, 5);
            Sections      = profileService.GetSections(UserProfile);
            Schedule      = await scheduleService.GetSchedule(UserProfile);

            Comments = await commentService.GetAllComments(Video.Id);

            NumberOfStreams   = UserVideos.Count;
            NumberOfFollowers = await followService.GetNumberOfFollowers(UserProfile.Id);

            NumberOfViews = UserVideos.Sum(x => x.Views);

            Notifications = await notificationService.GetNotifications(CurrentUserProfile.Username);

            if (!string.IsNullOrEmpty(commentId))
            {
                NotificationRequestComment = await storageService.Get <Comment>(SQLQueries.GetCommentWithId, commentId);
            }
            AreThereUnseenNotifications = await notificationService.AreThereUnseenNotifications(CurrentUserProfile.Username);

            Video.Views += 1;
            await storageService.Save(Video.Id, Video);

            return(Page());
        }
Example #8
0
        public async Task <Comment> EditComment(string message, string commentId)
        {
            try
            {
                var comment = await Get <Comment>(SQLQueries.GetCommentWithId, new string[] { commentId });

                comment.Message = MiscHelperMethods.URLIFY(message);
                comment.Edited  = "true";
                await Save(comment.Id, comment);

                return(comment);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in EditComment " + e.Message);
                return(null);
            }
        }
Example #9
0
        public async Task <IActionResult> OnGet(string searchTerm)
        {
            var tutors = await storageService.GetList <TutorSubject>(SQLQueries.GetApprovedTutorSubjects, "");

            CurrentUserProfile = await cookieService.GetCurrentUser();

            Videos = await storageService.GetList <Video>(SQLQueries.GetArchivedStreamsInDescendingOrderByViews, "");

            PopularTutors = tutors.GetRange(0, 3);
            LiveChannels  = await storageService.GetList <Channel>(SQLQueries.GetAllUserChannelsThatAreStreaming, "");

            AllTutors = new List <TutorSubject>();
            Hashtable table = new Hashtable();

            foreach (var tutor in tutors)
            {
                if (!table.Contains(tutor.Username))
                {
                    table.Add(tutor.Username, tutor);
                    AllTutors.Add(tutor);
                }
            }
            AllScheduledStreams = await storageService.GetList <Schedule>(SQLQueries.GetAllScheduledStreams, "");

            if (searchTerm != "SW")
            {
                SearchTerm = searchTerm;
                if (MiscHelperMethods.GetCorrespondingStreamColor(SearchTerm) != null)
                {
                    isFilterTerm = true;
                }
            }

            if (CurrentUserProfile != null)
            {
                Notifications = await notificationService.GetNotifications(CurrentUserProfile.Username);

                AreThereUnseenNotifications = await notificationService.AreThereUnseenNotifications(CurrentUserProfile.Username);
            }

            return(Page());
        }
Example #10
0
        public async Task <IActionResult> OnGet(string tutor)
        {
            if (!cookieService.Authenticated)
            {
                return(Redirect(cookieService.Url("/Home/SignIn/" + encryptionService.EncryptString("/Stream/Live/" + tutor))));
            }

            CurrentUserProfile = await cookieService.GetCurrentUser();

            UserProfile = await storageService.Get <DataModels.Profile>(SQLQueries.GetUserWithUsername, tutor);

            UserChannel = await storageService.Get <Channel>(SQLQueries.GetUserChannelWithUsername, tutor);

            if (UserChannel.StreamTitle == null)
            {
                return(Redirect(cookieService.Url("/Profiles/Tutor/" + UserProfile.Username)));
            }

            UserChannel.StreamSubjectIcon = MiscHelperMethods.GetCorrespondingSubjectThumbnail(UserChannel.StreamSubject);
            ChatInfo    = encryptionService.EncryptString(UserChannel.ArchivedVideoId);
            FollowValue = await followService.IsFollowingFollowee(CurrentUserProfile.Id, UserProfile.Id);

            UserArchivedStreams = await storageService.GetList <Video>(SQLQueries.GetArchivedStreamsWithUsername, new string[] { UserProfile.Username });

            RelatedTutors = (await storageService.GetList <DataModels.Profile>(SQLQueries.GetAllTutorsNotInTheList, new string[] { UserProfile.Id })).GetRange(0, 5);
            Sections      = profileService.GetSections(UserProfile);
            Schedule      = await scheduleService.GetSchedule(UserProfile);

            NumberOfStreams   = UserArchivedStreams.Count;
            NumberOfFollowers = await followService.GetNumberOfFollowers(UserProfile.Id);

            NumberOfViews = UserArchivedStreams.Sum(x => x.Views);

            Notifications = await notificationService.GetNotifications(CurrentUserProfile.Username);

            AreThereUnseenNotifications = await notificationService.AreThereUnseenNotifications(CurrentUserProfile.Username);

            UserChannel.Views += 1;
            await storageService.Save(UserChannel.Id, UserChannel);

            return(Page());
        }
Example #11
0
        public async Task <IActionResult> OnPostSignIn(string route)
        {
            var username = Request.Form["Username"];
            var password = Request.Form["Password"];
            var time     = Request.Form["Time"]; //gets time offset

            var userProfile = await storageService.Get <Profile>(SQLQueries.GetUserWithUsername, username);

            if (userProfile == null)
            {
                // User can also sign in with email address, in which case the username needs to be updated
                userProfile = await storageService.Get <Profile>(SQLQueries.GetUserWithEmailAddress, username);

                if (userProfile != null)
                {
                    username = userProfile.Username;
                }
            }

            if (userProfile != null)
            {
                if (time != "")
                {
                    userProfile.TimeZone = MiscHelperMethods.GetTimeZoneBasedOfOffset(time);
                    await storageService.Save(userProfile.Id, userProfile);
                }

                var signInProfile = await cookieService.SignIn(username, encryptionService.DecryptPassword(userProfile.Password, password));

                if (signInProfile != null)
                {
                    return(cookieService.Route(signInProfile, route, encryptionService));
                }
            }

            return(new JsonResult(new { Message = JsonResponse.Failed.ToString() }));
        }
Example #12
0
        public async Task SignUpOauth(HttpRequest request, string id, string type)
        {
            var         oauthRequestToken = request.Form["Token"];
            GoogleOauth oauthInfo         = await storageService.CallJSON <GoogleOauth>("https://oauth2.googleapis.com/tokeninfo?id_token=" + oauthRequestToken); //GETS EMAIL FOR GOOGLE OAUTH

            var password = encryptionService.EncryptPassword("!!0_STREAMWORK_!!0");

            var profile = new Profile {
                Id                    = id,
                Name                  = oauthInfo.Name.Contains(' ') ? oauthInfo.Name.Replace(' ', '|') : oauthInfo.Name + "|",
                EmailAddress          = oauthInfo.Email,
                Username              = Request.Form["Username"],
                Password              = password,
                ProfileType           = type,
                College               = Request.Form["SchoolName"],
                NotificationSubscribe = "True",
                Expiration            = DateTime.UtcNow,
                AcceptedTutor         = false,
                LastLogin             = DateTime.UtcNow,
                ProfileColor          = MiscHelperMethods.GetRandomColor(),
                ProfileSince          = DateTime.UtcNow,
                ProfilePicture        = MiscHelperMethods.defaultProfilePicture,
                ProfileBanner         = MiscHelperMethods.defaultBanner,
                TimeZone              = MiscHelperMethods.GetTimeZoneBasedOfOffset(Request.Form["Time"])
            };

            if (type == "tutor")
            {
                profile.PayPalAddress = Request.Form["PayPalAddress"];
                await AddUs5AsFollowers(id);
            }

            await storageService.Save(id, profile);

            await cookieService.SignIn(Request.Form["Username"], encryptionService.DecryptPassword(password, "!!0_STREAMWORK_!!0"));
        }
        public async Task <string> CreateNotificationTemplate(Notification notification, bool isPush)
        {
            string reader      = "";
            var    userProfile = await Get <Profile>(SQLQueries.GetUserWithUsername, notification.ReceiverUsername);

            if (notification.Type == NotificationType.Follow.ToString())
            {
                string template;

                if (!isPush)
                {
                    template = "NotificationTemplates/FollowNotification.html";
                }
                else
                {
                    template = "NotificationTemplates/PushNotifications/FollowPushNotification.html";
                }

                using (StreamReader streamReader = new StreamReader(template))
                {
                    reader = streamReader.ReadToEnd();
                    reader = reader.Replace("{Username}", notification.SenderUsername);
                    reader = reader.Replace("{NotificationId}", notification.Id);
                    reader = reader.Replace("{SenderProfilePicture}", notification.SenderProfilePicture);
                    reader = reader.Replace("{ProfileColor}", notification.ProfileColor);
                    reader = reader.Replace("{SenderName}", notification.SenderName.Replace('|', ' '));
                    reader = reader.Replace("{NotificationMessage}", " started following you");
                    reader = reader.Replace("{NotificationDate}", notification.Date.AddMinutes(MiscHelperMethods.GetOffsetBasedOfTimeZone(userProfile.TimeZone)).ToShortTimeString());
                    reader = reader.Replace("{SenderUsername}", notification.SenderUsername);
                    reader = reader.Replace("{NotificationType}", notification.Type);
                }
            }
            else if (notification.Type == NotificationType.Comment.ToString())
            {
                string template;

                if (!isPush)
                {
                    template = "NotificationTemplates/CommentNotification.html";
                }
                else
                {
                    template = "NotificationTemplates/PushNotifications/CommentPushNotification.html";
                }

                var comment = await Get <Comment>(SQLQueries.GetCommentWithId, notification.ObjectId);

                if (comment == null)
                {
                    return(null);
                }
                var video = await Get <Video>(SQLQueries.GetArchivedStreamsWithId, comment.StreamId);

                if (video == null)
                {
                    return(null);
                }

                using (StreamReader streamReader = new StreamReader(template))
                {
                    reader = streamReader.ReadToEnd();
                    reader = reader.Replace("{Username}", notification.SenderUsername);
                    reader = reader.Replace("{NotificationId}", notification.Id);
                    reader = reader.Replace("{SenderProfilePicture}", notification.SenderProfilePicture);
                    reader = reader.Replace("{ProfileColor}", notification.ProfileColor);
                    reader = reader.Replace("{SenderName}", notification.SenderName.Replace('|', ' '));
                    reader = reader.Replace("{NotificationMessage}", " commented on your stream (" + video.StreamTitle + ")");
                    reader = reader.Replace("{CommentMessage}", comment.Message);
                    reader = reader.Replace("{VideoId}", video.StreamID); //we need to use videos Id rather than streamId becasue we cahnge streaming later it will be hard to manage
                    reader = reader.Replace("{CommentId}", comment.Id);
                    reader = reader.Replace("{NotificationDate}", notification.Date.AddMinutes(MiscHelperMethods.GetOffsetBasedOfTimeZone(userProfile.TimeZone)).ToShortTimeString());
                    reader = reader.Replace("{SenderUsername}", notification.SenderUsername);
                    reader = reader.Replace("{NotificationType}", notification.Type);
                }
            }
            else if (notification.Type == NotificationType.Reply.ToString())
            {
                string template;

                if (!isPush)
                {
                    template = "NotificationTemplates/ReplyNotification.html";
                }
                else
                {
                    template = "NotificationTemplates/PushNotifications/ReplyPushNotification.html";
                }

                var comment = await Get <Comment>(SQLQueries.GetCommentWithId, notification.ObjectId);

                if (comment == null)
                {
                    return(null);
                }
                var parentComment = await Get <Comment>(SQLQueries.GetCommentWithId, comment.ParentId);

                var video = await Get <Video>(SQLQueries.GetArchivedStreamsWithId, comment.StreamId);

                if (video == null)
                {
                    return(null);
                }

                using (StreamReader streamReader = new StreamReader(template))
                {
                    reader = streamReader.ReadToEnd();
                    reader = reader.Replace("{Username}", notification.SenderUsername);
                    reader = reader.Replace("{NotificationId}", notification.Id);
                    reader = reader.Replace("{SenderProfilePicture}", notification.SenderProfilePicture);
                    reader = reader.Replace("{ProfileColor}", notification.ProfileColor);
                    reader = reader.Replace("{SenderName}", notification.SenderName.Replace('|', ' '));
                    reader = reader.Replace("{NotificationMessage}", " replied to your comment");
                    reader = reader.Replace("{CommentReply}", comment.Message);
                    reader = reader.Replace("{CommentMessage}", parentComment.Message);
                    reader = reader.Replace("{VideoId}", video.StreamID); //we need to use videos Id rather than streamId becasue we cahnge streaming later it will be hard to manage
                    reader = reader.Replace("{CommentId}", comment.Id);
                    reader = reader.Replace("{NotificationDate}", notification.Date.AddMinutes(MiscHelperMethods.GetOffsetBasedOfTimeZone(userProfile.TimeZone)).ToShortTimeString());
                    reader = reader.Replace("{SenderUsername}", notification.SenderUsername);
                    reader = reader.Replace("{NotificationType}", notification.Type);
                }
            }

            return(reader);
        }
Example #14
0
        public async Task OnGet()
        {
            // List of streams for the carousel
            List <string> streamsWithPriority = new List <string> {
                "F8U3mEscyNB_1",
                "EBRNrFsAqZZ_1",
                "E1OKuVsAi9U_1",
                "EdowSgsAqJV_1",
                "EYd2jUscrUz_1",
                "6SAvwnsAobr_1",
                "ETWYvVscngb_1",
                "F5pYLrscQ5Q_1"
            };

            // List of the IDs of the streams to hardcode in
            List <Video> videosByViews = await storageService.GetList <Video>(SQLQueries.GetArchivedStreamsInDescendingOrderByViews);

            List <Video> videos = new List <Video>();

            foreach (string streamWithPriority in streamsWithPriority) // Add hardcoded streams
            {
                int streamIndex = videosByViews.FindIndex(x => x.StreamID.Equals(streamWithPriority));
                videos.Add(videosByViews[streamIndex]);
                videosByViews.RemoveAt(streamIndex);
            }

            int toAdd = 12 - videos.Count;  // Since Count changes while the loop is running

            for (int i = 0; i < toAdd; i++) // Fill the rest in with streams in order of view count
            {
                videos.Add(videosByViews[i]);
            }

            ArchivedVideos = videos;

            Channel streamingChannel = await storageService.Get <Channel>(SQLQueries.GetAllUserChannelsThatAreStreaming);

            if (streamingChannel == null)
            {
                FeaturedChannel = await storageService.Get <Channel>(SQLQueries.GetUserChannelWithUsername, "juliamkim");

                FeaturedTutor = await storageService.Get <DataModels.Profile>(SQLQueries.GetUserWithUsername, "juliamkim");

                FeaturedArchivedVideo = await storageService.Get <Video>(SQLQueries.GetArchivedStreamsWithUsername, "juliamkim");

                FeaturedArchivedVideo.StreamSubjectIcon = MiscHelperMethods.GetCorrespondingSubjectThumbnail(FeaturedArchivedVideo.StreamSubject);
            }
            else
            {
                FeaturedChannel = streamingChannel;
                FeaturedTutor   = await storageService.Get <Profile>(SQLQueries.GetUserWithUsername, streamingChannel.Username);

                FeaturedChannel.StreamSubjectIcon = MiscHelperMethods.GetCorrespondingSubjectThumbnail(FeaturedChannel.StreamSubject);
            }

            if (cookieService.Authenticated)
            {
                CurrentUserProfile = await cookieService.GetCurrentUser();

                Notifications = await notificationService.GetNotifications(CurrentUserProfile.Username);

                AreThereUnseenNotifications = await notificationService.AreThereUnseenNotifications(CurrentUserProfile.Username);
            }

            ChatInfo = encryptionService.EncryptString(streamingChannel != null ? streamingChannel.ArchivedVideoId : FeaturedArchivedVideo.Id);
        }
Example #15
0
        public async Task <List <Profile> > GetAllFollowees(string followerId)
        {
            var listOfFollowees = await GetList <Follow>(SQLQueries.GetAllFolloweesWithId, new string[] { followerId });

            if (listOfFollowees.Count != 0)
            {
                List <string> idList = new List <string>();
                foreach (var followee in listOfFollowees)
                {
                    idList.Add(followee.FolloweeId);
                }
                return(await GetList <Profile>(SQLQueries.GetAllUsersInTheList, new string[] { MiscHelperMethods.FormatQueryString(idList) }));
            }

            return(null);
        }
Example #16
0
        public async Task <IActionResult> OnGet(string chatId)
        {
            var channel = await storageService.Get <Channel>(SQLQueries.GetUserChannelWithUsername, chatId);

            CurrentUserProfile = await cookieService.GetCurrentUser();

            ChatId   = chatId;
            ChatInfo = channel.ArchivedVideoId ?? "DEFAULT";
            Chats    = await chatService.GetAllChatsWithChatId(ChatId, ChatInfo);

            IsLoggedIn = CurrentUserProfile != null;

            Offset = CurrentUserProfile != null && CurrentUserProfile.TimeZone != null && CurrentUserProfile.TimeZone != "" ? MiscHelperMethods.GetOffsetBasedOfTimeZone(CurrentUserProfile.TimeZone) : -1.0;

            return(Page());
        }
Example #17
0
        public async Task <List <Schedule> > GetSchedule(Profile profile)
        {
            if (profile.TimeZone == null)
            {
                return new List <Schedule> {
                }
            }
            ;

            await Run <Schedule>(SQLQueries.DeletePastScheduledTasks, new string[] { DateTime.UtcNow.AddMinutes(MiscHelperMethods.GetOffsetBasedOfTimeZone(profile.TimeZone)).ToString("yyyy-MM-dd HH:mm") });

            return(await GetList <Schedule>(SQLQueries.GetScheduleWithUserUsername, new string[] { profile.Username, DateTime.UtcNow.AddMinutes(MiscHelperMethods.GetOffsetBasedOfTimeZone(profile.TimeZone)).ToString("yyyy-MM-dd HH:mm") }));
        }
Example #18
0
        public async Task <IActionResult> OnGet(string streamId)
        {
            var stream = await storageService.Get <Video>(SQLQueries.GetArchivedStreamsWithId, streamId);

            Chats = await chatService.GetAllChatsWithChatId(stream.Username, streamId);

            CurrentUserProfile = await cookieService.GetCurrentUser();

            Offset = CurrentUserProfile != null && CurrentUserProfile.TimeZone != null && CurrentUserProfile.TimeZone != "" ? MiscHelperMethods.GetOffsetBasedOfTimeZone(CurrentUserProfile.TimeZone) : -1.0;

            return(Page());
        }
Example #19
0
        public async Task <List <Schedule> > SaveToSchedule(HttpRequest request, string user)
        {
            try
            {
                Schedule schedule    = null;
                var      userProfile = await Get <Profile>(SQLQueries.GetUserWithUsername, new string[] { user });

                var id                = request.Form["Id"]; //for edit
                var streamTitle       = request.Form["StreamTitle"];
                var streamSubject     = request.Form["StreamSubject"];
                var streamDescription = request.Form["StreamDescription"];
                var timeStop          = request.Form["TimeStop"];
                var timeZone          = userProfile.TimeZone;

                var date      = DateTime.ParseExact(request.Form["Date"], "ddd MMM dd yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                var timeStart = DateTime.ParseExact(request.Form["TimeStart"], "h:mm tt", CultureInfo.InvariantCulture);

                DateTime newDate = new DateTime(date.Year, date.Month, date.Day, timeStart.Hour, timeStart.Minute, timeStart.Second);

                var dateNow = DateTime.UtcNow.AddMinutes(MiscHelperMethods.GetOffsetBasedOfTimeZone(timeZone));
                if (newDate < dateNow)
                {
                    return(null);
                }

                if (id.Equals("undefined"))
                {
                    var guid = Guid.NewGuid().ToString();
                    schedule = new Schedule
                    {
                        Id                = guid,
                        Name              = userProfile.Name,
                        Username          = userProfile.Username,
                        StreamTitle       = streamTitle,
                        StreamSubject     = streamSubject,
                        StreamDescription = streamDescription,
                        TimeStart         = timeStart.ToString("h:mm tt"),
                        TimeStop          = timeStop,
                        TimeZone          = timeZone,
                        Date              = newDate,
                        SubjectThumbnail  = MiscHelperMethods.GetCorrespondingSubjectThumbnail(streamSubject)
                    };
                }
                else
                {
                    schedule                   = (await GetList <Schedule>(SQLQueries.GetScheduleWithId, new string[] { id, DateTime.UtcNow.AddMinutes(MiscHelperMethods.GetOffsetBasedOfTimeZone(timeZone)).ToString("yyyy-MM-dd HH:mm") }))[0];
                    schedule.StreamTitle       = streamTitle;
                    schedule.StreamSubject     = streamSubject;
                    schedule.StreamDescription = streamDescription;
                    schedule.TimeStart         = timeStart.ToString("h:mm tt");
                    schedule.TimeStop          = timeStop;
                    schedule.TimeZone          = timeZone;
                    schedule.Date              = newDate;
                    schedule.SubjectThumbnail  = MiscHelperMethods.GetCorrespondingSubjectThumbnail(streamSubject);
                }

                await Save(schedule.Id, schedule);

                return(await GetSchedule(userProfile));
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in ScheduleMethods:AddToSchedule " + e.Message);
                return(null);
            }
        }