Beispiel #1
0
        public async Task <IActionResult> Post([FromBody] WeekAddDto week)
        {
            try
            {
                var id = await _weekService.AddAsync(week);

                var saveResult = await _weekService.SaveAsync();

                if (saveResult == 0)
                {
                    _logger.LogError("Unable to add a new week at this time");
                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }

                return(Ok(id));
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "An error occurred while trying to add a new week");
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Beispiel #2
0
        public SandwichClubMutation(IScSession session,
                                    IUserService userService,
                                    IPaymentService paymentService,
                                    IWeekService weekService)
        {
            Name = "Mutation";
            FieldAsync <WeekType>(
                "subscribeToWeek",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "userId", Description = "UserId of the user"
            },
                    new QueryArgument <IntGraphType> {
                Name = "weekId", Description = "WeekId of the week"
            },
                    new QueryArgument <IntGraphType> {
                Name = "slices", Description = "WeekId of the week"
            }
                    ),
                resolve: async context =>
            {
                var userId = context.GetArgument <int>("userId");
                var weekId = context.GetArgument <int>("weekId");
                var slices = context.GetArgument <int>("slices");

                return(await weekService.SubscibeToWeek(weekId, userId, slices));
            }
                );

            FieldAsync <PaymentType>(
                "markAllWeeksPaidForUser",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "userId", Description = "UserId to mark weeks paid for"
            }
                    ),
                resolve: async context =>
            {
                var userId = context.GetArgument <int>("userId");

                return(await paymentService.PayOwedForUser(userId));
            }
                );

            FieldAsync <WeekType>(
                "updateWeek",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "weekId", Description = "WeekId of the week"
            },
                    new QueryArgument <IntGraphType> {
                Name = "shopperId", Description = "UserId of the shopper"
            },
                    new QueryArgument <FloatGraphType> {
                Name = "cost", Description = "cost of the week"
            }
                    ),
                resolve: async context =>
            {
                var shopperId = context.GetArgument <int?>("shopperId");
                var weekId    = context.GetArgument <int>("weekId");
                var cost      = context.GetArgument <double?>("cost");

                return(await weekService.SaveAsync(new Week
                {
                    WeekId = weekId,
                    ShopperUserId = shopperId,
                    Cost = cost ?? 0,
                }));
            }
                );

            Field <UserType>(
                "updateMe",
                arguments: new QueryArguments(
                    new QueryArgument <StringGraphType> {
                Name = "bankName", Description = "The name of the users week bank"
            },
                    new QueryArgument <StringGraphType> {
                Name = "bankDetails", Description = "Details for making payments"
            },
                    new QueryArgument <BooleanGraphType> {
                Name = "shopper", Description = "Set as shopper"
            }
                    ),
                resolve: (context) =>
            {
                var user = session.CurrentUser;

                var bankName    = context.GetArgument <string>("bankName");
                var bankDetails = context.GetArgument <string>("bankDetails");
                var shopper     = context.GetArgument <bool?>("shopper");

                if (bankName != null)
                {
                    user.BankName = bankName;
                }
                if (bankDetails != null)
                {
                    user.BankDetails = bankDetails;
                }
                if (shopper != null)
                {
                    user.Shopper = shopper.Value;
                }

                return(userService.SaveAsync(user));
            }
                );
        }