Ejemplo n.º 1
0
 public void Insert(UserBindingModel model)
 {
     using (var context = new NewsBlogDatabase())
     {
         context.Users.Add(CreateModel(model, new Users()));
         context.SaveChanges();
     }
 }
Ejemplo n.º 2
0
 public void Insert(CategoryBindingModel model)
 {
     using (var context = new NewsBlogDatabase())
     {
         context.Categories.Add(CreateModel(model, new Categories()));
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public List <CategoryViewModel> GetFullList()
 {
     using (var context = new NewsBlogDatabase())
     {
         return(context.Categories
                .Select(rec => new CategoryViewModel
         {
             Id = rec.Idtheme,
             NameTheme = rec.Nametheme
         }).ToList());
     }
 }
Ejemplo n.º 4
0
 public List <RoleViewModel> GetFullList()
 {
     using (var context = new NewsBlogDatabase())
     {
         return(context.Role
                .Select(rec => new RoleViewModel
         {
             Id = rec.Idrole,
             NameRole = rec.Namerole
         }).ToList());
     }
 }
Ejemplo n.º 5
0
 public void Update(RoleBindingModel model)
 {
     using (var context = new NewsBlogDatabase())
     {
         var role = context.Role.FirstOrDefault(rec => rec.Idrole == model.Id);
         if (role == null)
         {
             throw new Exception("Роль не найдена");
         }
         CreateModel(model, role);
         context.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 public void Update(UserBindingModel model)
 {
     using (var context = new NewsBlogDatabase())
     {
         var user = context.Users.FirstOrDefault(rec => rec.Iduser == model.Id);
         if (user == null)
         {
             throw new Exception("Пользователь не найден");
         }
         CreateModel(model, user);
         context.SaveChanges();
     }
 }
Ejemplo n.º 7
0
 public void Update(CommentBindingModel model)
 {
     using (var context = new NewsBlogDatabase())
     {
         var comment = context.Comments.FirstOrDefault(rec => rec.Idcomment == model.Id);
         if (comment == null)
         {
             throw new Exception("Комментарий не найден");
         }
         CreateModel(model, comment);
         context.SaveChanges();
     }
 }
Ejemplo n.º 8
0
 public void Update(CategoryBindingModel model)
 {
     using (var context = new NewsBlogDatabase())
     {
         var category = context.Categories.FirstOrDefault(rec => rec.Idtheme == model.Id);
         if (category == null)
         {
             throw new Exception("Категория не найдена");
         }
         CreateModel(model, category);
         context.SaveChanges();
     }
 }
Ejemplo n.º 9
0
 public void Update(ArticleBindingModel model)
 {
     using (var context = new NewsBlogDatabase())
     {
         var article = context.Articles.FirstOrDefault(rec => rec.Idarticle == model.Id);
         if (article == null)
         {
             throw new Exception("Статья не найдена");
         }
         CreateModel(model, article);
         context.SaveChanges();
     }
 }
Ejemplo n.º 10
0
 public List <UserViewModel> GetFullList()
 {
     using (var context = new NewsBlogDatabase())
     {
         return(context.Users
                .Include(rec => rec.IdroleNavigation)
                .Select(rec => new UserViewModel
         {
             Id = rec.Iduser,
             Nickname = rec.Nickname,
             RoleId = rec.Idrole
         }).ToList());
     }
 }
Ejemplo n.º 11
0
 public void Delete(ArticleBindingModel model)
 {
     using (var context = new NewsBlogDatabase())
     {
         Articles article = context.Articles.FirstOrDefault(rec => rec.Idarticle == model.Id);
         if (article != null)
         {
             context.Articles.Remove(article);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Статья не найдена");
         }
     }
 }
Ejemplo n.º 12
0
 public void Delete(RoleBindingModel model)
 {
     using (var context = new NewsBlogDatabase())
     {
         Role role = context.Role.FirstOrDefault(rec => rec.Idrole == model.Id);
         if (role != null)
         {
             context.Role.Remove(role);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Роль не найдена");
         }
     }
 }
Ejemplo n.º 13
0
 public void Delete(CategoryBindingModel model)
 {
     using (var context = new NewsBlogDatabase())
     {
         Categories category = context.Categories.FirstOrDefault(rec => rec.Idtheme == model.Id);
         if (category != null)
         {
             context.Categories.Remove(category);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Категория не найдена");
         }
     }
 }
Ejemplo n.º 14
0
 public void Delete(CommentBindingModel model)
 {
     using (var context = new NewsBlogDatabase())
     {
         Comments comment = context.Comments.FirstOrDefault(rec => rec.Idcomment == model.Id);
         if (comment != null)
         {
             context.Comments.Remove(comment);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Комментарий не найден");
         }
     }
 }
Ejemplo n.º 15
0
 public void Delete(UserBindingModel model)
 {
     using (var context = new NewsBlogDatabase())
     {
         Users user = context.Users.FirstOrDefault(rec => rec.Iduser == model.Id);
         if (user != null)
         {
             context.Users.Remove(user);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Пользователь не найден");
         }
     }
 }
Ejemplo n.º 16
0
 public List <CategoryViewModel> GetFilteredList(CategoryBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new NewsBlogDatabase())
     {
         return(context.Categories
                .Where(rec => rec.Nametheme.Contains(model.NameTheme))
                .Select(rec => new CategoryViewModel
         {
             Id = rec.Idtheme,
             NameTheme = rec.Nametheme
         }).ToList());
     }
 }
Ejemplo n.º 17
0
 public List <RoleViewModel> GetFilteredList(RoleBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new NewsBlogDatabase())
     {
         return(context.Role
                .Where(rec => rec.Namerole.Contains(model.NameRole))
                .Select(rec => new RoleViewModel
         {
             Id = rec.Idrole,
             NameRole = rec.Namerole
         }).ToList());
     }
 }
Ejemplo n.º 18
0
 public List <CommentViewModel> GetFullList()
 {
     using (var context = new NewsBlogDatabase())
     {
         return(context.Comments
                .Include(rec => rec.IdarticleNavigation)
                .Include(rec => rec.IduserNavigation)
                .Select(rec => new CommentViewModel
         {
             Id = rec.Idcomment,
             Comment = rec.Comment,
             DateCreate = rec.Date,
             ArticleId = rec.Idarticle,
             UserId = rec.Iduser
         }).ToList());
     }
 }
Ejemplo n.º 19
0
 public CategoryViewModel GetElement(CategoryBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new NewsBlogDatabase())
     {
         var category = context.Categories
                        .FirstOrDefault(rec => rec.Nametheme.Equals(model.NameTheme) || rec.Idtheme == model.Id);
         return(category != null ?
                new CategoryViewModel
         {
             Id = category.Idtheme,
             NameTheme = category.Nametheme
         } : null);
     }
 }
Ejemplo n.º 20
0
 public RoleViewModel GetElement(RoleBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new NewsBlogDatabase())
     {
         var role = context.Role
                    .FirstOrDefault(rec => rec.Namerole.Equals(model.NameRole) || rec.Idrole == model.Id);
         return(role != null ?
                new RoleViewModel
         {
             Id = role.Idrole,
             NameRole = role.Namerole
         } : null);
     }
 }
