Exemplo n.º 1
0
        public GetEnquireModel GetEnquire(string chfid)
        {
            GetEnquireModel    response = null;
            List <DetailModel> details  = null;

            using (var imisContext = new ImisDB())
            {
                var chfidParameter = new SqlParameter("@CHFID", chfid)
                {
                    SqlDbType = SqlDbType.VarChar, Size = 12
                };

                var sql = "exec uspAPIGetCoverage @CHFID";

                DbConnection connection = imisContext.Database.GetDbConnection();

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

                    cmd.Parameters.AddRange(new[] { chfidParameter });

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

                    using (var reader = cmd.ExecuteReader())
                    {
                        do
                        {
                            while (reader.Read())
                            {
                                if (response == null)
                                {
                                    response = new GetEnquireModel();
                                    details  = new List <DetailModel>();

                                    response.InsureeName = string.Join(' ', reader["OtherNames"].ToString()) + ' ' + reader["LastName"].ToString();
                                    response.CHFID       = reader["CHFID"].ToString();
                                    response.PhotoPath   = reader["PhotoPath"].ToString();
                                    response.DOB         = reader["DOB"].ToString().ToNullableDatetime();
                                    response.Gender      = reader["Gender"].ToString();
                                }

                                details.Add(new DetailModel
                                {
                                    AntenatalAmountLeft       = reader["AntenatalAmountLeft"].ToString().ToNullableDecimal(),
                                    ConsultationAmountLeft    = reader["ConsultationAmountLeft"].ToString().ToNullableDecimal(),
                                    DeliveryAmountLeft        = reader["DeliveryAmountLeft"].ToString().ToNullableDecimal(),
                                    HospitalizationAmountLeft = reader["HospitalizationAmountLeft"].ToString().ToNullableDecimal(),
                                    SurgeryAmountLeft         = reader["SurgeryAmountLeft"].ToString().ToNullableDecimal(),
                                    TotalAdmissionsLeft       = reader["TotalAdmissionsLeft"].ToString().ToNullableDecimal(),
                                    TotalAntenatalLeft        = reader["TotalAntenatalLeft"].ToString().ToNullableDecimal(),
                                    TotalConsultationsLeft    = reader["TotalConsultationsLeft"].ToString().ToNullableDecimal(),
                                    TotalDelivieriesLeft      = reader["TotalDelivieriesLeft"].ToString().ToNullableDecimal(),
                                    TotalSurgeriesLeft        = reader["TotalSurgeriesLeft"].ToString().ToNullableDecimal(),
                                    TotalVisitsLeft           = reader["TotalVisitsLeft"].ToString().ToNullableDecimal(),
                                    PolicyValue   = reader["PolicyValue"].ToString().ToNullableDecimal(),
                                    EffectiveDate = reader["EffectiveDate"].ToString().ToNullableDatetime(),
                                    ProductCode   = reader["ProductCode"].ToString(),
                                    ProductName   = reader["ProductName"].ToString(),
                                    ExpiryDate    = reader["ExpiryDate"].ToString().ToNullableDatetime(),
                                    Status        = reader["Status"].ToString(),
                                    DedType       = reader["DedType"].ToString().ToNullableFloat(),
                                    Ded1          = reader["Ded1"].ToString().ToNullableDecimal(),
                                    Ded2          = reader["Ded2"].ToString().ToNullableDecimal(),
                                    Ceiling1      = reader["Ceiling1"].ToString().ToNullableDecimal(),
                                    Ceiling2      = reader["Ceiling2"].ToString().ToNullableDecimal(),
                                });
                            }
                        } while (reader.NextResult());
                    }
                }
            }

            if (response != null)
            {
                response.Details = details;
            }

            return(response);
        }
Exemplo n.º 2
0
        public GetEnquireModel GetEnquire(string chfid)
        {
            GetEnquireModel    response = new GetEnquireModel();
            List <DetailModel> details  = new List <DetailModel>();

            try
            {
                using (var imisContext = new ImisDB())
                {
                    var chfidParameter = new SqlParameter("@CHFID", chfid)
                    {
                        SqlDbType = SqlDbType.VarChar, Size = 12
                    };

                    var sql = "exec uspPolicyInquiry @CHFID";

                    DbConnection connection = imisContext.Database.GetDbConnection();

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

                        cmd.Parameters.AddRange(new[] { chfidParameter });

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

                        using (var reader = cmd.ExecuteReader())
                        {
                            do
                            {
                                bool firstValue = true;
                                while (reader.Read())
                                {
                                    if (firstValue)
                                    {
                                        response.CHFID       = reader["CHFID"].ToString();
                                        response.PhotoPath   = reader["PhotoPath"].ToString();
                                        response.InsureeName = reader["InsureeName"].ToString();
                                        response.DOB         = reader["DOB"].ToString();
                                        response.Gender      = reader["Gender"].ToString();

                                        firstValue = false;
                                    }

                                    details.Add(new DetailModel
                                    {
                                        ProductName = reader["ProductName"].ToString(),
                                        ExpiryDate  = reader["ExpiryDate"].ToString(),
                                        Status      = reader["Status"].ToString(),
                                        DedType     = reader["DedType"].ToString().ToNullableFloat(),
                                        Ded1        = reader["Ded1"].ToString().ToNullableDecimal(),
                                        Ded2        = reader["Ded2"].ToString().ToNullableDecimal(),
                                        Ceiling1    = reader["Ceiling1"].ToString().ToNullableDecimal(),
                                        Ceiling2    = reader["Ceiling2"].ToString().ToNullableDecimal(),
                                        ProductCode = reader["ProductCode"].ToString()
                                    });
                                }
                            } while (reader.NextResult());
                        }
                    }
                }

                response.Details = details;

                return(response);
            }
            catch (SqlException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw e;
            }
        }