Пример #1
0
 public void BulkInsert(List <TEntity> entities)
 {
     using (var db = new NewPlayDbContext()){
         db.AddRange(entities);
         db.SaveChanges();
     };
 }
Пример #2
0
 public void Remove(TEntity entity)
 {
     using (var db = new NewPlayDbContext()){
         db.Remove(entity);
         db.SaveChanges();
     };
 }
Пример #3
0
        public List <Game> GetGamesByUserId(string userId)
        {
            using (var db = new NewPlayDbContext()){
                var games = (from _games in db.Game
                             join gameGenre in db.GameGenre on _games.Id equals gameGenre.GameId
                             join gamePlatf in db.GamePlatform on _games.Id equals gamePlatf.GameId
                             join userGenre in db.UserGenre on gameGenre.GenreId equals userGenre.GenreId
                             join userPlatf in db.UserPlatform on gamePlatf.PlatformId equals userPlatf.PlatformId
                             where userPlatf.UserId == userId && userGenre.UserId == userId &&
                             db.UserGame.Where(ug => ug.GameId == _games.Id).First() == null
                             select _games).ToList();

                return(games);
            }
        }
Пример #4
0
        public object FilterBy(string id, DateTime?startDate,
                               DateTime?finishDate, bool?active, string accessType)
        {
            using (var db = new NewPlayDbContext()){
                var users = db.User.ToList();
                Predicate <User> match = null;

                if (!string.IsNullOrEmpty(id))
                {
                    match = (u => u.Id == id);
                }

                if (!string.IsNullOrEmpty(accessType))
                {
                    match = (u => u.Role == accessType);
                }

                if (startDate != null && finishDate != null)
                {
                    finishDate = Convert.ToDateTime(finishDate)
                                 .AddHours(23).AddMinutes(59).AddSeconds(59);

                    match = (u => u.CreationDate >= startDate &&
                             u.CreationDate <= finishDate);
                }

                if (active != null)
                {
                    if (active == true)
                    {
                        match = (u => u.DisableDate == null);
                    }
                    else
                    {
                        match = (u => u.DisableDate != null);
                    }
                }

                return(users.FindAll(match));
            }
        }
Пример #5
0
        public object GetAssociatedGamesPlatformAndGenres(string id)
        {
            using (var db = new NewPlayDbContext()){
                var user = (from users in db.User
                            // join userGame in db.UserGame on users.Id equals userGame.UserId
                            // join games in db.Game on userGame.GameId equals games.Id
                            join userGenre in db.UserGenre on users.Id equals userGenre.UserId
                            join genres in db.Genre on userGenre.GenreId equals genres.Id
                            join userPlatform in db.UserPlatform on users.Id equals userPlatform.UserId
                            join platform in db.Platform on userPlatform.PlatformId equals platform.Id
                            where users.Id == id
                            select users).FirstOrDefault();

                var _games = (from userGame in db.UserGame
                              join games in db.Game on userGame.GameId equals games.Id
                              where userGame.UserId == user.Id
                              select games).ToList();

                var _genres = (from userGenre in db.UserGenre
                               join genres in db.Genre on userGenre.GenreId equals genres.Id
                               where userGenre.UserId == user.Id
                               select genres).ToList();

                var _platforms = (from userPlatform in db.UserPlatform
                                  join platform in db.Platform on userPlatform.PlatformId equals platform.Id
                                  where userPlatform.UserId == user.Id
                                  select platform).ToList();

                return(new {
                    user.Nickname,
                    user.Email,
                    user.Avatar,
                    user.CreationDate,
                    user.Description,
                    _games,
                    _genres,
                    _platforms
                });
            }
        }
Пример #6
0
        public object FilterBy(string id, DateTime?startDate,
                               DateTime?finishDate, bool?active)
        {
            using (var db = new NewPlayDbContext()){
                var games = db.Game.ToList();
                Predicate <Game> match = null;

                if (!string.IsNullOrEmpty(id))
                {
                    match = (e => e.Id == id);
                }

                if (startDate != null && finishDate != null)
                {
                    finishDate = Convert.ToDateTime(finishDate)
                                 .AddHours(23).AddMinutes(59).AddSeconds(59);

                    match = (e => e.CreationDate >= startDate &&
                             e.CreationDate <= finishDate);
                }

                if (active != null)
                {
                    if (active == true)
                    {
                        match = (e => e.DisableDate == null);
                    }
                    else
                    {
                        match = (e => e.DisableDate != null);
                    }
                }

                return(games.FindAll(match));
            }
        }
        public object FilterBy(int?id, DateTime?startDate,
                               DateTime?finishDate, bool?active)
        {
            using (var db = new NewPlayDbContext()){
                var developers = db.Developer.ToList();
                Predicate <Developer> match = null;

                if (id != null)
                {
                    match = (e => e.Id == id);
                }

                if (startDate != null && finishDate != null)
                {
                    finishDate = Convert.ToDateTime(finishDate)
                                 .AddHours(23).AddMinutes(59).AddSeconds(59);

                    match = (e => e.CreationDate >= startDate &&
                             e.CreationDate <= finishDate);
                }

                if (active != null)
                {
                    if (active == true)
                    {
                        match = (e => e.DisableDate == null);
                    }
                    else
                    {
                        match = (e => e.DisableDate != null);
                    }
                }

                return(developers.FindAll(match));
            }
        }
Пример #8
0
        // public object FilterBy(string key, object value){

        //     using(var db = new NewPlayDbContext()){
        //        //Type type = db.Set<TEntity>().GetType();

        //        //var prop = db.Set<TEntity>().GetType().GetProperty(key).GetValue(db.Set<TEntity>().GetType());
        //        //var _value = prop.GetValue(db.Set<TEntity>());
        //     //    return db.Set<typeof(TEntity)>().ToList()
        //     //             .FindAll(e =>
        //     //             e.GetType()
        //     //             .get(key)
        //     //             .GetValue(e)
        //     //             == value);
        //     };
        //     return null;
        // }

        public IEnumerable <TEntity> GetAll()
        {
            using (var db = new NewPlayDbContext()){
                return(db.Set <TEntity>().ToList());
            };
        }
Пример #9
0
 public TEntity GetById(params object[] key)
 {
     using (var db = new NewPlayDbContext()){
         return(db.Set <TEntity>().Find(key));
     };
 }