public NewFamilyResponse Create(EnrolFamilyModel model, int userId, int officerId)
        {
            var enrolFamily = model.GetEnrolmentFromModel();

            enrolFamily.FileInfo.UserId    = userId;
            enrolFamily.FileInfo.OfficerId = officerId;

            var XML  = enrolFamily.XMLSerialize();
            var JSON = JsonConvert.SerializeObject(enrolFamily);

            var EnrolmentDir    = _configuration["AppSettings:Enrollment_Phone"] + Path.DirectorySeparatorChar;
            var JsonDebugFolder = _configuration["AppSettings:JsonDebugFolder"] + Path.DirectorySeparatorChar;
            var UpdatedFolder   = _configuration["AppSettings:UpdatedFolder"] + Path.DirectorySeparatorChar;
            var SubmittedFolder = _configuration["AppSettings:SubmittedFolder"] + Path.DirectorySeparatorChar;

            var hof = enrolFamily.Families.Select(x => x.HOFCHFID).FirstOrDefault();

            var FileName     = string.Format("{0}_{1}_{2}.xml", hof, officerId.ToString(), DateTime.Now.ToString(DateTimeFormats.FileNameDateTimeFormat));
            var JsonFileName = string.Format("{0}_{1}_{2}.json", hof, officerId.ToString(), DateTime.Now.ToString(DateTimeFormats.FileNameDateTimeFormat));

            var xmldoc = new XmlDocument();

            xmldoc.InnerXml = XML;

            if (!Directory.Exists(EnrolmentDir))
            {
                Directory.CreateDirectory(EnrolmentDir);
            }

            xmldoc.Save(EnrolmentDir + FileName);

            if (!Directory.Exists(JsonDebugFolder))
            {
                Directory.CreateDirectory(JsonDebugFolder);
            }

            File.WriteAllText(JsonDebugFolder + JsonFileName, JSON);

            int RV = -99;
            int InsureeUpd;
            int InsureeImported;

            using (var imisContext = new ImisDB())
            {
                var xmlParameter = new SqlParameter("@XML", XML)
                {
                    DbType = DbType.Xml
                };
                var returnParameter          = OutputParameter.CreateOutputParameter("@RV", SqlDbType.Int);
                var familySentParameter      = OutputParameter.CreateOutputParameter("@FamilySent", SqlDbType.Int);
                var familyImportedParameter  = OutputParameter.CreateOutputParameter("@FamilyImported", SqlDbType.Int);
                var familiesUpdParameter     = OutputParameter.CreateOutputParameter("@FamiliesUpd", SqlDbType.Int);
                var familyRejectedParameter  = OutputParameter.CreateOutputParameter("@FamilyRejected", SqlDbType.Int);
                var insureeSentParameter     = OutputParameter.CreateOutputParameter("@InsureeSent", SqlDbType.Int);
                var insureeUpdParameter      = OutputParameter.CreateOutputParameter("@InsureeUpd", SqlDbType.Int);
                var insureeImportedParameter = OutputParameter.CreateOutputParameter("@InsureeImported", SqlDbType.Int);
                var policySentParameter      = OutputParameter.CreateOutputParameter("@PolicySent", SqlDbType.Int);
                var policyImportedParameter  = OutputParameter.CreateOutputParameter("@PolicyImported", SqlDbType.Int);
                var policyRejectedParameter  = OutputParameter.CreateOutputParameter("@PolicyRejected", SqlDbType.Int);
                var policyChangedParameter   = OutputParameter.CreateOutputParameter("@PolicyChanged", SqlDbType.Int);
                var premiumSentParameter     = OutputParameter.CreateOutputParameter("@PremiumSent", SqlDbType.Int);
                var premiumImportedParameter = OutputParameter.CreateOutputParameter("@PremiumImported", SqlDbType.Int);
                var premiumRejectedParameter = OutputParameter.CreateOutputParameter("@PremiumRejected", SqlDbType.Int);

                var sql = "exec @RV = uspConsumeEnrollments @XML, @FamilySent OUT, @FamilyImported OUT, @FamiliesUpd OUT, @FamilyRejected OUT, " +
                          "@InsureeSent OUT, @InsureeUpd OUT, @InsureeImported OUT, " +
                          "@PolicySent OUT, @PolicyImported OUT, @PolicyRejected OUT, @PolicyChanged OUT," +
                          "@PremiumSent OUT, @PremiumImported OUT, @PremiumRejected OUT";

                DbConnection connection = imisContext.Database.GetDbConnection();

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

                    cmd.Parameters.AddRange(new[] { xmlParameter, returnParameter, familySentParameter, familyImportedParameter, familiesUpdParameter,
                                                    familyRejectedParameter, insureeSentParameter, insureeUpdParameter, insureeImportedParameter, policySentParameter,
                                                    policyImportedParameter, policyRejectedParameter, policyChangedParameter, premiumSentParameter, premiumImportedParameter,
                                                    premiumRejectedParameter });

                    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());
                    }
                }

                InsureeUpd      = insureeUpdParameter.Value == DBNull.Value ? 0 : (int)insureeUpdParameter.Value;
                InsureeImported = insureeImportedParameter.Value == DBNull.Value ? 0 : (int)insureeImportedParameter.Value;
                RV = (int)returnParameter.Value;

                if (RV == 0 && (InsureeImported > 0 || InsureeUpd > 0))
                {
                    if (!Directory.Exists(UpdatedFolder))
                    {
                        Directory.CreateDirectory(UpdatedFolder);
                    }

                    foreach (var picture in model.Family.Select(x => x.Insurees.Select(s => s.Picture)).FirstOrDefault().ToList())
                    {
                        if (picture != null)
                        {
                            if (picture.ImageContent != null)
                            {
                                if (picture.ImageContent.Length != 0)
                                {
                                    File.WriteAllBytes(UpdatedFolder + Path.DirectorySeparatorChar + picture.ImageName, Convert.FromBase64String(picture.ImageContent));
                                }
                            }
                        }
                    }
                }
            }

            var newFamily = new NewFamilyResponse();

            newFamily.Response = RV;
            if (RV == 0)
            {
                newFamily = CreateEnrolResponse(model);

                // Update the control number
                newFamily.Response = UpdateControlNumber(model, newFamily);

                // Create Premium
                CreatePremium(model);
            }

            return(newFamily);
        }
        public virtual async Task <int> OutputFailAsync(OutputParameter <string> RESPONSESTATUS, OutputParameter <string> RESPONSEMESSSAGE, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterRESPONSESTATUS = new SqlParameter
            {
                ParameterName = "RESPONSESTATUS",
                Size          = 20,
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.VarChar,
            };
            var parameterRESPONSEMESSSAGE = new SqlParameter
            {
                ParameterName = "RESPONSEMESSSAGE",
                Size          = 200,
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.VarChar,
            };
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                parameterRESPONSESTATUS,
                parameterRESPONSEMESSSAGE,
                parameterreturnValue,
            };
            var _ = await _context.Database.ExecuteSqlRawAsync("EXEC @returnValue = [dbo].[OutputFail] @RESPONSESTATUS OUTPUT, @RESPONSEMESSSAGE OUTPUT", sqlParameters, cancellationToken);

            RESPONSESTATUS.SetValue(parameterRESPONSESTATUS.Value);
            RESPONSEMESSSAGE.SetValue(parameterRESPONSEMESSSAGE.Value);
            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #3
