예제 #1
0
        public ActionResult Edit([Bind(Include = "CategoryId,Name")] Category_Tbl category_Tbl)
        {
            if (category_Tbl.Name == null)
            {
                return(View(category_Tbl));
            }
            if (Session["cat"].ToString() != category_Tbl.Name)
            {
                Category_Tbl c = db.Category_Tbl.FirstOrDefault(x => x.Name == category_Tbl.Name);
                if (c != null)
                {
                    ViewData["Error"] = "Category already exists";
                    return(View(category_Tbl));
                }
            }

            if (ModelState.IsValid)
            {
                db.Entry(category_Tbl).State = EntityState.Modified;
                db.SaveChanges();
                ViewData["ED"] = "Successfully edited";
                return(View("Index", db.Category_Tbl.ToList()));
            }
            return(View(category_Tbl));
        }
예제 #2
0
        public ActionResult Create(string name)
        {
            if (name == "")
            {
                ViewData["Error"] = "Please Enter some thing";
                return(RedirectToAction("Index"));
            }
            Category_Tbl category_Tbl = new Category_Tbl();

            category_Tbl.Name = name;
            Category_Tbl c = db.Category_Tbl.FirstOrDefault(x => x.Name == category_Tbl.Name);

            if (c != null)
            {
                ViewData["Error"] = "Already exists";
                return(View("Index", db.Category_Tbl.ToList()));
            }


            if (ModelState.IsValid)
            {
                db.Category_Tbl.Add(category_Tbl);
                db.SaveChanges();
                ViewData["Error"] = "Successfully Added";
                return(View("Index", db.Category_Tbl.ToList()));
            }

            return(RedirectToAction("Index"));
        }
예제 #3
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            Category_Tbl category_tbl = await db.Category_Tbl.FindAsync(id);

            db.Category_Tbl.Remove(category_tbl);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
예제 #4
0
        public async Task <ActionResult> Edit([Bind(Include = "categoryid,categoryname,categorydesc,createdby,createddate,updatedby,updateddate")] Category_Tbl category_tbl)
        {
            if (ModelState.IsValid)
            {
                db.Entry(category_tbl).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(category_tbl));
        }
예제 #5
0
        public async Task <ActionResult> Create([Bind(Include = "categoryid,categoryname,categorydesc,createdby,createddate,updatedby,updateddate")] Category_Tbl category_tbl)
        {
            if (ModelState.IsValid)
            {
                db.Category_Tbl.Add(category_tbl);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(category_tbl));
        }
예제 #6
0
        // GET: /Default1/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Category_Tbl category_tbl = await db.Category_Tbl.FindAsync(id);

            if (category_tbl == null)
            {
                return(HttpNotFound());
            }
            return(View(category_tbl));
        }
        public ActionResult Index(string searchBy, string search, int?page)
        {
            //ViewBag.search = new SelectList(db.Category_Tbl, "categoryid", "Name");


            if (searchBy == "Category")
            {
                c = db.Category_Tbl.FirstOrDefault(x => x.Name == search);
                if (c != null)
                {
                    return(View(db.Posts_Tbl.OrderByDescending(x => x.PostId).Where(x => (x.Status != "Pending" && x.CategoryId == c.CategoryId) || (x.Status != "pending" && search == null)).ToList().ToPagedList(page ?? 1, 10)));
                }
                return(View(db.Posts_Tbl.Where(x => x.CategoryId == -1).ToList().ToPagedList(page ?? 1, 10)));
            }

            return(View(db.Posts_Tbl.OrderByDescending(x => x.PostId).Where(x => (x.PostName.Contains(search) && x.Status != "Pending") || (search == null && x.Status != "Pending")).ToList().ToPagedList(page ?? 1, 10)));
        }
예제 #8
0
 // GET: Category_Tbl/Delete/5
 public ActionResult Delete(int?id)
 {
     if (Session["id"] != null)
     {
         u = db.Users_Tbl.Find(Session["id"]);
         if (u.RollId == 1)
         {
             if (id == null)
             {
                 return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
             }
             Category_Tbl category_Tbl = db.Category_Tbl.Find(id);
             if (category_Tbl == null)
             {
                 return(HttpNotFound());
             }
             return(View(category_Tbl));
         }
         return(RedirectToAction("index", "home"));
     }
     return(RedirectToAction("index", "home"));
 }
예제 #9
0
        public ActionResult DeleteConfirmed(int id)
        {
            try
            {
                List <Posts_Tbl> pl = db.Posts_Tbl.Where(x => x.CategoryId == id).ToList();
                foreach (var item in pl)
                {
                    try
                    {
                        List <Comment_Tbl> cl = db.Comment_Tbl.Where(x => x.PostId == item.PostId).ToList();
                        foreach (var comment in cl)
                        {
                            db.Comment_Tbl.Remove(comment);
                        }
                        db.Posts_Tbl.Remove(item);
                    }
                    catch (Exception)
                    {
                        db.Posts_Tbl.Remove(item);
                    }
                }
                Category_Tbl category_Tbl = db.Category_Tbl.Find(id);
                db.Category_Tbl.Remove(category_Tbl);
                db.SaveChanges();
                ViewData["ED"] = "Successfully deleted";
                return(View("Index", db.Category_Tbl.ToList()));
            }

            catch (Exception)
            {
                Category_Tbl category_Tbl = db.Category_Tbl.Find(id);
                db.Category_Tbl.Remove(category_Tbl);
                db.SaveChanges();
                ViewData["ED"] = "Successfully deleted";
                return(View("Index", db.Category_Tbl.ToList()));
            }
        }