Ejemplo n.º 1
0
        public void DeleteNews(News news)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var newsEntity = from item in context.News
                                 where item.NewsID == news.NewsID
                                 select item;

                News entity = newsEntity.SingleOrDefault();

                if (entity != null)
                {
                    context.DeleteObject(entity);
                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
        public string DeleteFile(File file)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var files = from item in context.Files
                            where item.FileID == file.FileID
                            select item;

                File entity = files.FirstOrDefault();

                if ((entity != null))
                {
                    context.DeleteObject(entity);
                    context.SaveChanges();
                }
                return entity.FileName;
            }
        }
Ejemplo n.º 3
0
        public bool ValidatePermission(int userID)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var data = (from user in context.Users
                            where user.UserID == userID
                            && user.IsEnabled == true
                            select user).ToList();
                if (data.Count != 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }

            }
        }
Ejemplo n.º 4
0
        public void UpdateUser(User user)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var users = from item in context.Users
                            where item.UserID == user.UserID
                            select item;

                User entity = users.SingleOrDefault();

                if (entity != null)
                {
                    entity.Name = user.Name;
                    entity.Password = Cryptography.EncryptData(user.Password, saltKeyword);
                    entity.Login = user.Login;
                    entity.IsEnabled = user.IsEnabled;

                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 5
0
        public void UpdateNews(News news)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var newsList = from item in context.News
                               where item.NewsID == news.NewsID
                               select item;

                News entity = newsList.SingleOrDefault();

                if (entity != null)
                {
                    entity.Title = news.Title;
                    entity.Text = news.Text;
                    entity.IsEnabled = news.IsEnabled;

                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 6
0
        public void UpdateFile(File file)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var files = from item in context.Files
                            where item.FileID == file.FileID
                            select item;

                File entity = files.FirstOrDefault();

                if ((entity != null))
                {
                    entity.SubTypeID = file.SubTypeID;
                    entity.IsEnabled = file.IsEnabled;

                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 7
0
        public User SelectUserToLogin(string login, string pwd)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                User user = (from item in context.Users
                             where item.Login == login
                             && item.IsEnabled == true
                             select item).FirstOrDefault();

                if (user != null)
                {
                    string spwd2 = Cryptography.EncryptData(pwd, saltKeyword);
                    string pwd2 = Cryptography.DecryptData(user.Password, saltKeyword);
                    if (pwd == pwd2)
                        return user;
                    else
                        return null;
                }
                else
                    return null;
            }
        }
Ejemplo n.º 8
0
        public List<User> SelectUser(int? userID, string name, bool? isEnabled)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var result = from item in context.Users
                             where (item.UserID == userID || userID == null)
                             && (item.Name == name || name == null)
                             && (item.IsEnabled == isEnabled || isEnabled == null)
                             orderby item.Name
                             select item;
                foreach (var item in result)
                {
                    //TODO: is necessary?
                    item.Password = Cryptography.DecryptData(item.Password, saltKeyword);
                }

                return result.ToList();
            }
        }
Ejemplo n.º 9
0
 public void InsertFile(File file)
 {
     using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
     {
         context.AddToFiles(file);
         context.SaveChanges();
     }
 }
Ejemplo n.º 10
0
        public List<Parameter> SelectParameter(int? parameterID, string name)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var result = from p in context.Parameters
                             where (p.ParameterID == parameterID || parameterID == null)
                             && (p.Name == name || name == null)
                             orderby p.Name
                             select p;

                return result.ToList();
            }
        }
Ejemplo n.º 11
0
        public News SelectNewsFrontEnd()
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var result = from item in context.News
                             where item.IsEnabled == true
                             orderby item.CreateDate descending
                             select item;

                return result.FirstOrDefault();
            }
        }
Ejemplo n.º 12
0
        public List<News> SelectNews(int? newsID, string title, bool? isEnabled)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var result = from item in context.News
                             where (item.NewsID == newsID || newsID == null)
                             && (item.Title == title || title == null)
                             && (item.IsEnabled == isEnabled || isEnabled == null)
                             orderby item.CreateDate descending
                             select item;

                return result.ToList();
            }
        }
Ejemplo n.º 13
0
        public List<File> SelectFileFiltered(int? userID, int? typeID, int? subTypeID, String name, System.DateTime? initialDate, System.DateTime? finalDate)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var result = from p in context.Files
                             where (p.User.UserID == userID || userID == null)
                             && (p.SubType.Type.TypeID == typeID || typeID == null)
                             && (p.SubType.SubTypeID == subTypeID || subTypeID == null)
                             && (p.Created >= initialDate || initialDate == null)
                             && (p.Created <= finalDate || finalDate == null)
                             && (p.FileName.Contains(name) || name == null)
                             && (p.IsEnabled == true)
                             orderby p.Created descending
                             select p;

                foreach (var item in result)
                {
                    item.UserReference.Load();
                    item.SubTypeReference.Load();
                    item.SubType.TypeReference.Load();
                }

                return result.ToList();
            }
        }
Ejemplo n.º 14
0
        public List<File> SelectFile(int? fileID, int? userID, int? typeID, int? subTypeID, string name, bool? isEnabled)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var result = from p in context.Files
                             where (p.FileID == fileID || fileID == null)
                             && (p.User.UserID == userID || userID == null)
                             && (p.SubType.SubTypeID == subTypeID || subTypeID == null)
                             && (p.SubType.Type.TypeID == typeID || typeID == null)
                             && (p.FileName == name || name == null)
                             && (p.IsEnabled == isEnabled || isEnabled == null)
                             orderby p.Created descending
                             select p;

                foreach (var item in result)
                {
                    item.UserReference.Load();
                    item.SubTypeReference.Load();
                    item.SubType.TypeReference.Load();
                }

                return result.ToList();
            }
        }
Ejemplo n.º 15
0
 public void InsertUser(User user)
 {
     using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
     {
         user.Password = Cryptography.EncryptData(user.Password, saltKeyword);
         context.AddToUsers(user);
         context.SaveChanges();
     }
 }
Ejemplo n.º 16
0
 public void InsertNews(News news)
 {
     using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
     {
         news.CreateDate = DateTime.Now;
         context.AddToNews(news);
         context.SaveChanges();
     }
 }
Ejemplo n.º 17
0
        public List<Entities.Type> SelectType(int? typeID, string name, bool? isEnabled)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var result = from p in context.Types
                             where (p.TypeID == typeID || typeID == null)
                             && (p.Name == name || name == null)
                             && (p.IsEnabled == isEnabled || isEnabled == null)
                             orderby p.Name
                             select p;

                foreach (var item in result)
                {
                    item.SubTypes.Load();
                }

                return result.ToList();
            }
        }
Ejemplo n.º 18
0
        public void DeleteUser(User user)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var users = from item in context.Users
                            where item.UserID == user.UserID
                            select item;

                User entity = users.SingleOrDefault();

                if (entity != null)
                {
                    context.DeleteObject(entity);
                    context.SaveChanges();
                }
            }
        }