public ActionResult CategoryEdit(dt_category category)
 {
     if (ModelState.IsValid)
     {
         var user = db.dt_user.FirstOrDefault();
         if (Session["personel_id"] == null)
             return RedirectToAction("Default", "Home");
         else
         {
             int personel_id = Convert.ToInt32(Session["personel_id"]);
             user = db.dt_user.Where(a => a.state == 1 && a.ID == personel_id).FirstOrDefault();
             if (user == null)
                 return RedirectToAction("Default", "Home");
             ViewBag.userName = user.name + " " + user.surname;
         }
         if (user.unvan_id != 2)
         {
             TempData["mesaj"] = "Bu işlemi gerçekleştirmeye yetkiniz yok...!";
             return RedirectToAction("CategoryEdit", new { ID = category.ID });
         }
         var dtcategory = (from cat in db.dt_category where cat.ID == category.ID && cat.state == 1 select cat).FirstOrDefault();
         if (dtcategory != null)
         {
             var cat1 = (from cat in db.dt_category where cat.company_id == category.company_id && cat.name == category.name && cat.ID != category.ID && cat.state == 1 select cat).FirstOrDefault();
             if (cat1 == null)
             {
                 dtcategory.upCategoryID = category.upCategoryID;
                 dtcategory.name = category.name;
                 dtcategory.summary = category.summary;
                 db.SaveChanges();
                 TempData["mesaj"] = "İşlem başarı ile gerçekleşti.";
                 return RedirectToAction("CategoryEdit", new { ID = category.ID });
             }
             else
             {
                 TempData["mesaj"] = "Bu isimde bir kategori mevcut";
                 return RedirectToAction("CategoryEdit", new { ID = category.ID });
             }
         }
         else
         {
             return RedirectToAction("CategoryShow");
         }
     }
     else
     {
         return RedirectToAction("CategoryEdit", new { ID = category.ID });
     }
 }
 public ActionResult CategoryEdit(dt_category category)
 {
     if (ModelState.IsValid)
     {
         var dtcategory = (from cat in db.dt_category where cat.company_id == category.company_id && cat.ID == category.ID && cat.state == 1 select cat).FirstOrDefault();
         if (dtcategory != null)
         {
             var cat1 = (from cat in db.dt_category where cat.company_id == category.company_id && cat.name == category.name && cat.ID != category.ID && cat.state == 1 select cat).FirstOrDefault();
             if (cat1 == null)
             {
                 dtcategory.upCategoryID = category.upCategoryID;
                 dtcategory.name = category.name;
                 dtcategory.summary = category.summary;
                 db.SaveChanges();
                 return RedirectToAction("CategoryEdit", new { ID = category.ID, mesaj = 1 });
             }
             else
             {
                 return RedirectToAction("CategoryEdit", new { ID = category.ID, mesaj = 0 });
             }
         }
         else
         {
             return RedirectToAction("CategoryShow");
         }
     }
     else
     {
         List<SelectListItem> listCategory = GetCategory(category.ID, category.company_id);
         //ViewBag.companyId = list.ToList();
         SelectListItem it = new SelectListItem();
         it.Text = "Üst Kategori";
         it.Value = "0";
         listCategory.Add(it);
         if (category.upCategoryID == 0)
             listCategory.Reverse();
         ViewBag.categoryId = listCategory.ToList();
         return View(category);
     }
 }
        public ActionResult CategoryCreate(dt_category category)
        {
            if (ModelState.IsValid)
            {
                var user = db.dt_user.FirstOrDefault();
                if (Session["personel_id"] == null)
                    return RedirectToAction("Default", "Home");
                else
                {
                    int personel_id = Convert.ToInt32(Session["personel_id"]);
                    user = db.dt_user.Where(a => a.state == 1 && a.ID == personel_id).FirstOrDefault();
                    if (user == null)
                        return RedirectToAction("Default", "Home");
                    if (user.unvan_id != 2)
                    {
                        TempData["mesaj"] = "Bu işlemi gerçekleştirmeye yetkiniz yok...!";
                        return RedirectToAction("CategoryCreate");
                    }
                    var c = db.dt_category.Where(a => a.name == category.name && a.company_id == user.company_id && a.state == 1);
                    if (c.Count() > 0)
                    {
                        TempData["mesaj"] = "Bu isimde bir kategori var...!";
                        return RedirectToAction("CategoryCreate");
                    }
                    db.dt_category.AddObject(new dt_category
                    {
                        name = category.name,
                        upCategoryID = category.upCategoryID,
                        company_id = user.company_id,
                        summary = category.summary,
                        state = 1
                    });
                    db.SaveChanges();
                    TempData["mesaj"] = "İşlem başarı ile gerçekleşti.";
                    return RedirectToAction("CategoryCreate");

                }
            }
            else
                return View(category);
        }
 public ActionResult CategoryCreate(dt_category category)
 {
     if (ModelState.IsValid)
     {
         var cat1 = (from cat in db.dt_category where cat.company_id == category.company_id && cat.name == category.name && cat.state == 1 select cat).FirstOrDefault();
         if (cat1 == null)
         {
             db.dt_category.AddObject(new dt_category
             {
                 company_id = category.company_id,
                 upCategoryID = category.upCategoryID,
                 name = category.name,
                 state = 1,
                 summary = category.summary
             });
             db.SaveChanges();
             return RedirectToAction("CategoryCreate", new { ID = category.ID, mesaj = 1 });
         }
         else
         {
             return RedirectToAction("CategoryCreate", new { ID = category.ID, mesaj = 0 });
         }
     }
     return View(category);
 }