Inheritance: DbContext
 public static VideoListItem GetVideo(Guid videoId) {
     using (Entities context = new Entities()) {
         var Query = context.Media.Where(v => v.MediaId == videoId);
         var Result = QueryVideoListItem(Query, null);
         return Result.FirstOrDefault();
     }
 }
示例#2
0
 public static Dbo.Comment Get(long commentId)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_Comment
                         .Where(cmmnt => cmmnt.Id == commentId)
                         .Select(c => new Dbo.Comment()
                         {
                             Id = c.Id,
                             UserId = c.UserId,
                             ArticleId = c.ArticleId,
                             Content = c.Comment,
                             CreationDate = c.CreationDate
                         })
                         .FirstOrDefault();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }
        //public static Version GetVersionInfo() {
        //    using (Entities context = new Entities()) {
        //        DbVersion Result = context.DbVersions.Single();
        //        return new Version(Result.Major, Result.Minor, Result.Build, Result.Revision);
        //    }
        //}

        public static Version GetVersionInfo() {
            using (Entities context = new Entities()) {
                // We must query manually because querying entity objects would fail on outdated databases.
                DbVersion Result = context.Database.SqlQuery<DbVersion>("SELECT Major, Minor, Build, Revision FROM Version").FirstOrDefault();
                return new Version(Result.Major, Result.Minor, Result.Build, Result.Revision);
            }
        }
        /// <summary>
        /// Inserts specified media into the database, or updates an existing entry.
        /// </summary>
        /// <param name="item">The media item to merge into the database.</param>
        /// <param name="context">The database context.</param>
        public static void InsertOrMerge(Media item, Entities context) {
            // Try to find matching element already within the database.
            List<Media> DbMatch = (from m in context.Media
                                         where m.MediaId == item.MediaId || (m.Artist == item.Artist && m.Title == item.Title)
                                         select m).ToList();
            Media DbItem;
            if (DbMatch.Count > 1) // If both matches happen simultaneously, Artist/Title must take priority to avoid creating duplicate.
                DbItem = DbMatch.Single(m => m.Artist == item.Artist && m.Title == item.Title);
            else
                DbItem = DbMatch.FirstOrDefault();

            // If merging, delete existing entry and we'll create a new one and merge the fields.
            if (DbItem != null)
                context.Media.Remove(DbItem);

            // Insert new data.
            context.Media.Add(item);

            // Merge fields.
            if (DbItem != null) {
                item.FileName = DbItem.FileName;
                item.MediaId = DbItem.MediaId; // If matching by Artist/Title, we keep the same ID to avoid creating duplicate ID.
            }

            // Commit changes.
            context.SaveChanges();
        }
 public static Media GetVideoByFileName(string fileName) {
     using (Entities context = new Entities()) {
         Media Result = (from v in context.Media.Include("MediaRatings.RatingCategory")
                         where v.FileName == fileName
                         select v).FirstOrDefault();
         return Result;
     }
 }
 public static Media GetVideoByTitle(string artist, string title) {
     using (Entities context = new Entities()) {
         Media Result = (from v in context.Media.Include("MediaRatings.RatingCategory")
                         where v.Artist == artist && v.Title == title
                         select v).FirstOrDefault();
         return Result;
     }
 }
 public static Media GetVideoById(Guid videoId) {
     using (Entities context = new Entities()) {
         Media Result = (from v in context.Media.Include("MediaRatings.RatingCategory")
                         where v.MediaId == videoId
                         select v).FirstOrDefault();
         return Result;
     }
 }
 public static int GetMediaCount(MediaType mediaType, RatingCategory ratingCategory, float[] minMax, double ratio) {
     using (Entities context = new Entities()) {
         if (ratingCategory.Name != "Intensity")
             return GetMediaQuery(context, mediaType, ratingCategory, minMax[0], minMax[1], ratio).Count();
         else
             return GetIntensityQuery(context, mediaType, ratingCategory, minMax[0], minMax[1], ratio).Count();
     }
 }
 public static List<RatingCategory> GetCustomRatingCategories() {
     using (Entities context = new Entities()) {
         var Query = (from c in context.RatingCategories
                      where c.Custom
                      orderby c.Name
                      select c);
         return Query.ToList();
     }
 }
 public static List<string> GetAllFileNames() {
     using (Entities context = new Entities()) {
         var Query = (from v in context.Media
                      where v.FileName != null
                      orderby v.FileName
                      select v.FileName);
         return Query.ToList();
     }
 }
 public static void UpdateVersionInfo(Version version) {
     using (Entities context = new Entities()) {
         DbVersion Row = context.DbVersions.Single();
         Row.Major = version.Major;
         Row.Minor = version.Minor;
         Row.Build = version.Build;
         Row.Revision = version.Revision;
         context.SaveChanges();
     }
 }
 public static List<Media> GetMediaListById(List<Guid> exportList) {
     using (Entities context = new Entities()) {
         var MediaData = (from v in context.Media
                             .Include(t => t.MediaRatings.Select(r => r.RatingCategory))
                             .Include(t => t.MediaCategory)
                          where exportList.Contains(v.MediaId)
                          orderby v.Artist, v.Title
                          select v).ToList();
         return MediaData;
     }
 }
 public static IQueryable<Media> GetMediaQuery(Entities context, MediaType mediaType, RatingCategory ratingCategory, double min, double max, double ratio) {
     var Query = (from m in context.Media
                  let val = (from r in m.MediaRatings
                             where r.RatingCategory.Name == ratingCategory.Name
                             select r.DbGetValue(r.Height, r.Depth, ratio)).FirstOrDefault()
                  where (mediaType == MediaType.None || m.MediaTypeId == (int)mediaType) &&
                     val != null && val > min && val <= max
                  orderby m.Artist, m.Title
                  select m);
     return Query;
 }
 public static IQueryable<Media> GetIntensityQuery(Entities context, MediaType mediaType, RatingCategory ratingCategory, double min, double max, double ratio) {
     var Query = (from m in context.Media
                      let val = (from r in m.MediaRatings
                                 let val = r.DbGetValue(r.Height, r.Depth, ratio)
                                 orderby val descending
                                 select val).Take(5).Average()
                  where (mediaType == MediaType.None || m.MediaTypeId == (int)mediaType) &&
                     val > min && val <= max
                  orderby m.Artist, m.Title
                  select m);
     return Query;
 }
 /// <summary>
 /// Returns the list of elements.
 /// </summary>
 /// <returns>A list of SearchCategoryItem objects.</returns>
 public static List<SearchCategoryItem> GetCategoryElements(SearchSettings settings) {
     using (Entities context = new Entities()) {
         var Query = (from c in context.RatingCategories
                      where (settings.Search == "" || c.Name.Contains(settings.Search))
                      orderby c.Name
                      select new SearchCategoryItem() {
                          FilterType = SearchFilterEnum.Element,
                          FilterValue = c.Name,
                          Text = c.Name
                      });
         return Query.ToList();
     }
 }
