public ActionResult Create(Role role) { if (ModelState.IsValid) { var dao = new RoleDao(); var getRole = dao.getByName(role.Name); //Check if new role exsits if (getRole != null) { ModelState.AddModelError("Name", "Role " + role.Name + " exists in database."); return(View(role)); } var entity = new Role(); entity.Id = Guid.NewGuid(); entity.Name = role.Name; entity.Description = role.Description; Guid id = dao.create(entity); if (id != null) { ViewBag.CreateRoleSuccessMessage = "Create " + role.Name + " successful"; } else { ViewBag.CreateRoleErrorMessage = "Create " + role.Name + " failed"; } } return(View(role)); }