コード例 #1
0
        // POST: api/Email
        public IHttpActionResult Post(EmailRequest emailRequest)
        {
            try
            {
                //Build the request model for the service to send the email
                PigeonRequest  pigeonRequest  = EmailFactory.CreatePigeonRequest(emailRequest);
                PigeonResponse pigeonResponse = _emailProvider.SendAFitPigeon(pigeonRequest);

                if (pigeonResponse.Success)
                {
                    //Create the Api response for the successful post request
                    EmailResponse emailResponse = EmailFactory.CreateEmailResponse(pigeonResponse);

                    //Save to database if the email is sent successfully
                    _emailSavingService = new EmailSavingService(_commonProvider, _databaseRepoProvider,
                                                                 emailRequest, emailResponse);

                    //request = CommonUtility.SerializeObject(emailRequest);
                    //response = CommonUtility.SerializeObject(emailResponse);
                    //var isSaved = databaseStuff.SaveaSomethingAwesome(request, response, 1, 2);

                    return(Ok(emailResponse));
                }
                else
                {
                    return(BadRequest("Response was not a success: " + pigeonResponse.Message));
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #2
0
        //[PrincipalPermission(SecurityAction.Demand, Role = "admin")]
        public EmailResponse NotifymeThankyoubyEmail(EmailRequest emailRequest)
        {
            EmailResponse emailResponse = new EmailResponse();
            DatabaseStuff databaseStuff = new DatabaseStuff();
            string        request, response;

            try
            {
                #region for wcf basic auth services
                var hostIdentity    = WindowsIdentity.GetCurrent().Name;
                var primaryIdentity = ServiceSecurityContext.Current.PrimaryIdentity.Name;
                var windowsIdentity = ServiceSecurityContext.Current.WindowsIdentity.Name;
                var threadIdentity  = Thread.CurrentPrincipal.Identity.Name;
                //var isAdmin = Thread.CurrentPrincipal.IsInRole("admin");
                #endregion

                var pigeonRequest = EmailFactory.CreatePigeonRequest(emailRequest);

                var pigeonResponse = notifyByPigeon.SendAFitPigeon(pigeonRequest);

                if (pigeonResponse.Success)
                {
                    emailResponse = EmailFactory.CreateEmailResponse(pigeonResponse);

                    request  = CommonUtility.SerializeObject(emailRequest);
                    response = CommonUtility.SerializeObject(emailResponse);

                    var isSaved = databaseStuff.SaveaSomethingAwesome(request, response, 1);
                }
            }
            catch (Exception ex)
            {
                emailResponse.Success           = false;
                emailResponse.Message           = "An error has occurred: " + ex.Message;
                emailResponse.SubmittedDateTime = null;
            }

            return(emailResponse);
        }