Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Detail(string id)
        {
            var dao = new RoleDao();

            //check if id = null
            if (id == null)
            {
                Response.StatusCode = 404;
                return(View("NotFound"));
            }

            //check if id does not exist in database
            if (dao.getById(id.ToString()) == null)
            {
                Response.StatusCode = 404;
                return(View("NotFound"));
            }
            else
            {
                return(View(dao.getById(id.ToString())));
            }
        }
Example #2
0
        public ActionResult Edit(Role role)
        {
            if (ModelState.IsValid)
            {
                var dao = new RoleDao();

                var checkExistRole = dao.getById(role.Id.ToString());
                if (checkExistRole == null)
                {
                    Response.StatusCode = 404;
                    return(View("NotFound"));
                }

                if (!role.Id.Equals(checkExistRole.Id))
                {
                    var roleDetail = dao.getById(role.Id.ToString());
                    if (roleDetail != null)
                    {
                        ModelState.AddModelError("Name", "Role " + role.Name + " exists in database.");
                        return(View(role));
                    }
                }

                var entity = new Role();
                entity.Id          = role.Id;
                entity.Name        = role.Name;
                entity.Description = role.Description;
                bool update = dao.update(entity);
                if (update)
                {
                    ViewBag.EditRoleSuccessMessage = "Update role Successful";
                }
                else
                {
                    ViewBag.EditRoleErrorMessage = "Update role failed";
                }
            }
            return(View(role));
        }
Example #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ActionResult Edit(string id)
 {
     if (id == null)
     {
         Response.StatusCode = 404;
         return(View("NotFound"));
     }
     else
     {
         var dao  = new RoleDao();
         var role = dao.getById(id);
         if (role == null)
         {
             Response.StatusCode = 404;
             return(View("NotFound"));
         }
         else
         {
             return(View(role));
         }
     }
 }
Example #4
0
 public ActionResult Delete(string id)
 {
     if (id == null)
     {
         Response.StatusCode = 404;
         return(View("NotFound"));
     }
     else
     {
         var dao  = new RoleDao();
         var role = dao.getById(id);
         if (role == null)
         {
             Response.StatusCode = 404;
             return(View("NotFound"));
         }
         else
         {
             new RoleDao().delete(id);
             return(RedirectToAction("Index"));
         }
     }
 }