Example #1
0
        public async Task <SecretSantaGroup> CreateSecretSantaGroup(SecretSantaGroup secretSantaGroup)
        {
            try
            {
                var content  = new StringContent(JsonConvert.SerializeObject(secretSantaGroup), Encoding.UTF8, "application/json");
                var response = await _client.PostAsync("secretsanta/group", content);

                if (!response.IsSuccessStatusCode)
                {
                    var errorMessageString = await response.Content.ReadAsStringAsync();

                    var errorMessage = JsonConvert.DeserializeObject <BrobotServiceError>(errorMessageString);
                    throw new BrobotServiceException((int)response.StatusCode, errorMessage.Message, $"Failed to create secret santa group {secretSantaGroup.Name}");
                }

                var newSecretSantaGroupString = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <SecretSantaGroup>(newSecretSantaGroupString));
            }
            catch (BrobotServiceException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Failed to create secret santa group {secretSantaGroup.Name}");
                throw new BrobotServiceException($"Failed to create secret santa group {secretSantaGroup.Name}", ex);
            }
        }
Example #2
0
        private async Task CreateGroup(params string[] args)
        {
            if (args.Length < 1 || args.Length > 2)
            {
                await ReplyAsync("Invalid arguments. Supply a group name and optional check past year");

                return;
            }

            var checkPastYear = false;

            if (args.Length == 2)
            {
                if (!bool.TryParse(args[1], out checkPastYear))
                {
                    await ReplyAsync($"Unable to parse {args[1]} for use past year value. Use true or false");
                }
            }

            var secretSantaGroup = new SecretSantaGroup
            {
                Name = args[0],
                CheckPastYearPairings = checkPastYear
            };

            var newSecretSantaGroup = await BrobotService.CreateSecretSantaGroup(secretSantaGroup);

            await ReplyAsync($"Created group {newSecretSantaGroup.Name} with an ID of {newSecretSantaGroup.SecretSantaGroupId}");
        }