Example #1
0
        public void AddNote(Note note, string userId)
        {
            this.validationProvider.Validate(note);

            Video video = this.videoRepository.Table.Where(
                x => (x.VideoId == note.VideoId) &&
                (x.Category.ApplicationUserId == userId)).FirstOrDefault();

            if (video != null)
            {
                this.noteRepository.Insert(note);
                return;
            }

            throw new ValidationException(
                      new List <ValidationResult>()
            {
                new ValidationResult(
                    "user",
                    ValidationExceptionMessages.UserNotAuthenticated(
                        userId,
                        "add note",
                        note.VideoId.ToString()))
            });
        }
        public IEnumerable <Video> SearchByYoutubeId(string id)
        {
            if ((!string.IsNullOrEmpty(id)) && (!string.IsNullOrEmpty(id.Trim())))
            {
                string idToLower = id.ToLower();
                IEnumerable <Video> searchResult = this.videoRepository.Table.Where(video => video.YtId.ToLower().Contains(idToLower)).Take(50).ToList <Video>();
                return(searchResult);
            }

            throw new ValidationException(new List <ValidationResult>()
            {
                new ValidationResult("search", ValidationExceptionMessages.SearchKeyWordsIncorrect(id))
            });
        }
        public IEnumerable <Note> SearchBySharedNotes(string keywords)
        {
            if ((!string.IsNullOrEmpty(keywords)) && (!string.IsNullOrEmpty(keywords.Trim())))
            {
                string             keywordsToLower = keywords.ToLower();
                IEnumerable <Note> searchResult    = this.noteRepository.Table.Where(note => note.Share.Equals(true) &&
                                                                                     (note.Title.ToLower().Contains(keywordsToLower) ||
                                                                                      note.Content.ToLower().Contains(keywordsToLower))).Take(50).ToList <Note>();
                return(searchResult);
            }

            throw new ValidationException(new List <ValidationResult>()
            {
                new ValidationResult("search", ValidationExceptionMessages.SearchKeyWordsIncorrect(keywords))
            });
        }
        public IEnumerable <Video> SearchByAllVideoTitles(string keywords)
        {
            if (
                (!string.IsNullOrEmpty(keywords)) &&
                (!string.IsNullOrEmpty(keywords.Trim())))
            {
                string keywordsToLower           = keywords.ToLower();
                IEnumerable <Video> searchResult = this.videoRepository.Table.Where(video => video.Title.ToLower().Contains(keywordsToLower)).Take(50).ToList <Video>();
                return(searchResult);
            }

            throw new ValidationException(new List <ValidationResult>()
            {
                new ValidationResult("search", ValidationExceptionMessages.SearchKeyWordsIncorrect(keywords))
            });
        }
        public IEnumerable <Note> SearchByUserNotes(string keywords, string userId)
        {
            if ((!string.IsNullOrEmpty(keywords)) && (!string.IsNullOrEmpty(keywords.Trim())))
            {
                string             keywordsToLower = keywords.ToLower();
                IEnumerable <Note> searchResult    = this.noteRepository.Table.Where(note =>
                                                                                     (note.Title.ToLower().Contains(keywordsToLower) ||
                                                                                      note.Content.ToLower().Contains(keywordsToLower)) &&
                                                                                     (note.Video.Category.ApplicationUserId == userId)).Take(50).ToList <Note>();
                return(searchResult);
            }

            throw new ValidationException(new List <ValidationResult>()
            {
                new ValidationResult("search", ValidationExceptionMessages.SearchKeyWordsIncorrect(keywords))
            });
        }
        public void AddVideo(Video video, string userId)
        {
            this.validationProvider.Validate(video);
            Category category = this.categoryRepository.GetById(video.CategoryId);

            if (category != null && category.ApplicationUserId == userId)
            {
                this.videoRepository.Insert(video);
                return;
            }
            else
            {
                throw new ValidationException(new List <ValidationResult>()
                {
                    new ValidationResult("user", ValidationExceptionMessages.UserNotAuthenticated(userId, "add video", "0"))
                });
            }
        }
Example #7
0
        public void DeleteCategoryById(string categoryId, string userId)
        {
            int      k        = int.Parse(categoryId);
            Category category = this.categoryRepository.GetById(k);

            if (category != null && category.ApplicationUserId == userId)
            {
                this.categoryRepository.Delete(category);
                return;
            }
            else
            {
                throw new ValidationException(new List <ValidationResult>()
                {
                    new ValidationResult("user", ValidationExceptionMessages.UserNotAuthenticated(userId, "delete category", categoryId))
                });
            }
        }
Example #8
0
        public IQueryable <Note> GetNotesFor(int videoId, string userId)
        {
            Video video = this.videoRepository.GetById(videoId);

            if (video != null)
            {
                Category category = this.categoryRepository.GetById(video.CategoryId);

                if (category.ApplicationUserId == userId)
                {
                    return(this.noteRepository.Table.Where(x => x.VideoId == videoId));
                }
            }

            throw new ValidationException(new List <ValidationResult>()
            {
                new ValidationResult("user", ValidationExceptionMessages.UserNotAuthenticated(userId, "get notes", videoId.ToString()))
            });
        }
        public Video DeleteVideoById(string videoId, string userId)
        {
            int   k     = int.Parse(videoId);
            Video video = this.videoRepository.GetById(k);

            if (video != null)
            {
                Category category = this.categoryRepository.GetById(video.CategoryId);
                if (category.ApplicationUserId == userId)
                {
                    this.videoRepository.Delete(video);
                    return(video);
                }
            }

            throw new ValidationException(new List <ValidationResult>()
            {
                new ValidationResult("user", ValidationExceptionMessages.UserNotAuthenticated(userId, "delete video", videoId))
            });
        }
Example #10
0
        public Note DeleteNoteById(string noteId, string userId)
        {
            int k = int.Parse(noteId);

            Note note = this.noteRepository.GetById(k);

            if (note != null)
            {
                Video    video    = this.videoRepository.GetById(note.VideoId);
                Category category = this.categoryRepository.GetById(video.CategoryId);
                if (category.ApplicationUserId == userId)
                {
                    this.noteRepository.Delete(note);
                    return(note);
                }
            }

            throw new ValidationException(new List <ValidationResult>()
            {
                new ValidationResult("user", ValidationExceptionMessages.UserNotAuthenticated(userId, "delete note", noteId))
            });
        }