コード例 #1
0
ファイル: Schema.cs プロジェクト: the-orb/orb.net
        public override object MutateAndGetPayload(
            MutationInputs inputs,
            ResolveFieldContext <object> context
            )
        {
            Database.RemoveTodo(
                Node.FromGlobalId(inputs.Get <string>("id")).Id
                );

            return(new
            {
                Viewer = Database.GetViewer(),
                deletedTodoId = inputs.Get <string>("id"),
            });
        }
コード例 #2
0
        public override async Task <object> MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context)
        {
            var organizationId = inputs.Get <int>("organizationId");
            var name           = inputs.Get <string>("name");
            var pipelineIds    = inputs.Get("pipelineIds", new object[0]).Cast <int>().ToList();
            var organization   = _organizationService.GetOrganization(organizationId);
            var pipelines      = _pipelineService.GetPipelines().Where(x => pipelineIds.Any(z => z == x.Id)).ToList();
            var userContext    = context.UserContext.As <Context>();
            var newPipelines   = new List <OnboardingPipeline>();
            var token          = userContext.HttpContext.Session.GetString("OAuthToken");

            if (token == null)
            {
                throw new NullReferenceException("OAuthToken is null");
            }

            _client.Credentials = new Credentials(token);

            foreach (var pipeline in pipelines)
            {
                var newOnboardingSteps = new List <OnboardingStep>();

                foreach (var step in pipeline.OnboardingSteps)
                {
                    var newStep = await GetOnboardingStep(organization, step);

                    newOnboardingSteps.Add(newStep);
                }

                newPipelines.Add(new OnboardingPipeline
                {
                    Name            = pipeline.Name,
                    OnboardingSteps = newOnboardingSteps,
                });
            }
            var process = new OnboardingProcess
            {
                Name                = name,
                Organization        = organization,
                OnboardingPipelines = newPipelines
            };

            _processService.Add(process);

            return(new {
                organization
            });
        }
コード例 #3
0
        public override async Task <object> MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context)
        {
            var userId   = inputs.Get <string>("userId");
            var token    = inputs.Get <string>("token");
            var password = inputs.Get <string>("password");
            var user     = await _userManager.FindByIdAsync(userId);

            var result = await _userManager.ResetPasswordAsync(user, token, password);

            foreach (var identityError in result.Errors)
            {
                _validationProvider.AddError("_error", identityError.Description);
            }

            return(null);
        }
コード例 #4
0
ファイル: Mutation.cs プロジェクト: ko-au/relay
        public override object MutateAndGetPayload(
            MutationInputs inputs,
            IResolveFieldContext <object> context
            )
        {
            var todo = Database.AddTodo(inputs.Get <string>("text"));

            return(new
            {
                TodoEdge = new Edge <Todo>
                {
                    Node = todo,
                    Cursor = ConnectionUtils.CursorForObjectInConnection(Database.GetTodos(), todo)
                },
                Viewer = Database.GetViewer(),
            });
        }
コード例 #5
0
        public override object MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context)
        {
            //var organizationId = inputs.Get<int>("organizationId");
            //var steps = inputs.Get("steps", new object[0]).Cast<string>().ToList();

            //var organization = _organizationService.GetOrganization(organizationId);

            //foreach (var step in steps)
            //{
            //    organization.OnboardingPipelines.Add(new OnboardingStep { Step = step });
            //}

            //_organizationService.Update(organization);

            //return organization;
            return(null);
        }
コード例 #6
0
        public override object MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context)
        {
            var cart = _cartService.LoadOrCreateCart(_cartService.DefaultCartName);

            AddToCartResult result = _cartService.AddToCart(cart, inputs.Get <string>("code"), inputs.Get <decimal>("quantity", 1m));

            if (!result.EntriesAddedToCart)
            {
                context.Errors.AddRange(result.ValidationMessages.Select(m => new ExecutionError(m)));
                return(null);
            }

            _orderRepository.Save(cart);
            _recommendationService.TrackCartAsync(_httpContextBase.Invoke()).Wait();

            LargeCartViewModel largeCartViewModel = _cartViewModelFactory.CreateLargeCartViewModel(cart);

            return(new { Cart = largeCartViewModel });
        }
コード例 #7
0
        public override async Task <object> MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context)
        {
            var userName = inputs.Get <string>("userName");

            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                _validationProvider.AddError("_error", "Unsuccessful login with service.");

                return(null);
            }
            var email = info.Principal.FindFirstValue(ClaimTypes.Email);

            var user = new ApplicationUser
            {
                UserName = userName,
                Email    = email
            };

            var result = await _userManager.CreateAsync(user);

            if (result.Succeeded)
            {
                result = await _userManager.AddLoginAsync(user, info);

                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, true);

                    _logger.LogInformation(6, $"User created an account using {info.LoginProvider} provider.");
                }
            }

            foreach (var identityError in result.Errors)
            {
                _validationProvider.AddError("_error", identityError.Description);
            }

            return(null);
        }
コード例 #8
0
        public override object MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context)
        {
            var audioId           = inputs.Get <int?>("audioId");
            var reason            = inputs.Get <string>("reason");
            var additionalDetails = inputs.Get <string>("additionalDetails");

            var flag = new Models.Flag
            {
                AudioId           = audioId,
                Reason            = reason,
                AdditionalDetails = additionalDetails,
            };

            _flagService.Add(flag);

            return(new
            {
                flag
            });
        }
コード例 #9
0
        public override async Task <object> MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context)
        {
            var pipelineId       = inputs.Get <int>("pipelineId");
            var memberId         = inputs.Get <int?>("memberId");
            var organizationName = inputs.Get <string>("organizationName");
            var name             = inputs.Get <string>("name");
            var pipeline         = _pipelineService.GetPipeline(pipelineId);
            var userContext      = context.UserContext.As <Context>();
            var token            = userContext.HttpContext.Session.GetString("OAuthToken");

            if (token == null)
            {
                throw new NullReferenceException("OAuthToken is null");
            }

            _client.Credentials = new Credentials(token);

            var newIssue = new NewIssue(name);

            if (memberId.HasValue)
            {
                var member = _memberService.GetMember(memberId.Value);

                newIssue.Assignees.Add(member.Name);
            }

            var issue = await _client.Issue.Create(organizationName, Constants.RepositoryName, newIssue);

            pipeline.OnboardingSteps.Add(new OnboardingStep
            {
                Id          = issue.Id,
                Name        = name,
                IssueNumber = issue.Number
            });

            _pipelineService.Update(pipeline);

            return(new {
                pipeline
            });
        }
コード例 #10
0
        public override object MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context)
        {
            ICart cart = _cartService.LoadCart(_cartService.DefaultCartName);

            _cartService.ChangeCartItem(
                cart,
                inputs.Get <int>("shipmentId"),
                inputs.Get <string>("code"),
                inputs.Get <decimal>("quantity"),
                inputs.Get <string>("size"),
                inputs.Get <string>("newSize"),
                inputs.Get <string>("displayName"));

            _orderRepository.Save(cart);

            _recommendationService.TrackCartAsync(_httpContextBase.Invoke()).Wait();

            LargeCartViewModel largeCartViewModel = _cartViewModelFactory.CreateLargeCartViewModel(cart);

            return(new { Cart = largeCartViewModel });
        }
コード例 #11
0
        public override object MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context)
        {
            var body = inputs.Get <string>("body");
            var originalCommentId = inputs.Get <int?>("originalCommentId");
            var audioId           = inputs.Get <int>("audioId");
            var user    = context.UserContext.As <Context>().CurrentUser;
            var comment = new Models.Comment
            {
                UserId            = user.Id,
                Body              = body,
                AudioId           = audioId,
                OriginalCommentId = originalCommentId
            };

            _commentService.Add(comment);

            return(new
            {
                comment
            });
        }
コード例 #12
0
        public override async Task <object> MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context)
        {
            var email = inputs.Get <string>("email");

            var user = await _userManager.FindByEmailAsync(email);

            if (user == null)
            {
                _validationProvider.AddError("_error", "We couldn't find that email address");

                return(null);
            }

            var code = await _userManager.GeneratePasswordResetTokenAsync(user);

            var passwordResetToken = System.Web.HttpUtility.UrlEncode(code);

            return(new
            {
                user,
                passwordResetToken
            });
        }
コード例 #13
0
        public override object MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context)
        {
            var name             = inputs.Get <string>("name");
            var coverImageName   = inputs.Get <string>("coverImageName");
            var liveStreamUrl    = inputs.Get <string>("liveStreamUrl");
            var websiteUrl       = inputs.Get <string>("websiteUrl");
            var country          = inputs.Get <string>("country");
            var genreIds         = inputs.Get("genreIds", new object[0]).Cast <string>().ToList();
            var tags             = inputs.Get("tags", new object[0]).Select(x => x.As <Dictionary <string, object> >().ToObject <TagInput>());
            var user             = context.UserContext.As <Context>().CurrentUser;
            var placeholderImage = _cloudStorage.CloudBlobContainers[CloudStorageType.AppImage].GetBlockBlobReference(Audio.Image.PlaceholderImageName);

            var liveStream = new Models.LiveStream
            {
                CoverImageName = coverImageName,
                Name           = name,
                //  LiveStreamUrl = liveStreamUrl,
                WebsiteUrl = websiteUrl,
                Country    = country,
            };

            //foreach (var genreId in genreIds)
            //{
            //    liveStream.AudioGenres.Add(new AudioGenre { GenreId = genreId });
            //}

            foreach (var tag in tags)
            {
                Tag.Tag tagModel;

                if (tag.Tag != null)
                {
                    tagModel = new Tag.Tag
                    {
                        Name = tag.Tag
                    };
                }
                else if (tag.Id.HasValue)
                {
                    var existingTag = _tagService.GetTag(tag.Id.Value);

                    tagModel = existingTag;
                }
                else
                {
                    throw new Exception("A tag id or name must be supplied");
                }

                if (liveStream.AudioTags.All(x => x.Tag.Id != tagModel.Id))
                {
                    liveStream.AudioTags.Add(new AudioTag {
                        Tag = tagModel
                    });
                }
            }

            _liveStreamService.Add(liveStream);

            return(new
            {
                liveStream
            });
        }
コード例 #14
0
        public override object MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context)
        {
            var memberIds = inputs.Get("memberIds", new object[0]).Cast <int>().ToList();

            return(null);
        }