0
 public void OutputParameter_ShouldThrowException_WhenNullAndNotNullable()
 {
     OutputParameter outputParameter = ExampleDBResult1.FindOutputParameter("nullParam");
     int             outputValue     = outputParameter.Value;
 }
Example #4
0
 private static void SetOutputParameter(SQLiteCommand cmd, ref OutputParameter outParam)
 {
     if ((cmd != null) && (cmd.Parameters.Count != 0))
     {
         for (int i = 0; i < cmd.Parameters.Count; i++)
         {
             SQLiteParameter parameter = cmd.Parameters[i];
             if ((parameter.Direction == ParameterDirection.InputOutput) || (parameter.Direction == ParameterDirection.Output))
             {
                 outParam.Add(parameter.ParameterName, parameter.Value);
             }
         }
     }
 }
Example #5
0
        private OutputParameter CheckInput(Parameter parameter, VerifyerParameter verifyerParameter)
        {
            if (verifyerParameter.Direction  == RatchetingDirections.TowardsZero)
            {
                _checker = new TowardsZeroChecker();
            }
            else
            {
                _checker = new TowardsHundredChecker();
            }
            _logProxy.LogThis(MessageImportance.Low, string.Format("Checking {0}", parameter.ParameterName));
            var par = new OutputParameter(parameter.ParameterName, "", false);

            if (Checker.CurrentValueIsWorseThanTargetValue(parameter.CurrentValue, verifyerParameter.TargetValue))
            {

                par.IsOk = false;
                par.VeriferResult = string.Format("Fail: {0} -> Current value is worse than target",
                                                  parameter.ParameterName);
                return par;
            }
            if (Checker.CurrentValueIsEqualToTargetValue(parameter.CurrentValue, verifyerParameter.TargetValue))
            {

                par.IsOk = true;
                par.VeriferResult = string.Format(
                    "Warning: {0} -> Current and Target equal - you are close to fail",
                    parameter.ParameterName);
                return par;
            }
            if (Checker.CurrentValueIsBetterThanTargetValue(parameter.CurrentValue, verifyerParameter.TargetValue) &
                !Checker.CurrentValueIsBetterThanTargetValueAndWarning(parameter.CurrentValue,
                                                                       verifyerParameter.TargetValue,
                                                                       verifyerParameter.WarningValue))
            {

                par.IsOk = true;
                par.VeriferResult = string.Format(
                    "Warning: {0} -> Current better than target but within warning - you are close to fail",
                    parameter.ParameterName);
                return par;
            }
            if (Checker.CurrentValueIsBetterThanTargetValue(parameter.CurrentValue, verifyerParameter.TargetValue) && verifyerParameter.RatchetValue > 0)
            {
                par.IsOk = true;
                par.VeriferResult = string.Format("Success: {0} -> Current is better than Target and can be ratcheted to {1}",
                                                  parameter.ParameterName,
                                                  Checker.NewRatchetValue(verifyerParameter.TargetValue,
                                                                          verifyerParameter.RatchetValue));
                return par;
            }

            if (Checker.CurrentValueIsBetterThanTargetValue(parameter.CurrentValue, verifyerParameter.TargetValue))
            {
                par.IsOk = true;
                par.VeriferResult = string.Format("Success: {0} -> Current is better than Target", parameter.ParameterName);
                return par;
            }

            par.IsOk = false;
            par.VeriferResult = "Error in verification: somehow i didn't  foresee this";
            return par;
        }
