public IActionResult Update([FromBody] Models.Invitation invitation)
        {
            IActionResult result          = null;
            IMapper       mapper          = null;
            IInvitation   innerInvitation = null;

            if (result == null && invitation == null)
            {
                result = BadRequest("Missing invitation data");
            }

            if (result == null && (!invitation.InvitationId.HasValue || invitation.InvitationId.Equals(Guid.Empty)))
            {
                result = BadRequest("Missing id");
            }

            if (result == null && !invitation.EventDate.HasValue)
            {
                result = BadRequest("Missing event date");
            }

            if (result == null && !invitation.RSVPDueDate.HasValue)
            {
                result = BadRequest("Missing RSVP date");
            }

            if (result == null && string.IsNullOrEmpty(invitation.Title))
            {
                result = BadRequest("Missing title");
            }

            if (result == null && string.IsNullOrEmpty(invitation.Invitee))
            {
                result = BadRequest("Missing invitee");
            }

            if (result == null)
            {
                mapper = new Mapper(m_mapperConfiguration);
                using (ILifetimeScope scope = m_container.BeginLifetimeScope())
                {
                    IInvitationFactory factory = scope.Resolve <IInvitationFactory>();
                    innerInvitation = factory.Get(m_settings.Value, invitation.InvitationId.Value);

                    if (innerInvitation == null)
                    {
                        result = NotFound();
                    }
                    else
                    {
                        mapper.Map <Models.Invitation, IInvitation>(invitation, innerInvitation);
                        IInvitationSaver saver = scope.Resolve <IInvitationSaver>();
                        saver.Update(m_settings.Value, innerInvitation);
                        invitation = mapper.Map <Models.Invitation>(innerInvitation);
                        result     = Ok(invitation);
                    }
                }
            }
            return(result);
        }
Example #2
0
        //I want to change this so it returns the final list of initations, but I don't know how.
        public void SendInvitations(Models.Invitation invitation, IList <Models.Friend> friends, double waitTime, int TargetTotalGuests, string message, int limit = 1)
        {
            Console.WriteLine("Sending inviations");
            //List to keep invitations
            var invitationList = new List <Invitation>();

            //max number of people to contact at a time
            Limit = limit;
            //Populate the Friend invitation list
            foreach (var friend in friends)
            {
                Console.WriteLine("Populating Friends");
                var friendInvitation = invitation.Clone(friend);
                Task.Factory.StartNew(() => friendInvitation.SetTimeout(waitTime));
                friendInvitation.invitationStatusChanged += InvitationOnInvitationStatusChanged;
                invitationList.Add(friendInvitation);
            }
            //While we have not reached the target number of people we want to invite, and there are still people
            //pending or not yet sent, do stuff!
            while (invitationList.Count(x => x.Status == InvitationStatus.Yes) != TargetTotalGuests ||
                   invitationList.Count(x => x.Status == InvitationStatus.Pending) != 0 &&
                   invitationList.Count(x => x.Status == InvitationStatus.NotYetSent) != 0)
            {
                //while we have not reached the limit of people we want pending, send messages
                while (invitationList.Count(x => x.Status == InvitationStatus.Pending) != limit)
                {
                    //might want to keep track of priority, but this might work if list is not shuffeled.
                    //find the first person not yet send and send to them.

                    invitationList.First(x => x.Status == InvitationStatus.NotYetSent).SendMessage(message);
                }
            }
        }
Example #3
0
 /// <summary>
 /// Create the invitation object.
 /// </summary>
 /// <returns>Returns the invitation object.</returns>
 private static Models.Invitation CreateInvitation()
 {
     // Set the invitation object.
     Models.Invitation invitation = new Models.Invitation();
     invitation.InvitedUserDisplayName  = InvitedUserDisplayName;
     invitation.InvitedUserEmailAddress = InvitedUserEmailAddress;
     invitation.InviteRedirectUrl       = "https://www.microsoft.com";
     invitation.SendInvitationMessage   = true;
     return(invitation);
 }
Example #4
0
        /// <summary>
        /// Main method.
        /// </summary>
        /// <param name="args">Optional arguments</param>
        static void Main(string[] args)
        {
            Models.Invitation invitation = CreateInvitation();

            Task.Run(async() =>
            {
                // Do any async anything you need here without worry
                await SendInvitationAsync(invitation);
            }).GetAwaiter().GetResult();
        }
Example #5
0
        public async Task <InvitationView> createInvitation([FromBody] Models.Invitation aInvitation, [FromUri] string username)
        {
            aInvitation.username = username;
            string id = await mInvitationsRepo.createInvitation(aInvitation);

            return(new InvitationView
            {
                groupName = aInvitation.groupName,
                groupAdmin = aInvitation.groupAdminName,
                received = aInvitation.date,
                id = id
            });
        }
Example #6
0
        public static async Task SendCustomInvitationAsync(Models.Invitation invitation)
        {
            var apiKey = ConfigurationManager.AppSettings["SendGridAPIKey"];
            var client = new SendGridClient(apiKey);
            var msg    = new SendGridMessage();

            msg.SetFrom(new EmailAddress(fromAddress, "Woodgrove Track"));
            msg.SetSubject("You are invited to join the Woodgrove Track App");

            msg.AddTo(new EmailAddress(invitation.InvitedUserEmailAddress, invitation.InvitedUserDisplayName));

            msg.HtmlContent = "<p>Hi " + invitation.InvitedUserDisplayName + "!<p>Click the link below to joing the Woodgrove Track App</p><p>" + invitation.InviteUrl + "</p>";

            var response = await client.SendEmailAsync(msg);
        }
Example #7
0
        public async System.Threading.Tasks.Task <string> createInvitation(Models.Invitation aInvitation)
        {
            string id = Guid.NewGuid().ToString();

            using (var connection = CreateConnection())
            {
                await connection.OpenAsync();

                var command = connection.CreateCommand();
                command.CommandText = "INSERT INTO Invitations(groupName, invitedUsername, id)" +
                                      "VALUES (?groupName, ?invitedUsername, ?id)";
                command.Parameters.AddWithValue("?groupName", aInvitation.groupName);
                command.Parameters.AddWithValue("?invitedUsername", aInvitation.username);
                command.Parameters.AddWithValue("?id", id);
                await command.ExecuteNonQueryAsync();
            }
            return(id);
        }
Example #8
0
        /// <summary>
        /// Send the guest user invite request.
        /// </summary>
        /// <param name="invitation">Invitation object.</param>
        private static async Task SendInvitationAsync(Models.Invitation invitation)
        {
            string accessToken = GetAccessToken();

            HttpClient httpClient = GetHttpClient(accessToken);

            // Make the invite call.
            HttpContent content = new StringContent(JsonConvert.SerializeObject(invitation));

            content.Headers.Add("ContentType", "application/json");
            var    postResponse   = httpClient.PostAsync(InviteEndPoint, content).Result;
            string serverResponse = postResponse.Content.ReadAsStringAsync().Result;

            Console.WriteLine(serverResponse);

            // Send custom invitation
            await Mail.Invitation.SendCustomInvitationAsync(invitation);

            Console.ReadLine();
        }
 /// <summary>
 /// Add Invitation to Group
 /// </summary>
 /// <param name="organizationId">Id of the organization (required)</param>
 /// <param name="groupId">Id of the group (required)</param>
 /// <param name="invitation">Invitation details</param>
 public async Task <Models.Invitation> CreateAsync(string organizationId, string groupId, Models.Invitation invitation)
 {
     return(await _apiClient.CreateAsync(organizationId, groupId, invitation));
 }