public Users GetUser(int id)
 {
     using (var context = new TranslatorHistoryDatabaseEntities())
     {
         return context.Users.FirstOrDefault(user => user.Id == id);
     }
 }
 public List<History> GetAllHistory(int userId)
 {
     using (var context = new TranslatorHistoryDatabaseEntities())
     {
         return context.History.Where(c => c.UserId == userId).ToList();
     }
 }
        //private readonly string connectionString;

        //public SqlUserssRepositary(string connectionString)
        //{
        //    this.connectionString = connectionString;
        //}

        public List<Users> GetAllUsers()
        {
            using (var context = new TranslatorHistoryDatabaseEntities())
            {
                return context.Users.ToList();
            }
        }
 public void DeleteUser(int userId)
 {
     using (var context = new TranslatorHistoryDatabaseEntities())
     {
         context.Users.Remove(context.Users.FirstOrDefault(u => u.Id == userId));
         context.SaveChanges();
     }
 }
 public int Add(History item)
 {
     using (var context = new TranslatorHistoryDatabaseEntities())
     {
         context.History.Add(item);
         context.SaveChanges();
         return item.Id;
     }
 }
 public int AddUser(Users user)
 {
     using (var context = new TranslatorHistoryDatabaseEntities())
     {
         context.Users.Add(user);
         context.SaveChanges();
         return user.Id;
     }
 }
        public List<History> GetLastHistoryEntries(int userId, int lastCount)
        {
            using (var context = new TranslatorHistoryDatabaseEntities())
            {
                int count = context.History.Count(c => c.UserId == userId);

                var history = context.History.Where(c => c.UserId == userId);

                return count <= lastCount ? history.ToList() : history.OrderBy(c => c.Id).Skip(count - lastCount).ToList();
            }
        }
        public void BanUser(int userId)
        {
            using (var context = new TranslatorHistoryDatabaseEntities())
            {
                var user = context.Users.FirstOrDefault(u => u.Id == userId);
                if (user == null) return;

                user.Disabled = !user.Disabled;
                context.SaveChanges();
            }
        }
        public void UpdateUser(Users obj)
        {
            using (var context = new TranslatorHistoryDatabaseEntities())
            {
                var user = context.Users.First(u => u.Id == obj.Id);
                user.Email = obj.Email;
                user.Firstname = obj.Firstname;
                user.Lastname = obj.Lastname;

                context.SaveChanges();
            }
        }
        public List<History> GetHistory(int userId, int page, int itemsPerPage)
        {
            // TODO: реалізувати метод GetHistory, який приймає номер сторінки і к-сть записів на одну сторінку
            return GetAllHistory(userId);

            using (var context = new TranslatorHistoryDatabaseEntities())
            {
                return context.History.Where(c => c.UserId == userId).ToList()
                    //.OrderByDescending(c => c.Time)
                    .Skip(Math.Max(0, context.History.Count() - page * itemsPerPage))
                    .Take(itemsPerPage)
                    .ToList();
            }
        }
 public bool DoesUserExist(string login, string password)
 {
     using (var context = new TranslatorHistoryDatabaseEntities())
     {
         return (context.Users.Any(u => u.Login == login && u.Password == password));
     }
 }
 public Users CheckUser(string login, string password)
 {
     using (var context = new TranslatorHistoryDatabaseEntities())
     {
         return (context.Users.FirstOrDefault(u => u.Login == login && u.Password == password));
     }
 }
 public Users GetUserByLogin(string login)
 {
     using (var context = new TranslatorHistoryDatabaseEntities())
     {
         return (context.Users.FirstOrDefault(u => u.Login == login));
     }
 }