Ejemplo n.º 21
0
 public List <ArticleViewModel> GetFullList()
 {
     using (var context = new NewsBlogDatabase())
     {
         return(context.Articles
                .Include(rec => rec.IdthemeNavigation)
                .Include(rec => rec.IduserNavigation)
                .Select(rec => new ArticleViewModel
         {
             Id = rec.Idarticle,
             Title = rec.Title,
             Text = rec.Text,
             DateCreate = rec.Date,
             CategoryId = rec.Idtheme,
             UserId = rec.Iduser
         }).ToList());
     }
 }
Ejemplo n.º 22
0
 public List <UserViewModel> GetFilteredList(UserBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new NewsBlogDatabase())
     {
         return(context.Users
                .Include(rec => rec.IdroleNavigation)
                .Where(rec => rec.Nickname.Contains(model.Nickname))
                .Select(rec => new UserViewModel
         {
             Id = rec.Iduser,
             Nickname = rec.Nickname,
             RoleId = rec.Idrole
         }).ToList());
     }
 }
Ejemplo n.º 23
0
 public UserViewModel GetElement(UserBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new NewsBlogDatabase())
     {
         var user = context.Users
                    .Include(rec => rec.IdroleNavigation)
                    .FirstOrDefault(rec => rec.Nickname.Equals(model.Nickname) || rec.Iduser == model.Id);
         return(user != null ?
                new UserViewModel
         {
             Id = user.Iduser,
             Nickname = user.Nickname,
             RoleId = user.Idrole
         } : null);
     }
 }
