示例#1
0
        public IHttpActionResult NotificationDev([FromBody] CBISMessage cbisMessage)
        {
            try
            {
                if (cbisMessage == null || cbisMessage.Data == null)
                {
                    throw new Exception("Payload is empty");
                }

                List <CBISResult> lstCBISResult = new List <CBISResult>();
                lstCBISResult.Add(new CBISResult()
                {
                    Id = "111", ResultType = "E_UNPROCESSABLE_RECORD"
                });
                lstCBISResult.Add(new CBISResult()
                {
                    Id = "111", ResultType = "E_UNPROCESSABLE_RECORD"
                });

                Dictionary <string, string> dicVer = new Dictionary <string, string>();
                dicVer.Add("Person", "1.0.0");

                CBISMessage cbisMessage_Response = new CBISMessage
                {
                    CbInstitutionId = cbisMessage.CbInstitutionId,
                    EventName       = cbisMessage.EventName,
                    MessageId       = cbisMessage.MessageId,
                    MessageType     = "NotificationResponse",
                    Model           = "CBISResult",
                    Origin          = "Tads",
                    Version         = dicVer,
                    Data            = JToken.FromObject(lstCBISResult)
                };

                return(Ok(cbisMessage_Response));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#2
0
        public IHttpActionResult Notification([FromBody] CBISMessage cbisMessage)
        {
            try
            {
                if (cbisMessage == null || cbisMessage.Data == null)
                {
                    throw new Exception("Payload is empty");
                }

                //Store incoming request to  application variable
                Dictionary <string, string> lstRequests = HttpContext.Current.Application["AckReq"] == null ? new Dictionary <string, string>() : (Dictionary <string, string>)HttpContext.Current.Application["AckReq"];
                lstRequests.Add(cbisMessage.MessageId, cbisMessage.ToString());
                HttpContext.Current.Application["AckReq"] = lstRequests;

                JToken        token     = cbisMessage.Data;
                List <Person> lstPerson = new List <Person>();

                if (token is JArray)
                {
                    lstPerson = token.ToObject <List <Person> >();
                }
                else if (token is JObject)
                {
                    lstPerson.Add(token.ToObject <Person>());
                }

                List <Applicant>  applicants    = new List <Applicant>();
                List <CBISResult> lstCBISResult = new List <CBISResult>();

                foreach (Person mem in lstPerson)
                {
                    if (mem != null)
                    {
                        Applicant applicant = new Applicant();
                        applicant.FirstName  = mem.FirstName;
                        applicant.LastName   = mem.LastName;
                        applicant.MiddleName = mem.MiddleName;
                        applicant.Gender     = mem.Gender;
                        applicant.DOB        = mem.BirthDate.ToString();

                        if (mem.Households != null && mem.Households.Count > 0)
                        {
                            Household houseHold = mem.Households[0];
                            applicant.HouseholdName = houseHold.Name;
                            if (houseHold.Phones != null && houseHold.Phones.Count > 0)
                            {
                                applicant.HouseholdPhone = houseHold.Phones[0].Number;
                            }
                            if (houseHold.EmailAddresses != null && houseHold.EmailAddresses.Count > 0)
                            {
                                applicant.HouseholdEmail = houseHold.EmailAddresses[0].EmailId;
                            }
                        }

                        if (mem.Grade != null)
                        {
                            applicant.Grade = mem.Grade.Name;
                        }

                        List <string> errors = this.ValidateData(applicant);
                        if (errors.Count > 0)
                        {
                            lstCBISResult.Add(new CBISResult
                            {
                                Id         = mem.PersonId,
                                ResultType = "E_UNPROCESSABLE_RECORD",
                                Errors     = errors
                            });
                        }
                        else
                        {
                            applicants.Add(applicant);

                            lstCBISResult.Add(new CBISResult
                            {
                                Id         = mem.PersonId,
                                ResultType = "SUCCESS"
                            });
                        }
                    }
                }

                if (!DBHelper.InsertApplicantstoDB(applicants))
                {
                    throw new Exception("DB acess failed");
                }

                CBISMessage cbisMessage_Response = new CBISMessage
                {
                    CbInstitutionId = cbisMessage.CbInstitutionId,
                    EventName       = cbisMessage.EventName,
                    MessageId       = cbisMessage.MessageId,
                    MessageType     = "NotificationResponse",
                    Model           = "CBISResult",
                    Origin          = "Tads",
                    Data            = JToken.FromObject(lstCBISResult)
                };

                return(Ok(cbisMessage_Response));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }