Пример #1
0
        public async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log)
        {
            var invitation = JsonConvert.DeserializeObject <Invitation>(await req.ReadAsStringAsync());

            var validator        = new InvitationValidator(Repository);
            var validatorResults = validator.Validate(invitation);

            if (!validatorResults.IsValid)
            {
                return(new BadRequestObjectResult(validatorResults.Errors));
            }

            await invitation.UpdateAsync(Repository);

            return(new JsonResult(invitation));
        }
Пример #2
0
        public async Task <IActionResult> Post([FromBody] InvitationDto invitationDto)
        {
            var validator = new InvitationValidator();
            var result    = validator.Validate(invitationDto);

            if (result.Errors.Count > 0)
            {
                return(new BadRequestObjectResult(new {
                    ErrorCode = result.Errors.First().ErrorCode,
                    Message = result.Errors.First().ErrorMessage
                }));
            }

            try
            {
                var invitationsCountSent = _invitationService.GetInvitationsCountPerApiId(4);

                if (invitationsCountSent + invitationDto.PhoneNumbers.Length > 128)
                {
                    return(new BadRequestObjectResult(new
                    {
                        ErrorCode = "403",
                        ErrorMessage = "BAD_REQUEST PHONE_NUMBERS_INVALID: Too much phone numbers, should be less or equal to 128 per day"
                    }));
                }

                var duplicatesPhoneNumbers = await _invitationService.CheckDuplicatePhones(invitationDto.PhoneNumbers);

                if (duplicatesPhoneNumbers.Count() > 0)
                {
                    invitationDto.PhoneNumbers = invitationDto.PhoneNumbers.Except(duplicatesPhoneNumbers).ToArray();
                }

                await _invitationService.SendInvites(invitationDto.PhoneNumbers, 7);
            }
            catch (Exception ex)
            {
                return(StatusCode(500, "INTERNAL " + ex.Source + ": " + ex.Message));
            }

            return(Ok());
        }