示例#1
0
        public int UpdateControlNumber(PolicyRenewalModel renewal)
        {
            if (!String.IsNullOrEmpty(renewal.ControlNumber))
            {
                var sSQL = @"UPDATE PD SET InsuranceNumber = @InsuranceNumber, PolicyStage = N'R', ValidityFrom = GETDATE()
                                FROM tblControlNumber CN
                                INNER JOIN tblPaymentDetails PD ON CN.PaymentId = PD.PaymentID
                                WHERE CN.ValidityTo IS NULL
                                AND CN.ControlNumber = @ControlNumber;";

                SqlParameter[] parameters =
                {
                    new SqlParameter("@ControlNumber",   renewal.ControlNumber),
                    new SqlParameter("@InsuranceNumber", renewal.CHFID)
                };

                try
                {
                    var dh = new DB.SqlServer.DataHelper.DataHelper(_configuration);
                    dh.Execute(sSQL, parameters, CommandType.Text);
                }
                catch (Exception ex)
                {
                    return((int)Errors.Renewal.CouldNotUpdateControlNumber);
                }

                //}
            }

            return((int)Errors.Renewal.Accepted);
        }
        public int Post(PolicyRenewalModel policy)
        {
            int response;

            response = policyRenewalRepository.Post(policy);

            return(response);
        }
