public ActionResult Create(Role role, FormCollection form) { ViewData["ValidationErrorMessage"] = String.Empty; if (this.FormCollectionIsValid(form)) { db.Save(this.RemoveExtraSpaces(role)); List<Object> logList = new List<Object>(); logList.Add(log.GetNewLog(ConfigurationManager.AppSettings["CreateText"] + ControllerContext.RouteData.Values["controller"] + "(Id=" + role.Id.ToString().Replace("-", "").ToUpper() + " - Description=" + role.Description + " - Name=" + role.Name + ")", (int)EventTypes.Create, (int)Session["UserId"])); log.Write(logList); return RedirectToAction("Index"); } return View(role); }
public void CanCreateUserAndRole() { IRepository<Role> repoA = new RoleRepository(); Role role1 = new Role(); role1.Name = "PruebaRol1"; role1.Description = "Prueba descriptiva rol 1"; Role role2 = new Role(); role2.Name = "PruebaRol2"; role2.Description = "Prueba descriptiva rol 2"; repoA.Save(role1); repoA.Save(role2); IRepository<User> repoB = new UserRepository(); User user1 = new User(); user1.DocumentId = 11111; user1.LoginEmail = "*****@*****.**"; user1.FirstName = "Usuario prueba nombre 1"; user1.MiddleName = "Usuario prueba nombre 2"; user1.LastName1 = "Usuario prueba apellido 1"; user1.LastName2 = "Usuario prueba apellido 2"; user1.PhoneNumber = "457-4334(90)"; user1.IsActive = true; user1.Password = "******"; UserRole userRole1 = new UserRole(); userRole1.Role = role1; userRole1.User = user1; UserRole userRole2 = new UserRole(); userRole2.Role = role2; userRole2.User = user1; user1.Roles.Add(userRole1); user1.Roles.Add(userRole2); repoB.Save(user1); }
private Role RemoveExtraSpaces(Role role) { role.Name = !String.IsNullOrWhiteSpace(role.Name) ? role.Name.Trim() : null; role.Description = !String.IsNullOrWhiteSpace(role.Description) ? role.Description.Trim() : null; return role; }