protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage httpRequestMessage, CancellationToken cancellationToken)
        {
            Security frayteSecurity = new Security();
            string   accountNumber  = string.Empty;
            var      content        = await httpRequestMessage.Content.ReadAsStringAsync();

            try
            {
                if (httpRequestMessage.RequestUri.ToString().Contains("AftershipTracking/ProcessWebHook"))
                {
                    if (!string.IsNullOrEmpty(content))
                    {
                        // send mail to developer
                        Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("AftershipTracking's ProcessWebHook hit."));
                        Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(content));
                        try
                        {
                            AftershipWebhookObject webHookObj = JsonConvert.DeserializeObject <AftershipWebhookObject>(content);
                            if (webHookObj == null)
                            {
                                Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Aftership's obj  not parsed."));

                                DynamicViewBag viewBag = new DynamicViewBag();
                                viewBag.AddValue("Value", content);
                                string template        = File.ReadAllText(AppSettings.EmailServicePath + "/EmailTeamplate/" + "aftershipError.cshtml");
                                var    templateService = new TemplateService();
                                var    EmailBody       = templateService.Parse(template, "", viewBag, null);
                                FrayteEmail.SendMail("*****@*****.**", "", "Aftership's obj  not parsed.", "", "", "");
                            }
                        }
                        catch (Exception ex)
                        {
                            Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Aftership's obj  not parsed."));
                        }
                    }
                    else
                    {
                        Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Aftership's obj  is empty."));
                    }
                }
                return(await base.SendAsync(httpRequestMessage, cancellationToken));
            }
            catch (Exception ex)
            {
                return(httpRequestMessage.CreateResponse(HttpStatusCode.Forbidden, "Json is not valid"));
            }
        }
Example #2
0
        public IHttpActionResult ProcessWebHook(AftershipWebhookObject webHookDetail)
        {
            Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("AfterShip hit"));
            if (webHookDetail != null)
            {
                FrayteResult result = new FrayteResult();
                try
                {
                    dynamic json = Newtonsoft.Json.JsonConvert.SerializeObject(webHookDetail);
                    Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(json));

                    new DirectShipmentRepository().UpdateShipmentStatus(webHookDetail.msg.custom_fields.module_type, webHookDetail.msg.tag, webHookDetail.msg.title);
                    new DirectShipmentRepository().UpdateShipmentDetail(webHookDetail.msg.delivery_time, webHookDetail.msg.shipment_delivery_date, webHookDetail.msg.signed_by, webHookDetail.msg.title, webHookDetail.msg.custom_fields.module_type);
                    Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Status updtaed"));

                    if (webHookDetail.msg.custom_fields.module_type == FrayteShipmentServiceType.DirectBooking)
                    {
                        result = new AftershipTrackingRepository().SendTrackingStatusEmail(webHookDetail);
                    }
                    Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Email sent"));
                }
                catch (Exception ex)
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                }
                if (result.Status)
                {
                    return(Ok(result));
                }
                else
                {
                    return(BadRequest());
                }
            }
            else
            {
                return(BadRequest());
            }
        }