Esempio n. 1
0
        public ActionResult Create(RoleEditViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return View(model);
            }

            var role = new Role()
            {
                RoleName = model.Name,
                Description = model.Description
            };

            try
            {
                this.roleService.CreateRole(role);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError("Name", ex.Message);
                return View(model);
            }

            return RedirectToAction("Details", new { id = role.RoleId });
        }
Esempio n. 2
0
        public void PostEdit()
        {
            MockRoleService service = new MockRoleService();
            RoleController controller = GetRoleController(service);

            Role role = service.Roles[0];

            RoleEditViewModel model = new RoleEditViewModel()
            {
                Id = role.RoleId,
                Name = "New " + role.RoleName
            };

            ActionResult result = controller.Edit(role.RoleId, model);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));

            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;

            Assert.AreEqual("Details", redirectResult.RouteValues["action"]);
            Assert.AreEqual(role.RoleId, redirectResult.RouteValues["id"]);

            Assert.AreEqual(role.RoleName, model.Name);
            Assert.AreEqual(role.RoleId, model.Id);
        }
Esempio n. 3
0
        public void PostCreate()
        {
            MockRoleService service = new MockRoleService();
            RoleController controller = GetRoleController(service);
            int nroles = service.Roles.Count;

            var model = new RoleEditViewModel()
            {
                Name = "New Role",
                Description = "New Role"
            };

            ActionResult result = controller.Create(model);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));

            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;

            Assert.AreEqual("Details", redirectResult.RouteValues["action"]);

            Assert.AreEqual(nroles + 1, service.Roles.Count);

            Assert.IsNotNull(service.NewRole);
            Assert.AreEqual("New Role", service.NewRole.RoleName);
        }
Esempio n. 4
0
        public ActionResult Edit(Guid id, RoleEditViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return View(model);
            }

            var role = this.roleService.GetRoleById(id);
            role.RoleName = model.Name;
            role.Description = model.Description;

            try
            {
                this.roleService.UpdateRole(role);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError("Name", ex.Message);
                return View(model);
            }

            return RedirectToAction("Details", new { id = id });
        }
Esempio n. 5
0
        public ActionResult Edit(Guid id)
        {
            var role = this.roleService.GetRoleById(id);
            var model = new RoleEditViewModel()
            {
                Id = role.RoleId,
                Name = role.RoleName,
                OriginalName = role.RoleName,
                Description = role.Description
            };

            return View(model);
        }