public ActionResult Edit([Bind(Include = "Id,Title,Url,FormatUrl,SortOrder,Publish,CreateDate,ModifiedDate")] CategoryBlog category)
        {
            category.ModifiedDate    = DateTime.Now;
            db.Entry(category).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "Title,FormatUrl,SortOrder,Publish")] CategoryBlog category)
        {
            category.Id = (db.CategoryBlogs.Max(x => (int?)x.Id) ?? 0) + 1;

            category.Url          = Common.TiegVietKhongDauUrl(Common.NameStandard(category.Title));
            category.CreateDate   = DateTime.Now;
            category.ModifiedDate = DateTime.Now;


            db.CategoryBlogs.Add(category);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #3
0
        public async Task <int> AddCategoryBlog(CategoryBlogForCreation cateDto)
        {
            var checkcategoryExist = await _db.CategoryBlogs.Where(p => p.CategoryBlogName == cateDto.CategoryBlogName).FirstOrDefaultAsync();

            if (checkcategoryExist == null)
            {
                CategoryBlog category = new CategoryBlog
                {
                    CategoryBlogName = cateDto.CategoryBlogName
                };
                _db.CategoryBlogs.Add(category);
                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }