Exemple #1
0
        public ActionResult searchByName(string searchString)
        {
            DataBaseBlog       db       = new DataBaseBlog();
            List <Models.Blog> listBlog = db.Blogs.Where(b => b.title.Contains(searchString)).ToList();

            return(View(listBlog));
        }
Exemple #2
0
        public static void addObject(FormCollection collection, UserSection section)
        {
            DataBaseBlog db = new DataBaseBlog();

            Models.Blog obj = new Models.Blog();


            obj.ID        = Guid.NewGuid().ToString();
            obj.title     = collection["title"];
            obj.contents  = collection["contents"];
            obj.thumbnail = collection["thumbnail"];
            obj.status    = 2;
            obj.create_at = DateTime.Now;
            obj.create_by = section.UserID;


            db.Set(obj.GetType()).Add(obj);
            db.SaveChanges();

            if (collection["categories"] != null)
            {
                List <string> result = collection["categories"].Split(',').ToList();
                blog_category_Data.inserts(obj.ID, result);
            }
        }
Exemple #3
0
        public ActionResult Index()
        {
            DataBaseBlog       db    = new DataBaseBlog();
            List <Models.Blog> blogs = db.Blogs.ToList();

            return(View(blogs));
        }
Exemple #4
0
        public static void addObject <T>(T obj)
        {
            DataBaseBlog db = new DataBaseBlog();

            db.Set(obj.GetType()).Add(obj);
            db.SaveChanges();
        }
Exemple #5
0
        public static void removeFromBlogId(string BlogId)
        {
            DataBaseBlog db = new DataBaseBlog();

            db.Blog_category.RemoveRange(db.Blog_category.Where(b => b.blog_id == BlogId));
            db.SaveChanges();
        }
Exemple #6
0
        public static void removeFromCategory(string category_id)
        {
            DataBaseBlog db = new DataBaseBlog();

            db.Blog_category.RemoveRange(db.Blog_category.Where(b => b.category_id == category_id));

            db.SaveChanges();
        }
Exemple #7
0
        public ActionResult searchByCategory(string id)
        {
            DataBaseBlog db = new DataBaseBlog();

            Category cate = db.Categories.Where(x => x.ID == id).SingleOrDefault();

            return(View(cate.Blog_category.ToList()));
        }
Exemple #8
0
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            DataBaseBlog           db   = new DataBaseBlog();
            List <Models.Category> list = db.Categories.ToList();

            ViewBag.ListCate = list;

            base.OnActionExecuted(filterContext);
        }
Exemple #9
0
        public ActionResult SelectCategories()
        {
            DataBaseBlog db = new DataBaseBlog();

            db.Configuration.ProxyCreationEnabled = false;
            List <Category> Categories = db.Categories.OrderByDescending(c => c.name).ToList();

            return(this.Json(Categories, JsonRequestBehavior.AllowGet));
        }
Exemple #10
0
        public static void remove(string id)
        {
            DataBaseBlog db        = new DataBaseBlog();
            Category     objRemove = db.Categories.Find(id);

            try{
                blog_category_Data.removeFromCategory(id);
                db.Categories.Remove(objRemove);
                db.SaveChanges();
            }
            catch {
            }
        }
Exemple #11
0
        public static void remove(string id)
        {
            DataBaseBlog db = new DataBaseBlog();

            db.Blog_category.RemoveRange(db.Blog_category.Where(x => x.blog_id == id));
            try
            {
                db.Blogs.Remove(db.Blogs.Find(id));
                db.SaveChanges();
            }
            catch
            {
            }
        }
Exemple #12
0
        public static void inserts(string blogId, List <string> categoryIds)
        {
            DataBaseBlog db = new DataBaseBlog();

            foreach (string categoryId in categoryIds)
            {
                Blog_category bc = new Blog_category();
                bc.ID          = Guid.NewGuid().ToString();
                bc.blog_id     = blogId;
                bc.category_id = categoryId;
                db.Blog_category.Add(bc);
            }
            db.SaveChanges();
        }
Exemple #13
0
        public static void update(Category newObj)
        {
            DataBaseBlog db = new DataBaseBlog();

            try
            {
                Category oldObj = db.Categories.Find(newObj.ID);
                oldObj.name        = newObj.name;
                oldObj.description = newObj.description;
                db.SaveChanges();
            }
            catch {
            }
        }
Exemple #14
0
        public static void Update(string blogId, List <string> categoryIds)
        {
            DataBaseBlog db = new DataBaseBlog();

            db.Blog_category.RemoveRange(db.Blog_category.Where(b => b.blog_id == blogId));
            foreach (string categoryId in categoryIds)
            {
                Blog_category bc = new Blog_category();
                bc.ID          = Guid.NewGuid().ToString();
                bc.blog_id     = blogId;
                bc.category_id = categoryId;
                db.Blog_category.Add(bc);
            }
            db.SaveChanges();
        }
Exemple #15
0
        public static void Update(string id, FormCollection collection)
        {
            DataBaseBlog db = new DataBaseBlog();

            Models.Blog obj = db.Blogs.Find(id);

            obj.title     = collection["title"];
            obj.contents  = collection["contents"];
            obj.thumbnail = collection["thumbnail"];

            db.SaveChanges();

            if (collection["categories"] != null)
            {
                List <string> result = collection["categories"].Split(',').ToList();
                blog_category_Data.Update(id, result);
            }
            else
            {
                blog_category_Data.removeFromBlogId(id);
            }
        }
Exemple #16
0
        public static Models.Blog selectBlog(string ID)
        {
            DataBaseBlog mydb = new DataBaseBlog();

            return(mydb.Blogs.Find(ID));
        }
Exemple #17
0
        public static List <Models.Blog> selectListBlogs(int total)
        {
            DataBaseBlog mydb = new DataBaseBlog();

            return(mydb.Blogs.ToList());
        }
Exemple #18
0
        public static List <Models.Category> selectListCategorys(int total)
        {
            DataBaseBlog mydb = new DataBaseBlog();

            return(mydb.Categories.ToList());
        }
 public BlogsDetailsController(DataBaseBlog context)
 {
     _context = context;
 }
Exemple #20
0
        public static Category find(string id)
        {
            DataBaseBlog db = new DataBaseBlog();

            return(db.Categories.Find(id));
        }
Exemple #21
0
        public static Models.Blog find(string ID)
        {
            DataBaseBlog db = new DataBaseBlog();

            return(db.Blogs.Find(ID));
        }
Exemple #22
0
        public static List <Category> pagination(int pana)
        {
            DataBaseBlog db = new DataBaseBlog();

            return(db.Categories.OrderByDescending(c => c.create_at).Take(pana).ToList());
        }
Exemple #23
0
        public static List <Category> all()
        {
            DataBaseBlog db = new DataBaseBlog();

            return(db.Categories.OrderByDescending(c => c.create_at).ToList());
        }