public ActionResult Create([Bind(Include = "ID,DEPT_NAME,DEPT_ID,IsActive")] departmant departmantModel)
        {
            var SessionControl = Convert.ToInt32(HttpContext.Session["RoleID"]);

            if (SessionControl != 5)
            {
                return(RedirectToAction("Index", "Home"));
            }

            //departmant dbDept = new departmant();
            try {
                if (db.departmant.Any(x => x.DEPT_ID == departmantModel.DEPT_ID))
                {
                    TempData["info"] = departmantModel.DEPT_ID + " " + "Department already created!";
                    return(RedirectToAction("Create", "Departmants"));
                }
                if (ModelState.IsValid)
                {
                    db.departmant.Add(departmantModel);
                    db.SaveChanges();
                    TempData["info"] = "Department Created Succesfull";
                    return(RedirectToAction("Index", "Location"));
                }
            }
            catch (Exception ex)
            {
                TempData["info"] = "Problem Occured: " + " " + ex.Message;
                return(RedirectToAction("Index", "Location"));
            }


            return(View(departmantModel));
        }
        // GET: Departmants/Delete/5
        public ActionResult Delete(int?id)
        {
            var SessionControl = Convert.ToInt32(HttpContext.Session["RoleID"]);

            if (SessionControl != 5)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var SessionSuperAdmin = Convert.ToInt32(HttpContext.Session["UserID"]);

            if (SessionSuperAdmin != 1000000000)
            {
                return(RedirectToAction("Index", "Location"));
            }
            // Request id is null then bad request error appear 400
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            departmant departmant = db.departmant.Find(id);

            if (departmant == null)
            {
                return(HttpNotFound());
            }
            return(View(departmant));
        }
        public ActionResult DepartmentDetails(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            departmant department = db.departmant.Find(id);

            if (department == null)
            {
                return(HttpNotFound());
            }

            ViewBag.LocationCount = db.departmant.Where(x => x.ID == id).Count();


            return(View(department));
        }
        [ValidateAntiForgeryToken] // for avoid the anti forgery keys attacks.
        public ActionResult Edit([Bind(Include = "ID,DEPT_NAME,DEPT_ID,IsActive")] departmant departmant)
        {
            var SessionControl = Convert.ToInt32(HttpContext.Session["RoleID"]);

            if (SessionControl != 5)
            {
                return(RedirectToAction("Index", "Home"));
            }
            //Check if model state which is department model from requested result and validations are true then edit else return the current page
            if (ModelState.IsValid)
            {
                db.Entry(departmant).State = EntityState.Modified;
                db.SaveChanges();
                TempData["info"] = "Department Edit Succesfully";
                return(RedirectToAction("Index", "Location"));
            }
            return(View(departmant));
        }
        // Details for Department
        // GET: Departmants/Details/5
        public ActionResult Details(int?id)
        {
            var SessionControl = Convert.ToInt32(HttpContext.Session["RoleID"]);

            if (SessionControl != 5)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            departmant departmant = db.departmant.Find(id);

            if (departmant == null)
            {
                return(HttpNotFound());
            }
            return(View(departmant));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            var SessionControl = Convert.ToInt32(HttpContext.Session["RoleID"]);

            if (SessionControl != 5)
            {
                return(RedirectToAction("Index", "Home"));
            }
            try {
                departmant departmant = db.departmant.Find(id);
                db.departmant.Remove(departmant);
                db.SaveChanges();
                TempData["info"] = "Department Deleted Succesfully";
                if (departmant.location.Any())
                {
                }
                return(RedirectToAction("Index", "Location"));
            }
            catch (Exception Ex)
            {
                TempData["info"] = "There is a problem occured" + " " + Ex.Message;
                return(RedirectToAction("Delete", "Departmants", new { id = id }));
            }
        }
 public void Update(departmant obj)
 {
     _context.departmant.AddOrUpdate();
 }
 public void Insert(departmant obj)
 {
     _context.departmant.Add(obj);
 }