Example #6
0
        public void DBResult_ShouldFindOutputParameter_ByName()
        {
            OutputParameter outputParameter = ExampleDBResult1.FindOutputParameter("param3");

            Assert.AreEqual(true, outputParameter.Value);
        }
Example #7
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            using (var db = new NorthwindContext())
            {
                //var procs = new NorthwindContextProcedures(db);

                var sret     = new OutputParameter <string>();
                var returned = new OutputParameter <string>();
                await db.GetProcedures().OutputFailAsync(sret, returned);

                if (sret.Value != "yes")
                {
                    Console.Error.WriteLine($"AssertEqual failed. Expected: \"yes\". Actual: {sret.Value}.");
                }

                var spacesResult = await db.GetProcedures().SpacesAsync();

                if (spacesResult.Count != 1)
                {
                    Console.Error.WriteLine($"AssertEqual failed. Expected: 1. Actual: {spacesResult.Count}.");
                }

                var output1 = new OutputParameter <string>();
                var output2 = new OutputParameter <string>();
                var output3 = new OutputParameter <int>();
                var result  = await db.GetProcedures().TestMethodOutputNoResultAsync(0, null, output1, output2, output3);

                var result2 = await db.GetProcedures().CustOrderHistDupeAsync("ALFKI");

                if (result2.Count != 11)
                {
                    Console.Error.WriteLine($"AssertEqual failed. Expected: 11. Actual: {result2.Count}.");
                }

                var return1 = new OutputParameter <int>();
                var test    = await db.GetProcedures().ReturnValueAsync(return1);

                if (return1.Value != 42)
                {
                    Console.Error.WriteLine($"AssertEqual failed. Expected: 42. Actual: {return1.Value}.");
                }

                var rowsResult = await db.GetProcedures().CategoryUpdateAsync("Beverages", 1);

                if (rowsResult != 1)
                {
                    Console.Error.WriteLine($"AssertEqual failed. Expected: 1. Actual: {rowsResult}.");
                }

                var rowsResult2 = await db.GetProcedures().CategoryUpdateAsync("Beverages", int.MinValue);

                if (rowsResult2 != 0)
                {
                    Console.Error.WriteLine($"AssertEqual failed. Expected: 0. Actual: {rowsResult2}.");
                }

                var udfTest = db.Categories
                              .Where(c => c.CategoryName == NorthwindContext.GetCustInfo("x", null))
                              .ToList();
            }
        }
Example #8
0
        public void Named_WithNull()
        {
            Action action = () => OutputParameter.Named(null);

            action.Should().Throw <ArgumentNullException>();
        }
Example #9
0
        public virtual async Task <SearchBreadCrumbByCateResult[]> SearchBreadCrumbByCateAsync(int?ArticleCategoryId, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "ArticleCategoryId",
                    Value         = ArticleCategoryId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <SearchBreadCrumbByCateResult>("EXEC @returnValue = [dbo].[SearchBreadCrumbByCate] @ArticleCategoryId", sqlParameters, cancellationToken);

            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #10
0
        public virtual async Task <AccountSearchResult[]> AccountSearchAsync(string Keyword, Guid?RoleId, bool?Active, int?PageSize, int?CurrentPage, OutputParameter <int?> ItemCount, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterItemCount = new SqlParameter
            {
                ParameterName = "ItemCount",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "Keyword",
                    Size          = 4000,
                    Value         = Keyword ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.NVarChar,
                },
                new SqlParameter
                {
                    ParameterName = "RoleId",
                    Value         = RoleId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.UniqueIdentifier,
                },
                new SqlParameter
                {
                    ParameterName = "Active",
                    Value         = Active ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Bit,
                },
                new SqlParameter
                {
                    ParameterName = "PageSize",
                    Value         = PageSize ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "CurrentPage",
                    Value         = CurrentPage ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                parameterItemCount,
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <AccountSearchResult>("EXEC @returnValue = [dbo].[AccountSearch] @Keyword, @RoleId, @Active, @PageSize, @CurrentPage, @ItemCount OUTPUT", sqlParameters, cancellationToken);

            ItemCount.SetValue(parameterItemCount.Value);
            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #11
0
        public virtual async Task <ArticleSearchResult[]> ArticleSearchAsync(string Keyword, string Tags, int?ArticleCategoryId, int?ArticleStatusId, int?ProductBrandId, int?ArticleTypeId, int?ExceptionId, bool?ExceptionArticleTop, DateTime?FromDate, DateTime?ToDate, bool?Efficiency, bool?Active, Guid?CreateBy, int?PageSize, int?CurrentPage, OutputParameter <int?> ItemCount, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterItemCount = new SqlParameter
            {
                ParameterName = "ItemCount",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "Keyword",
                    Size          = 4000,
                    Value         = Keyword ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.NVarChar,
                },
                new SqlParameter
                {
                    ParameterName = "Tags",
                    Size          = 400,
                    Value         = Tags ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.NVarChar,
                },
                new SqlParameter
                {
                    ParameterName = "ArticleCategoryId",
                    Value         = ArticleCategoryId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "ArticleStatusId",
                    Value         = ArticleStatusId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "ProductBrandId",
                    Value         = ProductBrandId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "ArticleTypeId",
                    Value         = ArticleTypeId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "ExceptionId",
                    Value         = ExceptionId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "ExceptionArticleTop",
                    Value         = ExceptionArticleTop ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Bit,
                },
                new SqlParameter
                {
                    ParameterName = "FromDate",
                    Value         = FromDate ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.DateTime,
                },
                new SqlParameter
                {
                    ParameterName = "ToDate",
                    Value         = ToDate ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.DateTime,
                },
                new SqlParameter
                {
                    ParameterName = "Efficiency",
                    Value         = Efficiency ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Bit,
                },
                new SqlParameter
                {
                    ParameterName = "Active",
                    Value         = Active ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Bit,
                },
                new SqlParameter
                {
                    ParameterName = "CreateBy",
                    Value         = CreateBy ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.UniqueIdentifier,
                },
                new SqlParameter
                {
                    ParameterName = "PageSize",
                    Value         = PageSize ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "CurrentPage",
                    Value         = CurrentPage ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                parameterItemCount,
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <ArticleSearchResult>("EXEC @returnValue = [dbo].[ArticleSearch] @Keyword, @Tags, @ArticleCategoryId, @ArticleStatusId, @ProductBrandId, @ArticleTypeId, @ExceptionId, @ExceptionArticleTop, @FromDate, @ToDate, @Efficiency, @Active, @CreateBy, @PageSize, @CurrentPage, @ItemCount OUTPUT", sqlParameters, cancellationToken);

            ItemCount.SetValue(parameterItemCount.Value);
            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #12
0
        public async Task <HygDatum[]> pGetStarsInCoordinateRangeAsync(double?Xmin, double?Ymin, double?Zmin, double?Xmax, double?Ymax, double?Zmax, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "Xmin",
                    Value         = Xmin ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Float,
                },
                new SqlParameter
                {
                    ParameterName = "Ymin",
                    Value         = Ymin ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Float,
                },
                new SqlParameter
                {
                    ParameterName = "Zmin",
                    Value         = Zmin ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Float,
                },
                new SqlParameter
                {
                    ParameterName = "Xmax",
                    Value         = Xmax ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Float,
                },
                new SqlParameter
                {
                    ParameterName = "Ymax",
                    Value         = Ymax ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Float,
                },
                new SqlParameter
                {
                    ParameterName = "Zmax",
                    Value         = Zmax ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Float,
                },
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <HygDatum>("EXEC @returnValue = [dbo].[pGetStarsInCoordinateRange] @Xmin, @Ymin, @Zmin, @Xmax, @Ymax, @Zmax", sqlParameters, cancellationToken);

            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #13
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);
        }
        public virtual async Task <TempObjectsResult[]> TempObjectsAsync(int?DetailID, OutputParameter <int?> returnCode, OutputParameter <string> result, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterreturnCode = new SqlParameter
            {
                ParameterName = "returnCode",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };
            var parameterresult = new SqlParameter
            {
                ParameterName = "result",
                Size          = -1,
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.VarChar,
            };
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "DetailID",
                    Value         = DetailID ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                parameterreturnCode,
                parameterresult,
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <TempObjectsResult>("EXEC @returnValue = [dbo].[TempObjects] @DetailID, @returnCode OUTPUT, @result OUTPUT", sqlParameters, cancellationToken);

            returnCode.SetValue(parameterreturnCode.Value);
            result.SetValue(parameterresult.Value);
            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #15
0
        public virtual async Task <List <SpArticleGetByCategoryIdResult> > SpArticleGetByCategoryIdAsync(int?ArticleCategoryId, int?PageSize, int?CurrentPage, OutputParameter <int?> ItemCount, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterItemCount = new SqlParameter
            {
                ParameterName = "ItemCount",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "ArticleCategoryId",
                    Value         = ArticleCategoryId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "PageSize",
                    Value         = PageSize ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "CurrentPage",
                    Value         = CurrentPage ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                parameterItemCount,
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <SpArticleGetByCategoryIdResult>("EXEC @returnValue = [dbo].[SpArticleGetByCategoryId] @ArticleCategoryId, @PageSize, @CurrentPage, @ItemCount OUTPUT", sqlParameters, cancellationToken);

            ItemCount.SetValue(parameterItemCount.Value);
            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
        public virtual async Task <TestResult[]> TestAsync(string something, string something1, string something2, string something3, string something4, string something5, string something6, string something7, string something8, string something9, string something10, string something11, string something12, string something13, string something14, string something15, string something16, OutputParameter <int?> myOutput, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parametermyOutput = new SqlParameter
            {
                ParameterName = "myOutput",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                parametermyOutput,
                new SqlParameter
                {
                    ParameterName = "something",
                    Size          = 12,
                    Value         = something ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something1",
                    Size          = 40,
                    Value         = something1 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something2",
                    Size          = 40,
                    Value         = something2 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something3",
                    Size          = 40,
                    Value         = something3 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something4",
                    Size          = 40,
                    Value         = something4 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something5",
                    Size          = 40,
                    Value         = something5 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something6",
                    Size          = 10,
                    Value         = something6 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something7",
                    Size          = 40,
                    Value         = something7 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something8",
                    Size          = 3,
                    Value         = something8 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something9",
                    Size          = 1,
                    Value         = something9 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something10",
                    Size          = 16,
                    Value         = something10 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something11",
                    Size          = 20,
                    Value         = something11 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something12",
                    Size          = 30,
                    Value         = something12 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something13",
                    Size          = 241,
                    Value         = something13 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something14",
                    Size          = 241,
                    Value         = something14 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something15",
                    Size          = 241,
                    Value         = something15 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "something16",
                    Size          = 1000,
                    Value         = something16 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <TestResult>("EXEC @returnValue = [dbo].[Test] @myOutput OUTPUT, @something, @something1, @something2, @something3, @something4, @something5, @something6, @something7, @something8, @something9, @something10, @something11, @something12, @something13, @something14, @something15, @something16", sqlParameters, cancellationToken);

            myOutput.SetValue(parametermyOutput.Value);
            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #17
0
        public virtual async Task <List <SpArticleGetNewByCategoryIdResult> > SpArticleGetNewByCategoryIdAsync(int?ArticleCategoryId, int?Number, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "ArticleCategoryId",
                    Value         = ArticleCategoryId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "Number",
                    Value         = Number ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <SpArticleGetNewByCategoryIdResult>("EXEC @returnValue = [dbo].[SpArticleGetNewByCategoryId] @ArticleCategoryId, @Number", sqlParameters, cancellationToken);

            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #18
0
        public virtual async Task <CustOrdersOrdersResult[]> CustOrdersOrdersAsync(string CustomerID, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "CustomerID",
                    Size          = 10,
                    Value         = CustomerID ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.NChar,
                },
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <CustOrdersOrdersResult>("EXEC @returnValue = [dbo].[CustOrdersOrders] @CustomerID", sqlParameters, cancellationToken);

            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #19
0
        public virtual async Task <List <SpProductBreadcrumbResult> > SpProductBreadcrumbAsync(int?ProductCategoryId, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "ProductCategoryId",
                    Value         = ProductCategoryId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <SpProductBreadcrumbResult>("EXEC @returnValue = [dbo].[SpProductBreadcrumb] @ProductCategoryId", sqlParameters, cancellationToken);

            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #20
0
 public static int ExecuteStoredProcedureWithQuery(string ConnectionString, string StoredProcedureName, ref DataSet ds, ref OutputParameter Outputs, params Parameter[] Params)
 {
     SqlConnection conn = CreateDataConnection(ConnectionString);
     if (conn == null)
     {
         return -1001;
     }
     int num = ExecuteStoredProcedureWithQuery(conn, StoredProcedureName, ref ds, ref Outputs, Params);
     conn.Close();
     return num;
 }
Example #21
0
        public virtual async Task <List <SpProductCommentStaffSearchResult> > SpProductCommentStaffSearchAsync(string Keyword, int?ProductId, bool?Active, string CreateBy, int?PageSize, int?CurrentPage, OutputParameter <int?> ItemCount, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterItemCount = new SqlParameter
            {
                ParameterName = "ItemCount",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "Keyword",
                    Size          = 4000,
                    Value         = Keyword ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.NVarChar,
                },
                new SqlParameter
                {
                    ParameterName = "ProductId",
                    Value         = ProductId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "Active",
                    Value         = Active ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Bit,
                },
                new SqlParameter
                {
                    ParameterName = "CreateBy",
                    Size          = 200,
                    Value         = CreateBy ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "PageSize",
                    Value         = PageSize ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "CurrentPage",
                    Value         = CurrentPage ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                parameterItemCount,
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <SpProductCommentStaffSearchResult>("EXEC @returnValue = [dbo].[SpProductCommentStaffSearch] @Keyword, @ProductId, @Active, @CreateBy, @PageSize, @CurrentPage, @ItemCount OUTPUT", sqlParameters, cancellationToken);

            ItemCount.SetValue(parameterItemCount.Value);
            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #22
0
        public void DBResult_ShouldReturnNull_WhenParameterNotFound()
        {
            OutputParameter outputParameter = ExampleDBResult1.FindOutputParameter("Param3");

            Assert.IsNull(outputParameter);
        }
Example #23
0
        public virtual async Task <List <SpProductSearchResult> > SpProductSearchAsync(string Keyword, int?ProductCategoryId, int?ProductManufactureId, int?ProductStatusId, int?CountryId, int?LocationId, int?DepartmentManId, int?ProductBrandId, int?ProductTypeId, int?ExceptionId, bool?ExceptionProductTop, decimal?FromPrice, decimal?ToPrice, DateTime?FromDate, DateTime?ToDate, bool?Efficiency, bool?Active, string AssignBy, string CreateBy, string OrderBy, int?PageSize, int?CurrentPage, OutputParameter <int?> ItemCount, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterItemCount = new SqlParameter
            {
                ParameterName = "ItemCount",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "Keyword",
                    Size          = 4000,
                    Value         = Keyword ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.NVarChar,
                },
                new SqlParameter
                {
                    ParameterName = "ProductCategoryId",
                    Value         = ProductCategoryId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "ProductManufactureId",
                    Value         = ProductManufactureId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "ProductStatusId",
                    Value         = ProductStatusId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "CountryId",
                    Value         = CountryId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "LocationId",
                    Value         = LocationId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "DepartmentManId",
                    Value         = DepartmentManId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "ProductBrandId",
                    Value         = ProductBrandId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "ProductTypeId",
                    Value         = ProductTypeId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "ExceptionId",
                    Value         = ExceptionId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "ExceptionProductTop",
                    Value         = ExceptionProductTop ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Bit,
                },
                new SqlParameter
                {
                    ParameterName = "FromPrice",
                    Value         = FromPrice ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Money,
                },
                new SqlParameter
                {
                    ParameterName = "ToPrice",
                    Value         = ToPrice ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Money,
                },
                new SqlParameter
                {
                    ParameterName = "FromDate",
                    Value         = FromDate ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.DateTime,
                },
                new SqlParameter
                {
                    ParameterName = "ToDate",
                    Value         = ToDate ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.DateTime,
                },
                new SqlParameter
                {
                    ParameterName = "Efficiency",
                    Value         = Efficiency ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Bit,
                },
                new SqlParameter
                {
                    ParameterName = "Active",
                    Value         = Active ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Bit,
                },
                new SqlParameter
                {
                    ParameterName = "AssignBy",
                    Size          = 900,
                    Value         = AssignBy ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.NVarChar,
                },
                new SqlParameter
                {
                    ParameterName = "CreateBy",
                    Size          = 900,
                    Value         = CreateBy ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.NVarChar,
                },
                new SqlParameter
                {
                    ParameterName = "OrderBy",
                    Size          = 200,
                    Value         = OrderBy ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.VarChar,
                },
                new SqlParameter
                {
                    ParameterName = "PageSize",
                    Value         = PageSize ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "CurrentPage",
                    Value         = CurrentPage ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                parameterItemCount,
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <SpProductSearchResult>("EXEC @returnValue = [dbo].[SpProductSearch] @Keyword, @ProductCategoryId, @ProductManufactureId, @ProductStatusId, @CountryId, @LocationId, @DepartmentManId, @ProductBrandId, @ProductTypeId, @ExceptionId, @ExceptionProductTop, @FromPrice, @ToPrice, @FromDate, @ToDate, @Efficiency, @Active, @AssignBy, @CreateBy, @OrderBy, @PageSize, @CurrentPage, @ItemCount OUTPUT", sqlParameters, cancellationToken);

            ItemCount.SetValue(parameterItemCount.Value);
            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #24
0
 public void OutputParameter_ShouldThrowException_WhenTypesDontMatch()
 {
     OutputParameter outputParameter = ExampleDBResult1.FindOutputParameter("param2");
     char            outputValue     = outputParameter.Value;
 }
Example #25
0
        public virtual async Task <List <SpUserNotifySearchResult> > SpUserNotifySearchAsync(int?UserNotifyTypeId, Guid?AspNetUsersId, bool?Readed, int?PageSize, int?CurrentPage, OutputParameter <int?> ItemCount, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterItemCount = new SqlParameter
            {
                ParameterName = "ItemCount",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "UserNotifyTypeId",
                    Value         = UserNotifyTypeId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "AspNetUsersId",
                    Value         = AspNetUsersId ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.UniqueIdentifier,
                },
                new SqlParameter
                {
                    ParameterName = "Readed",
                    Value         = Readed ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Bit,
                },
                new SqlParameter
                {
                    ParameterName = "PageSize",
                    Value         = PageSize ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                new SqlParameter
                {
                    ParameterName = "CurrentPage",
                    Value         = CurrentPage ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                parameterItemCount,
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <SpUserNotifySearchResult>("EXEC @returnValue = [dbo].[SpUserNotifySearch] @UserNotifyTypeId, @AspNetUsersId, @Readed, @PageSize, @CurrentPage, @ItemCount OUTPUT", sqlParameters, cancellationToken);

            ItemCount.SetValue(parameterItemCount.Value);
            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #26
0
    /// <summary>
    /// 执行指定存储过程(事务中),返回结果集
    /// </summary>
    /// <param name="StoredProcedureName">存储过程名称</param>
    /// <param name="Outputs">输出参数列表</param>
    /// <param name="Params">输入参数列表</param>
    /// <returns>返回查询结果集</returns>
    public static DataSet ExecuteStoredProcedureWithQuery(string StoredProcedureName, ref OutputParameter Outputs, params Parameter[] Params)
    {
        DataSet        dataSet     = null;
        SqlTransaction transaction = null;

        try
        {
            if (_sCon == null)
            {
                _sCon = GetSqlConnection();
            }
            if (_sCon.State != ConnectionState.Open)
            {
                _sCon.Open();
            }
            using (SqlDataAdapter adapter = new SqlDataAdapter("", _sCon))
            {
                SqlCommand cmd = new SqlCommand(StoredProcedureName, _sCon);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Clear();                           //清除参数
                AddParameter(ref cmd, Params);                    //为sql语句添加参数
                transaction           = _sCon.BeginTransaction(); //开始事务
                cmd.Transaction       = transaction;
                adapter.SelectCommand = cmd;
                dataSet = new DataSet();
                adapter.Fill(dataSet);
                transaction.Commit();
                AddReturnParameter(cmd, ref Outputs); //将输出参数添加到 Outputs中 以便上层获取输出参数值
            }
        }
        catch (Exception ex)
        {
            transaction.Rollback();
            //:@在这里处理异常
            throw new Exception(ex.Message);
            //:$
        }
        finally
        {
            try
            {
                _sCon.Close();
            }
            catch (Exception ex2)
            {
                //:@在这里处理异常
                throw new Exception(ex2.Message);
                //:$
            }
        }
        return(dataSet);
    }
Example #27
0
 public void LogSuccess(OutputParameter param )
 {
     _parent.Log.LogMessage(MessageImportance.Normal,param.ParameterName + " succeded: " + param.VeriferResult);
 }
        public virtual async Task <List <CustOrdersDetailResult> > CustOrdersDetailAsync(int?OrderID, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "OrderID",
                    Value         = OrderID ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <CustOrdersDetailResult>("EXEC @returnValue = [dbo].[CustOrdersDetail] @OrderID", sqlParameters, cancellationToken);

            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
        // 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;
            }
        }
        public virtual async Task <SalesByCategoryResult[]> SalesByCategoryAsync(string CategoryName, string OrdYear, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "CategoryName",
                    Size          = 30,
                    Value         = CategoryName ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.NVarChar,
                },
                new SqlParameter
                {
                    ParameterName = "OrdYear",
                    Size          = 8,
                    Value         = OrdYear ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.NVarChar,
                },
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <SalesByCategoryResult>("EXEC @returnValue = [dbo].[SalesByCategory] @CategoryName, @OrdYear", sqlParameters, cancellationToken);

            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #31
0
 public static int ExecuteStoredProcedureNonQuery(MySqlConnection conn, string StoredProcedureName, ref OutputParameter Outputs, params Parameter[] Params)
 {
     if (conn == null)
     {
         return -1001;
     }
     bool flag = true;
     if (conn.State != ConnectionState.Open)
     {
         flag = false;
         try
         {
             conn.Open();
         }
         catch
         {
             return -1001;
         }
     }
     MySqlCommand command = new MySqlCommand(StoredProcedureName, conn);
     command.CommandType = CommandType.StoredProcedure;
     SetCommandParameters(ref command, Params);
     MySqlTransaction transaction = conn.BeginTransaction();
     command.Transaction = transaction;
     bool flag2 = false;
     try
     {
         command.ExecuteNonQuery();
         transaction.Commit();
         flag2 = true;
     }
     catch
     {
         transaction.Rollback();
         flag2 = false;
     }
     if (!flag)
     {
         conn.Close();
     }
     if (!flag2)
     {
         return -1002;
     }
     SetOutputParameter(command, ref Outputs);
     return 0;
 }
        public virtual async Task <TenMostExpensiveProductsResult[]> TenMostExpensiveProductsAsync(OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <TenMostExpensiveProductsResult>("EXEC @returnValue = [dbo].[Ten Most Expensive Products]", sqlParameters, cancellationToken);

            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #33
0
 public static int ExecuteStoredProcedureWithQuery(MySqlConnection conn, string StoredProcedureName, ref DataSet ds, ref OutputParameter Outputs, params Parameter[] Params)
 {
     if (conn == null)
     {
         return -1001;
     }
     bool flag = true;
     if (conn.State != ConnectionState.Open)
     {
         flag = false;
         try
         {
             conn.Open();
         }
         catch
         {
             return -1001;
         }
     }
     MySqlDataAdapter adapter = new MySqlDataAdapter("", conn);
     MySqlCommand command = new MySqlCommand(StoredProcedureName, conn);
     command.CommandType = CommandType.StoredProcedure;
     command.Parameters.Clear();
     SetCommandParameters(ref command, Params);
     if (ds == null)
     {
         ds = new DataSet();
     }
     MySqlTransaction transaction = conn.BeginTransaction();
     command.Transaction = transaction;
     adapter.SelectCommand = command;
     bool flag2 = false;
     try
     {
         adapter.Fill(ds);
         transaction.Commit();
         flag2 = true;
     }
     catch
     {
         transaction.Rollback();
         flag2 = false;
     }
     if (!flag)
     {
         conn.Close();
     }
     if (!flag2)
     {
         return -1002;
     }
     SetOutputParameter(command, ref Outputs);
     return 0;
 }
        public virtual async Task <int> TestMethodOutputNoResultAsync(int?testParameter1, string testParameter4, OutputParameter <string> testParameter2, OutputParameter <string> testParameter3, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parametertestParameter2 = new SqlParameter
            {
                ParameterName = "testParameter2",
                Size          = 255,
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.VarChar,
            };
            var parametertestParameter3 = new SqlParameter
            {
                ParameterName = "testParameter3",
                Size          = 255,
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.VarChar,
            };
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "testParameter1",
                    Value         = testParameter1 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.Int,
                },
                parametertestParameter2,
                parametertestParameter3,
                new SqlParameter
                {
                    ParameterName = "testParameter4",
                    Size          = -1,
                    Value         = testParameter4 ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.NVarChar,
                },
                parameterreturnValue,
            };
            var _ = await _context.Database.ExecuteSqlRawAsync("EXEC @returnValue = [dbo].[TestMethodOutputNoResult] @testParameter1, @testParameter2 OUTPUT, @testParameter3 OUTPUT, @testParameter4", sqlParameters, cancellationToken);

            testParameter2.SetValue(parametertestParameter2.Value);
            testParameter3.SetValue(parametertestParameter3.Value);
            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #35
0
 public static int ExecuteStoredProcedureWithQuery(string StoredProcedureName, ref DataSet ds, ref OutputParameter Outputs, params Parameter[] Params)
 {
     return ExecuteStoredProcedureWithQuery(ConfigurationSettings.AppSettings["ConnectionString"], StoredProcedureName, ref ds, ref Outputs, Params);
 }
Example #36
0
        public void Named_WithEmpty()
        {
            Action action = () => OutputParameter.Named("");

            action.Should().Throw <ArgumentException>();
        }
Example #37
0
 public static int ExecuteStoredProcedureWithQuery(SqlConnection conn, string StoredProcedureName, ref DataSet ds, ref OutputParameter Outputs, params Parameter[] Params)
 {
     if (conn == null)
     {
         return -1001;
     }
     bool flag = true;
     if (conn.State != ConnectionState.Open)
     {
         flag = false;
         try
         {
             conn.Open();
         }
         catch
         {
             return -1001;
         }
     }
     SqlDataAdapter adapter = new SqlDataAdapter("", conn);
     SqlCommand command = new SqlCommand(StoredProcedureName, conn);
     command.CommandType = CommandType.StoredProcedure;
     command.Parameters.Clear();
     SetCommandParameters(ref command, Params);
     SqlParameter parameter = new SqlParameter("@Shove_Database_MSSQL_ExecuteStoredProcedureWithQuery_Rtn", SqlDbType.Int);
     parameter.Direction = ParameterDirection.ReturnValue;
     command.Parameters.Add(parameter);
     if (ds == null)
     {
         ds = new DataSet();
     }
     SqlTransaction transaction = conn.BeginTransaction();
     command.Transaction = transaction;
     adapter.SelectCommand = command;
     bool flag2 = false;
     try
     {
         adapter.Fill(ds);
         transaction.Commit();
         flag2 = true;
     }
     catch(Exception ex)
     {
         transaction.Rollback();
         flag2 = false;
     }
     if (!flag)
     {
         conn.Close();
     }
     if (!flag2)
     {
         return -1002;
     }
     SetOutputParameter(command, ref Outputs);
     parameter = GetReturnParameter(command);
     if (parameter != null)
     {
         return (int) parameter.Value;
     }
     return 0;
 }
Example #38
0
        public virtual async Task <EmployeeSalesbyCountryResult[]> EmployeeSalesbyCountryAsync(DateTime?Beginning_Date, DateTime?Ending_Date, OutputParameter <int> returnValue = null, CancellationToken cancellationToken = default)
        {
            var parameterreturnValue = new SqlParameter
            {
                ParameterName = "returnValue",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int,
            };

            var sqlParameters = new []
            {
                new SqlParameter
                {
                    ParameterName = "Beginning_Date",
                    Value         = Beginning_Date ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.DateTime,
                },
                new SqlParameter
                {
                    ParameterName = "Ending_Date",
                    Value         = Ending_Date ?? Convert.DBNull,
                    SqlDbType     = System.Data.SqlDbType.DateTime,
                },
                parameterreturnValue,
            };
            var _ = await _context.SqlQueryAsync <EmployeeSalesbyCountryResult>("EXEC @returnValue = [dbo].[Employee Sales by Country] @Beginning_Date, @Ending_Date", sqlParameters, cancellationToken);

            returnValue?.SetValue(parameterreturnValue.Value);

            return(_);
        }
Example #39
0
 /// <summary>
 /// Implements the constructor: OutputParameter()
 /// Direct superclasses: global::MetaDslx.Soal.TypedElement, global::MetaDslx.Soal.AnnotatedElement
 /// All superclasses: global::MetaDslx.Soal.TypedElement, global::MetaDslx.Soal.AnnotatedElement
 /// </summary>
 public virtual void OutputParameter(OutputParameter @this)
 {
     this.TypedElement(@this);
     this.AnnotatedElement(@this);
 }