示例#16
0
        public static void CreateAndAddTags(T_Article article, List<T_Tag> tags)
        {
            try
            {
                using (Entities bdd = new Entities())
                {
                    using (TransactionScope scope = new TransactionScope())
                    {

                        bdd.T_Article.Add(article);
                        bdd.SaveChanges();

                        foreach (T_Tag tag in tags)
                        {
                            T_Tag oldTag = bdd.T_Tag.Where(tg => tg.Name == tag.Name).FirstOrDefault();
                            if (oldTag == null)
                            {
                                bdd.T_Tag.Add(tag);
                                bdd.SaveChanges();
                                T_ArticleTag at = new T_ArticleTag()
                                {
                                    ArticleId = article.Id,
                                    TagId = tag.Id
                                };
                                bdd.T_ArticleTag.Add(at);
                                bdd.SaveChanges();
                            }
                            else
                            {
                                T_ArticleTag at = new T_ArticleTag()
                                {
                                    ArticleId = article.Id,
                                    TagId = oldTag.Id
                                };
                                bdd.T_ArticleTag.Add(at);
                                bdd.SaveChanges();
                            }
                        }

                        scope.Complete();
                    }
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message);
                throw;
            }
        }
示例#17
0
 public static List<T_Blog> SearchByTheme(string theme)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_Blog.Include("T_Theme").Where(blg => blg.T_Theme.Description.Equals(theme)).ToList();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         return new List<T_Blog>();
     }
 }
示例#18
0
 public static T_Blog Get(long blogId)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_Blog.Where(bl => bl.Id == blogId).FirstOrDefault();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }
示例#19
0
 public static T_Blog Get(string login, string blogName)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_Blog.Include("T_User").Where(bl => bl.T_User.Login == login && bl.Name == blogName).FirstOrDefault();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }
示例#20
0
 public static T_Tag GetByName(string name)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_Tag.Where(tg => tg.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }
示例#21
0
 public static List<T_Blog> SearchBlogFromUser(long userId)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_Blog.Include("T_User").Where(blg => blg.T_User.Id == userId).ToList();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         return new List<T_Blog>();
     }
 }
示例#22
0
 public static T_MediaType Get(long mediaTypeId)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_MediaType.Where(mdType => mdType.Id == mediaTypeId).FirstOrDefault();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }
示例#23
0
 public static T_Style GetDefault()
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_Style.FirstOrDefault();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }
示例#24
0
 public static bool DoesLoginExists(string login)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_User.Where(usr => usr.Login == login).FirstOrDefault() != null;
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }
示例#25
0
 public static T_Theme Get(long themeId)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_Theme.Where(thm => thm.Id == themeId).FirstOrDefault();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }
示例#26
0
 public static T_ArticleTag Get(long articleTagId)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_ArticleTag.Where(art => art.Id == articleTagId).FirstOrDefault();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }
示例#27
0
 public static List<T_Theme> GetAll()
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_Theme.ToList();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }
示例#28
0
 public static T_Follow Get(long followId)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_Follow.Where(fllw => fllw.Id == followId).FirstOrDefault();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }
示例#29
0
 public static T_Style Get(long styleId)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_Style.Where(stl => stl.Id == styleId).FirstOrDefault();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }
示例#30
0
 public static T_User Get(long userId)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             return bdd.T_User.Where(usr => usr.Id == userId).FirstOrDefault();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }