Beispiel #1
0
        public async Task <Result <HttpResponse> > UpdatePermission(PermissionDto permissionDto)
        {
            try
            {
                var exists = await _unitOfWork.PermissionRepository.ExistAsync(x => x.Id == permissionDto.Id);

                if (!exists)
                {
                    return(HttpResponseHelper.NewResult(HttpStatusCode.Conflict, HttpResponseHelper.NewHttpResponse(error: "The permission doesn't exist.")));
                }

                var permissionTypeExist = await _unitOfWork.PermissionTypeRepository.ExistAsync(x => x.Id == permissionDto.PermissionType.Id);

                if (!permissionTypeExist)
                {
                    return(HttpResponseHelper.NewResult(HttpStatusCode.Conflict, HttpResponseHelper.NewHttpResponse(error: "The permission type doesn't exist.")));
                }

                var permission = _mapper.Map <Permission>(permissionDto);
                await _unitOfWork.PermissionRepository.UpdateAsync(permission);

                await _unitOfWork.SaveAsync();

                return(HttpResponseHelper.NewResult(HttpStatusCode.OK, HttpResponseHelper.NewHttpResponse("The permission was updated it", success: true)));
            }
            catch (Exception e)
            {
                return(HttpResponseHelper.NewResult(HttpStatusCode.InternalServerError, HttpResponseHelper.NewHttpResponse(error: e.Message)));
            }
        }
Beispiel #2
0
        public async Task <Result <HttpResponse> > AddPermission(PermissionDto permissionDto)
        {
            try
            {
                var permission     = _mapper.Map <Permission>(permissionDto);
                var permissionType = _unitOfWork.PermissionTypeRepository.GetByIdAsync(permission.PermissionType.Id).Result;

                if (permissionType != null)
                {
                    permission.PermissionType = permissionType;
                }

                await _unitOfWork.PermissionRepository.AddAsync(permission);

                await _unitOfWork.SaveAsync();

                return(HttpResponseHelper.NewResult(HttpStatusCode.Created, HttpResponseHelper.NewHttpResponse("New permission added", success: true)));
            }
            catch (Exception e)
            {
                return(HttpResponseHelper.NewResult(HttpStatusCode.InternalServerError, HttpResponseHelper.NewHttpResponse(error: e.Message)));
            }
        }
        public async Task <Result <HttpResponse> > DeletePermissionType(int permissionTypeId)
        {
            try
            {
                var exists = await _unitOfWork.PermissionTypeRepository.ExistAsync(x => x.Id == permissionTypeId);

                if (!exists)
                {
                    return(HttpResponseHelper.NewResult(HttpStatusCode.BadRequest, HttpResponseHelper.NewHttpResponse(error: "The permission type doesn't exist.")));
                }

                var permissionType = await _unitOfWork.PermissionTypeRepository.GetByIdAsync(permissionTypeId);

                await _unitOfWork.PermissionTypeRepository.DeleteAsync(permissionType);

                await _unitOfWork.SaveAsync();

                return(HttpResponseHelper.NewResult(HttpStatusCode.OK, HttpResponseHelper.NewHttpResponse(message: "The permission type was deleted it.", success: true)));
            }
            catch (Exception e)
            {
                return(HttpResponseHelper.NewResult(HttpStatusCode.InternalServerError, HttpResponseHelper.NewHttpResponse(error: e.Message)));
            }
        }
        public async Task <Result <HttpResponse> > AddPermissionType(PermissionTypeDto permissionTypeDto)
        {
            try
            {
                var exists = await _unitOfWork.PermissionTypeRepository.ExistAsync(x => x.Id == permissionTypeDto.Id);

                if (exists)
                {
                    return(HttpResponseHelper.NewResult(HttpStatusCode.Conflict, HttpResponseHelper.NewHttpResponse(error: "The permission type already exist.")));
                }

                var permissionType = _mapper.Map <PermissionType>(permissionTypeDto);

                await _unitOfWork.PermissionTypeRepository.AddAsync(permissionType);

                await _unitOfWork.SaveAsync();

                return(HttpResponseHelper.NewResult(HttpStatusCode.Created, HttpResponseHelper.NewHttpResponse("New permission type added", success: true)));
            }
            catch (Exception e)
            {
                return(HttpResponseHelper.NewResult(HttpStatusCode.InternalServerError, HttpResponseHelper.NewHttpResponse(error: e.Message)));
            }
        }