Exemple #1
0
        public virtual async Task <GenericResponse <TDto> > ReadAsync(GenericRequest <TDtoType> request)
        {
            var response = new GenericResponse <TDto>();

            var dto = await _repository.ReadAsync(request.Data);

            if (dto == null)
            {
                response.AddErrorMessage(GeneralResource.Item_NotFound);
                return(response);
            }

            response.Data = dto;

            return(response);
        }
Exemple #2
0
        public async Task <GenericResponse <object> > RemoveRole(AddRemoveRoleDto removeRoleDto)
        {
            try
            {
                var user = await _userRepository.FindById(removeRoleDto.UserId);

                if (user is null)
                {
                    return(new GenericResponse <object>(new object(), false).AddErrorMessage("User doesn't exists"));
                }

                var role = await _roleRepository.FindById(removeRoleDto.RoleId);

                var removed = user.RemoveRole(role);

                await _userRepository.UnitOfWork.Commit();

                var response = new GenericResponse <object>(new object(), removed);
                if (removed)
                {
                    response.AddInfoMessage("Successfully removed");
                }
                else
                {
                    response.AddErrorMessage("Cannot remove - check if role exists");
                }

                return(response);
            }
            catch (Exception)
            {
                await _userRepository.UnitOfWork.Rollback();

                throw;
            }
        }