Exemplo n.º 1
0
        public IHttpActionResult InviteToGroup([FromUri] int groupId, [FromUri] string finderFlag, [FromBody] User person)
        {
            if (!ModelState.IsValid)
            {
                var errors    = ModelState.Values.SelectMany(val => val.Errors).Aggregate("", (current, err) => current + err.Exception.Message);
                var dataError = new ApiErrorDto("CreateInvitation Data Invalid", new InvalidOperationException("Invalid CreateInvitation Data " + errors));
                throw new HttpResponseException(dataError.HttpResponseMessage);
            }

            return(Authorized(token =>
            {
                try
                {
                    _finderService.InviteToGroup(token, groupId, person, finderFlag);

                    // Call Analytics
                    var props = new EventProperties {
                        { "InvitationToEmail", person.email }
                    };
                    _analyticsService.Track(AuthenticationRepository.GetContactId(token).ToString(), "HostInvitationSent", props);

                    return (Ok());
                }
                catch (ValidationException e)
                {
                    var error = new ApiErrorDto("Not authorized to send invitations of this type", e, HttpStatusCode.Forbidden);
                    throw new HttpResponseException(error.HttpResponseMessage);
                }
                catch (Exception e)
                {
                    _logger.Error($"Could not create invitation to recipient {person.firstName + " " + person.lastName} ({person.email}) for group {3}", e);
                    var apiError = new ApiErrorDto("CreateInvitation Failed", e, HttpStatusCode.InternalServerError);
                    throw new HttpResponseException(apiError.HttpResponseMessage);
                }
            }));
        }