public void Insert(UserBindingModel model) { using (var context = new NewsBlogDatabase()) { context.Users.Add(CreateModel(model, new Users())); context.SaveChanges(); } }
public void Insert(CategoryBindingModel model) { using (var context = new NewsBlogDatabase()) { context.Categories.Add(CreateModel(model, new Categories())); context.SaveChanges(); } }
public List <CategoryViewModel> GetFullList() { using (var context = new NewsBlogDatabase()) { return(context.Categories .Select(rec => new CategoryViewModel { Id = rec.Idtheme, NameTheme = rec.Nametheme }).ToList()); } }
public List <RoleViewModel> GetFullList() { using (var context = new NewsBlogDatabase()) { return(context.Role .Select(rec => new RoleViewModel { Id = rec.Idrole, NameRole = rec.Namerole }).ToList()); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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()); } }
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("Статья не найдена"); } } }
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("Роль не найдена"); } } }
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("Категория не найдена"); } } }
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("Комментарий не найден"); } } }
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("Пользователь не найден"); } } }
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()); } }
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()); } }
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()); } }
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); } }
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); } }
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()); } }
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()); } }
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); } }
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()); } }
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); } }
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); } }
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()); } }