Ejemplo n.º 24
0
 public List <CommentViewModel> GetFilteredList(CommentBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new NewsBlogDatabase())
     {
         return(context.Comments
                .Include(rec => rec.IdarticleNavigation)
                .Include(rec => rec.IduserNavigation)
                .Where(rec => rec.Comment.Contains(model.Comment) || (!model.DateFrom.HasValue && !model.DateTo.HasValue && rec.Date.Date == model.DateCreate.Date) ||
                       (model.DateFrom.HasValue && model.DateTo.HasValue && rec.Date.Date >= model.DateFrom.Value.Date && rec.Date.Date <= model.DateTo.Value.Date))
                .Select(rec => new CommentViewModel
         {
             Id = rec.Idcomment,
             Comment = rec.Comment,
             DateCreate = rec.Date,
             ArticleId = rec.Idarticle,
             UserId = rec.Iduser
         }).ToList());
     }
 }
Ejemplo n.º 25
0
 public CommentViewModel GetElement(CommentBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new NewsBlogDatabase())
     {
         var comment = context.Comments
                       .Include(rec => rec.IdarticleNavigation)
                       .Include(rec => rec.IduserNavigation)
                       .FirstOrDefault(rec => rec.Comment.Equals(model.Comment) || rec.Idcomment == model.Id);
         return(comment != null ?
                new CommentViewModel
         {
             Id = comment.Idcomment,
             Comment = comment.Comment,
             DateCreate = comment.Date,
             ArticleId = comment.Idarticle,
             UserId = comment.Iduser
         } : null);
     }
 }
Ejemplo n.º 26
0
 public ArticleViewModel GetElement(ArticleBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new NewsBlogDatabase())
     {
         var article = context.Articles
                       .Include(rec => rec.IdthemeNavigation)
                       .Include(rec => rec.IduserNavigation)
                       .FirstOrDefault(rec => rec.Title.Equals(model.Title) || rec.Idarticle == model.Id);
         return(article != null ?
                new ArticleViewModel
         {
             Id = article.Idarticle,
             Title = article.Title,
             Text = article.Text,
             DateCreate = article.Date,
             CategoryId = article.Idtheme,
             UserId = article.Iduser
         } : null);
     }
 }
Ejemplo n.º 27
0
 public List <ArticleViewModel> GetFilteredList(ArticleBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new NewsBlogDatabase())
     {
         return(context.Articles
                .Include(rec => rec.IdthemeNavigation)
                .Include(rec => rec.IduserNavigation)
                .Where(rec => rec.Title.Contains(model.Title) || (!model.DateFrom.HasValue && !model.DateTo.HasValue && rec.Date.Date == model.DateCreate.Date) ||
                       (model.DateFrom.HasValue && model.DateTo.HasValue && rec.Date.Date >= model.DateFrom.Value.Date && rec.Date.Date <= model.DateTo.Value.Date))
                .Select(rec => new ArticleViewModel
         {
             Id = rec.Idarticle,
             Title = rec.Title,
             Text = rec.Text,
             DateCreate = rec.Date,
             CategoryId = rec.Idtheme,
             UserId = rec.Iduser
         }).ToList());
     }
 }