示例#3
0
        public void CreatePremium(PolicyRenewalModel renewal)
        {
            ImisPayment payment      = new ImisPayment(_configuration, _hostingEnvironment, _loggerFactory);
            var         paymentLogic = new PaymentLogic(_configuration, _hostingEnvironment, _loggerFactory);

            if (_configuration.GetValue <bool>("PaymentGateWay:CreatePremiumOnPaymentReceived"))
            {
                int paymentId = payment.GetPaymentId(renewal.ControlNumber);
                _ = paymentLogic.CreatePremium(paymentId);
            }
        }
        public IActionResult Post([FromBody] PolicyRenewalModel model)
        {
            int response;

            try
            {
                response = _imisModules.GetPolicyModule().GetPolicyRenewalLogic().Post(model);
            }
            catch (ValidationException e)
            {
                throw new BusinessException(e.Message);
            }

            return(Ok(response));
        }
        public IActionResult Post([FromBody] PolicyRenewalModel model)
        {
            int response;

            try
            {
                response = _imisModules.GetPolicyModule().GetPolicyRenewalLogic().Post(model);
            }
            catch (ValidationException e)
            {
                return(BadRequest(new { error = new { message = e.Message, value = e.Value } }));
            }

            return(Ok(response));
        }
        // TODO Change the RV assignment codes. It should be on the list for better understanding
        public int Post(PolicyRenewalModel policy)
        {
            int RV = 2;

            try
            {
                var policyRenew = policy.GetPolicy();
                var XML         = policyRenew.XMLSerialize();

                var fromPhoneRenewalDir         = _configuration["AppSettings:FromPhone_Renewal"] + Path.DirectorySeparatorChar;
                var fromPhoneRenewalRejectedDir = _configuration["AppSettings:FromPhone_Renewal_Rejected"] + Path.DirectorySeparatorChar;

                var fileName = "RenPol_" + policy.Date + "_" + policy.CHFID + "_" + policy.ReceiptNo + ".xml";

                var xmldoc = new XmlDocument();
                xmldoc.InnerXml = XML;

                bool ifSaved = false;

                try
                {
                    if (!Directory.Exists(fromPhoneRenewalDir))
                    {
                        Directory.CreateDirectory(fromPhoneRenewalDir);
                    }
                    if (!Directory.Exists(fromPhoneRenewalRejectedDir))
                    {
                        Directory.CreateDirectory(fromPhoneRenewalRejectedDir);
                    }

                    xmldoc.Save(fromPhoneRenewalDir + fileName);
                    ifSaved = true;
                }
                catch (Exception e)
                {
                    return(RV);
                }

                if (ifSaved)
                {
                    using (var imisContext = new ImisDB())
                    {
                        var xmlParameter = new SqlParameter("@XML", XML)
                        {
                            DbType = DbType.Xml
                        };
                        var returnParameter   = OutputParameter.CreateOutputParameter("@RV", SqlDbType.Int);
                        var fileNameParameter = new SqlParameter("@FileName", SqlDbType.NVarChar, 200);
                        fileNameParameter.Value = fileName;

                        var sql = "exec @RV = uspIsValidRenewal @FileName, @XML";

                        DbConnection connection = imisContext.Database.GetDbConnection();

                        using (DbCommand cmd = connection.CreateCommand())
                        {
                            cmd.CommandText = sql;

                            cmd.Parameters.AddRange(new[] { fileNameParameter, xmlParameter, returnParameter });

                            if (connection.State.Equals(ConnectionState.Closed))
                            {
                                connection.Open();
                            }

                            using (var reader = cmd.ExecuteReader())
                            {
                                // Displaying errors in the Stored Procedure in Debug mode
                                //do
                                //{
                                //    while (reader.Read())
                                //    {
                                //        Debug.WriteLine("Error/Warning: " + reader.GetValue(0));
                                //    }
                                //} while (reader.NextResult());
                            }
                        }

                        int tempRV = (int)returnParameter.Value;

                        if (tempRV == 0 || tempRV == -4)
                        {
                            RV = 1;
                        }
                        else if (tempRV == -1 || tempRV == -2 || tempRV == -3)
                        {
                            if (File.Exists(fromPhoneRenewalDir + fileName))
                            {
                                File.Move(fromPhoneRenewalDir + fileName, fromPhoneRenewalRejectedDir + fileName);
                            }
                            RV = 0;
                        }
                        else
                        {
                            RV = 2;
                        }
                    }
                }

                return(RV);
            }
            catch (SqlException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#7
0
        // TODO Add a RV for missing EO or previous policy (currently -5)
        public int Post(PolicyRenewalModel policy)
        {
            int RV = (int)Errors.Renewal.Rejected;

            var policyRenew = policy.GetPolicy();
            var XML         = policyRenew.XMLSerialize();

            var fromPhoneRenewalDir         = _configuration["AppSettings:FromPhone_Renewal"] + Path.DirectorySeparatorChar;
            var fromPhoneRenewalRejectedDir = _configuration["AppSettings:FromPhone_Renewal_Rejected"] + Path.DirectorySeparatorChar;

            var fileName = "RenPol_" + policy.Date.ToString(DateTimeFormats.FileNameDateTimeFormat) + "_" + policy.CHFID + "_" + policy.ReceiptNo + ".xml";

            var xmldoc = new XmlDocument();

            xmldoc.InnerXml = XML;

            bool ifSaved = false;

            try
            {
                if (!Directory.Exists(fromPhoneRenewalDir))
                {
                    Directory.CreateDirectory(fromPhoneRenewalDir);
                }
                if (!Directory.Exists(fromPhoneRenewalRejectedDir))
                {
                    Directory.CreateDirectory(fromPhoneRenewalRejectedDir);
                }

                xmldoc.Save(fromPhoneRenewalDir + fileName);
                ifSaved = true;
            }
            catch
            {
                return((int)Errors.Renewal.UnexpectedException);
            }

            if (ifSaved)
            {
                using (var imisContext = new ImisDB())
                {
                    var xmlParameter = new SqlParameter("@XML", XML)
                    {
                        DbType = DbType.Xml
                    };
                    var returnParameter   = OutputParameter.CreateOutputParameter("@RV", SqlDbType.Int);
                    var fileNameParameter = new SqlParameter("@FileName", SqlDbType.NVarChar, 200);
                    fileNameParameter.Value = fileName;

                    var sql = "exec @RV = uspIsValidRenewal @FileName, @XML";

                    DbConnection connection = imisContext.Database.GetDbConnection();

                    using (DbCommand cmd = connection.CreateCommand())
                    {
                        cmd.CommandText = sql;

                        cmd.Parameters.AddRange(new[] { fileNameParameter, xmlParameter, returnParameter });

                        if (connection.State.Equals(ConnectionState.Closed))
                        {
                            connection.Open();
                        }

                        using (var reader = cmd.ExecuteReader())
                        {
                            // Displaying errors in the Stored Procedure in Debug mode
                            do
                            {
                                while (reader.Read())
                                {
                                    Debug.WriteLine("Error/Warning: " + reader.GetValue(0));
                                }
                            } while (reader.NextResult());
                        }
                    }

                    int  tempRV         = (int)returnParameter.Value;
                    bool moveToRejected = false;

                    switch (tempRV)
                    {
                    case 0:
                        RV = (int)Errors.Renewal.Accepted;
                        break;

                    case -2:
                        moveToRejected = true;
                        RV             = (int)Errors.Renewal.GracePeriodExpired;
                        break;

                    case -4:
                        RV = (int)Errors.Renewal.AlreadyAccepted;
                        break;

                    case -1:
                        moveToRejected = true;
                        RV             = (int)Errors.Renewal.UnexpectedException;
                        break;

                    case -5:
                        moveToRejected = true;
                        RV             = (int)Errors.Renewal.Rejected;
                        break;

                    default:
                        moveToRejected = true;
                        RV             = (int)Errors.Renewal.Rejected;
                        break;
                    }

                    if (moveToRejected)
                    {
                        if (File.Exists(fromPhoneRenewalDir + fileName))
                        {
                            File.Move(fromPhoneRenewalDir + fileName, fromPhoneRenewalRejectedDir + fileName);
                        }
                    }
                }
            }

            if (RV == (int)Errors.Renewal.Accepted)
            {
                RV = UpdateControlNumber(policy);

                CreatePremium(policy);
            }

            return(RV);
        }