public long AddInvitation(InvitationDTO invitationDto, long userID, string fileName) { var invitation = new Invitation(); invitation.InvitationName = invitationDto.InvitationName; //invitation.InvitationDateTime = DateTime.Now; invitation.InvitationDateTime = invitationDto.InvitationDateTime; invitation.InvitationDescription = invitationDto.InvitationDescription; invitation.TemplateID = invitationDto.TemplateID; invitation.UserID = userID; invitation.icsFile = fileName; _invitationService.Insert(invitation); var inviteesList = AddSelectedInvitees(invitationDto.inviteesData, userID, invitation.InvitationID); SaveChanges(); // Uncomment below code to run Sending email foreach (var item in inviteesList) { var contact = _contactService.GetContactByID(item.ContactID); string url = "http://invitationsbackend.azurewebsites.net/#!/viewInvitationForInvitee/" + invitation.InvitationID + "/" + item.InviteeID; string body = PopulateBody(url); SendHtmlFormattedEmail(contact.ContactEmail, "New Invitation!", body); //sendEmailViaWebApi(invitation.InvitationID, item.InviteeID, contact.ContactEmail, fileName); } // Edit consumed Users in package and send to subscription UpdateUserPackages(invitationDto.ConsumedPackage, userID); return(invitation.InvitationID); }