Esempio n. 1
0
        public ArchiveBloggViewModel GetAllCategories()
        {
            var model = new ArchiveBloggViewModel();

            using (BloggContext db = new BloggContext())
            {
                model.BloggCategories = db.BloggCategories.ToList();
            }
            return(model);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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));
     }
 }
Esempio n. 10
0
 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();
     }
 }
Esempio n. 11
0
 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);
 }
Esempio n. 12
0
        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));
 }
Esempio n. 14
0
 public void CreateNewBlogg(ArchiveBloggViewModel model)
 {
     _repository.Create(model);
 }
Esempio n. 15
0
 public IActionResult GetBySearch(ArchiveBloggViewModel model)
 {
     _archivedBloggViewModel.BloggCategory.BloggInfo = _repository.GetBloggs(model).OrderByDescending(r => r.Date).ToList();
     _archivedBloggViewModel.BloggCategories         = _context.BloggCategories.ToList();
     return(View(_archivedBloggViewModel));
 }