public ArchiveBloggViewModel GetAllCategories() { var model = new ArchiveBloggViewModel(); using (BloggContext db = new BloggContext()) { model.BloggCategories = db.BloggCategories.ToList(); } return(model); }
public List <BloggInfo> Get(ArchiveBloggViewModel model) { var list = new List <BloggInfo>(); using (BloggContext db = new BloggContext()) { list = db.BloggInfo.OrderByDescending(r => r.Date).ToList(); } return(list); }
public List <BloggInfo> Get(ArchiveBloggViewModel model) { var list = new List <BloggInfo>(); using (BloggContext db = new BloggContext()) { list = db.BloggInfo.Where(r => r.CategoryId == model.BloggInfo.CategoryId).ToList(); } return(list); }
public List <BloggInfo> Get(ArchiveBloggViewModel model) { var list = new List <BloggInfo>(); using (BloggContext db = new BloggContext()) { list = db.BloggInfo.Where(r => r.Heading.StartsWith(model.BloggInfo.Heading)).ToList(); } return(list); }
public ArchiveBloggViewModel GetBloggDetails(int id) { var model = new ArchiveBloggViewModel(); using (BloggContext db = new BloggContext()) { model.BloggInfo = db.BloggInfo.First(r => r.Id == id); model.BloggCategories = db.BloggCategories.ToList(); } return(model); }
public ArchiveBloggViewModel GetAll() { var model = new ArchiveBloggViewModel(); using (BloggContext db = new BloggContext()) { model.BloggCategory.BloggInfo = db.BloggInfo.OrderByDescending(r => r.Date).ToList(); model.BloggCategories = db.BloggCategories.ToList(); } return(model); }
public ArchiveBloggViewModel BloggsByCategory(ArchiveBloggViewModel model) { var list = new List <BloggInfo>(); using (BloggContext db = new BloggContext()) { model.BloggCategory.BloggInfo = db.BloggInfo.Where(r => r.CategoryId == model.BloggInfo.CategoryId) .OrderByDescending(r => r.Date).ToList() .ToList(); model.BloggCategories = db.BloggCategories.ToList(); } return(model); }
public ArchiveBloggViewModel BloggsBySearchWord(ArchiveBloggViewModel model) { var list = new List <BloggInfo>(); using (BloggContext db = new BloggContext()) { model.BloggCategory.BloggInfo = db.BloggInfo.Where(r => r.Heading.StartsWith(model.BloggInfo.Heading)) .OrderByDescending(r => r.Date).ToList().ToList(); model.BloggCategories = db.BloggCategories.ToList(); } return(model); }
public IActionResult CreateBlogg(ArchiveBloggViewModel model) { if (ModelState.IsValid) { Services.Instance.CreateNewBlogg(model); ModelState.Clear(); return(RedirectToAction("Index")); } else { model = Services.Instance.GetAllCategories(); return(View(nameof(Index), model)); } }
public void Create(ArchiveBloggViewModel model) { using (BloggContext db = new BloggContext()) { var blogg = new BloggInfo() { CategoryId = model.BloggInfo.CategoryId, Date = DateTime.Now, BloggInput = model.BloggInfo.BloggInput, Heading = model.BloggInfo.Heading }; db.BloggInfo.Add(blogg); db.SaveChanges(); } }
public ArchiveBloggViewModel GetBloggs(ArchiveBloggViewModel model) { if ((model.BloggInfo.CategoryId == 4 || model.BloggInfo.CategoryId == 0) && model.BloggInfo.Heading == null) { return(_repository.GetAll()); } else if ((model.BloggInfo.CategoryId == 0 || model.BloggInfo.CategoryId == 4) && model.BloggInfo.Heading != null) { return(_repository.BloggsBySearchWord(model)); } else if (model.BloggInfo.CategoryId != 4 && model.BloggInfo.CategoryId != 0 && model.BloggInfo.Heading == null) { return(_repository.BloggsByCategory(model)); } else if (model.BloggInfo.CategoryId != 4 && model.BloggInfo.CategoryId != 0 && model.BloggInfo.Heading != null) { return(_repository.BloggsByCategoryAndSearchWord(model)); } return(model); }
public List <BloggInfo> GetBloggs(ArchiveBloggViewModel model) { var list = new List <BloggInfo>(); if ((model.BloggInfo.CategoryId == 4 || model.BloggInfo.CategoryId == 0) && model.BloggInfo.Heading == null) { return(new AllBloggsStrategy().Get(model)); } else if ((model.BloggInfo.CategoryId == 0 || model.BloggInfo.CategoryId == 4) && model.BloggInfo.Heading != null) { return(new BloggsBySearchwordStrategy().Get(model)); } else if (model.BloggInfo.CategoryId != 4 && model.BloggInfo.CategoryId != 0 && model.BloggInfo.Heading == null) { return(new BloggsByCategoryStrategy().Get(model)); } else if (model.BloggInfo.CategoryId != 4 && model.BloggInfo.CategoryId != 0 && model.BloggInfo.Heading != null) { return(new BloggsByCategoryAndSearchwordStrategy().Get(model)); } return(list); }
public IActionResult GetBySearch(ArchiveBloggViewModel model) { model = Services.Instance.GetBloggs(model); return(View(model)); }
public void CreateNewBlogg(ArchiveBloggViewModel model) { _repository.Create(model); }
public IActionResult GetBySearch(ArchiveBloggViewModel model) { _archivedBloggViewModel.BloggCategory.BloggInfo = _repository.GetBloggs(model).OrderByDescending(r => r.Date).ToList(); _archivedBloggViewModel.BloggCategories = _context.BloggCategories.ToList(); return(View(_archivedBloggViewModel)); }