Exemplo n.º 1
0
        public ActionResult Create(Role roles)
        {
            if (ModelState.IsValid)
            {
                db.Roles.Add(roles);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(roles);
        }
Exemplo n.º 2
0
        public JsonResult CreateRole(Role role)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." });
                }

                var addedRole = db.Roles.Add(role);
                db.SaveChanges();
                return Json(new { Result = "OK", Record = addedRole });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }
Exemplo n.º 3
0
        public JsonResult UpdateRole(Role role)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." });
                }

                db.Entry(role).State = EntityState.Modified;
                db.SaveChanges();
                return Json(new { Result = "OK" });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }
Exemplo n.º 4
0
 public ActionResult Edit(Role roles)
 {
     if (ModelState.IsValid)
     {
         db.Entry(roles).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(roles);
 }