Beispiel #1
0
        //todo unitestd
        public int AddRole(Role role)
        {
            var checkRole = _roleDao.GetRole(role.RoleName);

            if (!checkRole.IsNullOrEmpty())
            {
                throw new BussinessException(ERROR_ROLENAME_EXIST);
            }
            return(_roleDao.AddRole(GetRolePoFromRole(role)));
        }
        public IEnumerable <User> GetAllUsers()
        {
            _logger.Info($"DAL.{nameof(UserDao)}.{nameof(GetAllUsers)}: Getting all users");

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                SqlCommand command = new SqlCommand("dbo.User_GetAllUsers", connection)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                };

                SqlDataReader reader;

                try
                {
                    connection.Open();

                    reader = command.ExecuteReader();

                    _logger.Info($"DAL.{nameof(UserDao)}.{nameof(GetAllUsers)}: Connected to database");
                }
                catch (InvalidOperationException ex)
                {
                    _logger.Error($"DAL.{nameof(UserDao)}.{nameof(GetAllUsers)}: Not connected to database: " + ex.Message);

                    throw new SystemException("Connection error", ex);
                }

                int?RoleID;

                while (reader.Read())
                {
                    RoleID = (int?)reader["RoleID"];

                    yield return(new User(
                                     (int?)reader["Id"],
                                     (string)reader["Login"],
                                     (string)reader["Password"],
                                     RoleID is null ? null : _roleDao.GetRole(RoleID ?? -1),
                                     (string)reader["Name"]));
                }
            }

            _logger.Info($"DAL.{nameof(UserDao)}.{nameof(GetAllUsers)}: All users received");

            yield break;
        }
        /// <summary>
        /// Gets the roles.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public RoleResponse GetRoles(RoleRequest request)
        {
            var response = new RoleResponse();

            if (request.LoadOptions.Contains("Roles"))
            {
                response.Roles = request.LoadOptions.Contains("Active") ? RoleDao.GetRoles(request.IsActive) : RoleDao.GetRoles();
            }
            if (request.LoadOptions.Contains("Role"))
            {
                response.Role = RoleDao.GetRole(request.RoleId);
                if (request.LoadOptions.Contains("RoleSite"))
                {
                    response.Role.RoleSiteEntities = RoleSiteDao.GetRoleSiteByRoleId(request.RoleId);
                }
            }

            return(response);
        }
        public Role GetRoleOrNull(int id)
        {
            _logger.Info($"BLL.{nameof(RoleBll)}.{nameof(GetRoleOrNull)}: Getting the role id = " + id);

            if (_roleDao.IsRole(id))
            {
                _logger.Info($"BLL.{nameof(RoleBll)}.{nameof(GetRoleOrNull)}: Role id = {id} received");

                return(_roleDao.GetRole(id));
            }
            else
            {
                _logger.Warn($"BLL.{nameof(RoleBll)}.{nameof(GetRoleOrNull)}: Role id = {id} not found");

                return(null);
            }
        }
Beispiel #5
0
 public int AddUser(User user)
 {
     user.RoleId   = roleDao.GetRole(Role.VALUE.USER.ToString()).Id;
     user.StatusId = statusDao.GetStatus(Status.VALUE.USER_ACTIVE.ToString()).Id;
     return(userDao.AddUser(user));
 }
        public ActionResult EditRole(string RoleID)
        {
            var ressult = _roleRepository.GetRole(RoleID);

            return(View(Mapper.ToDto(ressult)));
        }