Esempio n. 1
0
        public RoleFullDto CreateRole(RoleFullDto roleDto)
        {
            foreach (GrantPermissionDto g in roleDto.GrantPermissions)
            {
                g.PermissionId = g.Permission.Id;
                g.Permission   = null;
            }
            var role = _mapper.Map <Role>(roleDto);
            int res  = _repo.Create(role);

            if (res <= 0)
            {
                return(null);
            }
            return(roleDto);
        }
Esempio n. 2
0
        public RoleFullDto UpdateRole(RoleFullDto roleDto)
        {
            foreach (GrantPermissionDto g in roleDto.GrantPermissions)
            {
                g.PermissionId = g.Permission.Id;
                g.Permission   = null;
            }
            _grantPermissionRepo.DeleteByRoleId(roleDto.Id);
            var role = _mapper.Map <Role>(roleDto);
            int res  = _repo.Update(role);

            if (res <= 0)
            {
                return(null);
            }
            return(roleDto);
        }
Esempio n. 3
0
        public ActionResult <RoleDto> CreateRole([FromBody] RoleFullDto roleFull)
        {
            var roleFullDto = _roleService.CreateRole(roleFull);

            if (roleFullDto == null)
            {
                List <string> errorMessage = new List <string>();
                errorMessage.Add("Đã phát sinh lỗi, vui lòng thử lại");
                return(BadRequest(new ResponseDto(errorMessage, 500, roleFullDto)));
            }
            List <string> successMessage = new List <string>();

            successMessage.Add("Thêm thông tin thành công");
            var responseDto = new ResponseDto(successMessage, 200, roleFullDto);

            return(Ok(responseDto));
        }