public static RoleModelDA RoleModelBLToRoleModelDA(RoleModelBL role) { var newRole = new RoleModelDA() { Id = role.Id, Name = role.Name, //Users = new List<UserModelDA>() }; if (role.Users == null) { return(newRole); } newRole.Users = new List <UserModelDA>(); role.Users.ToList().ForEach(s => newRole.Users.Add(new UserModelDA { Login = s.Login, Password = s.Password, IsActive = s.IsActive })); return(newRole); }
public bool Create(RoleModelDA createRole) { var role = _context.Roles.FirstOrDefault(u => u.Name == createRole.Name); if (role == null) { _context.Roles.Add(RoleMapDA.RoleModelDAToRole(createRole)); } else { throw new Exception("The role is exist."); } _context.SaveChanges(); return(true); }