/// <summary> /// Конструктор /// </summary> /// <param name="video">данные о видео</param> internal VideoForUser(Data.Video.Video video) : this(video.Title, video.HtmlCode) { Id = video.Id; HasImage = EnumerableValidator.IsNotNullAndNotEmpty(video.Image); SortInfo = new SortInfo(video); }
public VideoForUser Get(string title) { VideoForUser videoForUser = Adapter.ReadByContext(c => { Data.Video.Video video = GetByTitle(title); if (video == null) { return(null); } long videoId = video.Id; IOrderedQueryable <VideoSentence> videosQuery = (from vs in c.VideoSentence where vs.VideoId == videoId orderby vs.Order select vs); var innerResult = new VideoForUser(video); foreach (VideoSentence videoSentence in videosQuery.ToList()) { innerResult.Sentences.Add(new Tuple <string, string>(videoSentence.Source, videoSentence.Translation)); } return(innerResult); }); return(videoForUser); }
private Data.Video.Video GetOrCreateVideo(VideoForUser videoForUser, byte[] image, int?rating, byte videoType, StudyLanguageContext c) { string title = videoForUser.Title; string htmlCode = videoForUser.HtmlCode; Data.Video.Video video = c.Video.FirstOrDefault( e => (e.Title == title || e.HtmlCode == htmlCode) && e.LanguageId == _languageId && e.Type == videoType); if (video == null) { video = new Data.Video.Video { IsVisible = true, Rating = rating, LanguageId = _languageId, Type = videoType }; c.Video.Add(video); } video.Title = title; video.HtmlCode = htmlCode; video.Image = image; video.LastModified = DateTime.Now; c.SaveChanges(); return(video); }
private Data.Video.Video GetByTitle(string title) { Data.Video.Video result = Adapter.ReadByContext(c => { IQueryable <Data.Video.Video> videosQuery = (from v in c.Video where v.Title == title && v.IsVisible && v.LanguageId == _languageId select v); return(videosQuery.AsEnumerable().FirstOrDefault()); }); return(result); }
public VideoForUser GetOrCreate(VideoType type, VideoForUser videoForUser, byte[] image, int?rating) { if (EnumValidator.IsInvalid(type) || videoForUser == null || string.IsNullOrWhiteSpace(videoForUser.Title) || string.IsNullOrWhiteSpace(videoForUser.HtmlCode) /*|| EnumerableValidator.IsNullOrEmpty(videoForUser.Sentences)*/) { return(null); } byte parsedVideoType = (byte)type; VideoForUser result = null; Adapter.ActionByContext(c => { Data.Video.Video video = GetOrCreateVideo(videoForUser, image, rating, parsedVideoType, c); long videoId = video.Id; if (IdValidator.IsInvalid(videoId)) { return; } DeleteVideoSentences(c, videoId); result = new VideoForUser(video); int order = 1; foreach (var sentence in videoForUser.Sentences) { var videoSentence = new VideoSentence { VideoId = videoId, Source = sentence.Item1, Translation = sentence.Item2, Order = order++ }; c.VideoSentence.Add(videoSentence); } c.SaveChanges(); }); return(result); }
internal SortInfo(Data.Video.Video video) { LastModified = video.LastModified; Rating = video.Rating ?? DEFAULT_RATING; Name = video.Title; }
public byte[] GetImage(string title) { Data.Video.Video video = GetByTitle(title); return(video != null ? video.Image : null); }