public Response Drop(DropRequest Request)
        {
            Response oResponse = new Response();
            LogManager.WriteLog("VaultService: Drop -- Entered", LogManager.enumLogLevel.Info);
            try
            {
                StringWriter outStream = new StringWriter();
                XmlSerializer s = new XmlSerializer(typeof(DropRequest));

                s.Serialize(outStream, Request);
                LogManager.WriteLog("VaultService: Drop Xml" + outStream.ToString(), LogManager.enumLogLevel.Info);
                outStream.Close();

                if (Request.EventID == 0)
                {
                    oResponse.ErrCode = 1;
                    oResponse.ErrDesc = "Invalid EventID ";
                }
                //else if (Request.DeviceID == 0)
                //{
                //    oResponse.ErrCode = 1;
                //    oResponse.ErrDesc = "Invalid DeviceID";
                //}
                else if (Request.DeviceName.IsNullOrEmpty())
                {
                    oResponse.ErrCode = 2;
                    oResponse.ErrDesc = "Invalid Device Name";
                }
                else if (Request.TotalTransactionAmount < 0)
                {
                    oResponse.ErrCode = 4;
                    oResponse.ErrDesc = "Invalid Amount(Must be greater than 0)";
                }

                else if (Request.CassetteDetails == null || Request.CassetteDetails.Count == 0)
                {
                    oResponse.ErrCode = 5;
                    oResponse.ErrDesc = "cassette details not found";
                }

              

                foreach (Cassette cte in Request.CassetteDetails)
                {
                    if (cte.CassetteName.IsNullOrEmpty())
                    {
                        oResponse.ErrCode = 6;
                        oResponse.ErrDesc = "Cassette name invalid.";
                        break;
                    }
                    if (cte.Denom == 0)
                    {
                        oResponse.ErrCode = 5;
                        oResponse.ErrDesc = "Cassette denom invalid.";
                        break;
                    }

                    //if (cte.Amount == 0)
                    //{
                    //    oResponse.ErrCode = 5;
                    //    oResponse.ErrDesc = "cassette amount invalid.";
                    //    break;
                    //}

                }

                if (oResponse.ErrCode != 0)
                {
                    LogManager.WriteLog("Drop Response: " + oResponse.ToString(), LogManager.enumLogLevel.Debug);
                    return oResponse;

                }

                SqlParameter[] sqlParameters = new SqlParameter[4];
                sqlParameters[0] = new SqlParameter("@EventId", Request.EventID);
                sqlParameters[1] = new SqlParameter("@EventDescription", "DROPWEBREQUEST");
                sqlParameters[2] = new SqlParameter("@XML", outStream.ToString());
                sqlParameters[3] = new SqlParameter("@Device", Request.DeviceSerialNumber);
                int retval = int.Parse(SqlHelper.ExecuteScalar(GetConnectionString(), CommandType.StoredProcedure, "usp_Vault_UpdateGenericMessage", sqlParameters).ToString());

                if (retval > 0)
                {
                    LogManager.WriteLog("Drop Updated Successfully Device:" + Request.DeviceName + " Amount: " + Request.TotalTransactionAmount, LogManager.enumLogLevel.Info);
                }
                else
                {
                    if (retval == -701)
                    {
                        oResponse.ErrCode = 701;
                        oResponse.ErrDesc = "Vault not enrolled/invalid serial number";

                    }
                    else if (retval == -702)
                    {
                        oResponse.ErrCode = 702;
                        oResponse.ErrDesc = "Feature not enabled";

                    }
                    else
                    {
                        oResponse.ErrCode = -100;
                        oResponse.ErrDesc = "Unable to process request";
                    }
                    LogManager.WriteLog("Drop Updated Failed Asset:" + Request.DeviceName + " Amount: " + Request.TotalTransactionAmount, LogManager.enumLogLevel.Info);
                }

            }
            catch (Exception ex)
            {
                LogManager.WriteLog("Error in updating  Drop Info", LogManager.enumLogLevel.Error);
                ExceptionManager.Publish(ex);
                oResponse.ErrCode = -100;
                oResponse.ErrDesc = "Error Occured";
            }
            LogManager.WriteLog("Drop Response: " + oResponse.ToString(), LogManager.enumLogLevel.Debug);
            return oResponse;
        }
        public Response ProcessMessages(string XMLRequest)
        {

            Response oResponse = new Response();
            LogManager.WriteLog("VaultService: ProcessEvents -- Entered", LogManager.enumLogLevel.Info);
            try
            {

                LogManager.WriteLog("VaultService: ProcessEvents Xml" + XMLRequest, LogManager.enumLogLevel.Info);

                using (SqlConnection oConn = new SqlConnection(GetConnectionString()))
                {

                    try
                    {
                        oConn.Open();

                        //if (request.DeviceID.IsNullOrEmpty())
                        //{
                        //    oResponse.ErrCode = 1;
                        //    oResponse.ErrDesc = "Invalid DeviceID";
                        //}
                        //if (request.SiteID.ToString().Length < 4)
                        //{
                        //    oResponse.ErrCode = 2;
                        //    oResponse.ErrDesc = "Invalid SiteID(Must be a integer with 4 digits)";
                        //}
                        //if (request.EventID < 1)
                        //{
                        //    oResponse.ErrCode = 3;
                        //    oResponse.ErrDesc = "Invalid EventID";
                        //}
                        //if (request.EventDescription.IsNullOrEmpty())
                        //{
                        //    oResponse.ErrCode = 4;
                        //    oResponse.ErrDesc = "Invalid EventDescription";
                        //}

                        if (oResponse.ErrCode != 0)
                        {
                            LogManager.WriteLog("ProcessMessages Response: " + oResponse.ToString(), LogManager.enumLogLevel.Debug);
                            return oResponse;
                        }

                        var sqlParameters = new SqlParameter[1];

                        sqlParameters[0] = new SqlParameter("@doc", XMLRequest);

                        int retval = SqlHelper.ExecuteNonQuery(oConn, CommandType.StoredProcedure, "rsp_Vault_UpdateMessagesFromXML", sqlParameters);

                        if (retval == 1)
                        {
                            LogManager.WriteLog("Messages Updated Successfully ", LogManager.enumLogLevel.Info);
                           
                        }
                        else
                        {
                            LogManager.WriteLog("Messages Update Failed", LogManager.enumLogLevel.Info);
                            oResponse.ErrCode = -100;
                            oResponse.ErrDesc = "Unable to update vault messages";
                        }



                    }
                    catch (Exception Ex)
                    {
                        ExceptionManager.Publish(Ex);
                        oResponse.ErrCode = -100;
                        oResponse.ErrDesc = "Unable to update vault messages";
                    }
                }


            }
            catch (Exception ex)
            {
                LogManager.WriteLog("Error in reading Vault Messages Info", LogManager.enumLogLevel.Error);
                ExceptionManager.Publish(ex);
                oResponse.ErrCode = -100;
                oResponse.ErrDesc = "Error Occured";

            }
           
            return oResponse;
        }
        public Response ProcessVouchers(VoucherModel request)
        {
            Response oResponse = new Response();
            LogManager.WriteLog("VaultService: ProcessVouchers -- Entered", LogManager.enumLogLevel.Info);

            try
            {
                StringWriter outStream = new StringWriter();
                XmlSerializer s = new XmlSerializer(typeof(VoucherModel));
                s.Serialize(outStream, request);
                LogManager.WriteLog("VaultService: Vouchers Xml" + outStream.ToString(), LogManager.enumLogLevel.Info);

                outStream.Close();

                if (request.BarCode.IsNullOrEmpty())
                {
                    oResponse.ErrCode = 1;
                    oResponse.ErrDesc = "Invalid BarCode";
                }

                if (request.Amount < 1)
                {
                    oResponse.ErrCode = 2;
                    oResponse.ErrDesc = "Invalid Amount(Must be greater than 0)";
                }
                if (request.SiteID.ToString().Length < 4)
                {
                    oResponse.ErrCode = 3;
                    oResponse.ErrDesc = "Invalid SiteID(Must be a integer with 4 digits)";
                }
                //case -4:
                //    oResponse.ErrCode = 4;
                //    oResponse.ErrDesc = "Invalid RedeemedDateTime";
                //    break;
                if (request.RedeemedAsset.IsNullOrEmpty())
                {
                    oResponse.ErrCode = 5;
                    oResponse.ErrDesc = "Invalid Redeemed Asset";
                }
                if (request.PrintedAsset.IsNullOrEmpty())
                {
                    oResponse.ErrCode = 6;
                    oResponse.ErrDesc = "Invalid Printed Asset";
                }
                //case -7:
                //    oResponse.ErrCode = 7;
                //    oResponse.ErrDesc = "Invalid PrintedDateTime";
                //    break;
                //case -8:
                //    oResponse.ErrCode = 8;
                //    oResponse.ErrDesc = "Invalid ExpiryDate";
                //    break;
                if (request.Type.GetType() != typeof(VoucherTypeModel))
                {
                    oResponse.ErrCode = 9;
                    oResponse.ErrDesc = "Invalid Type";

                }
                //case -10:
                //    oResponse.ErrCode = 10;
                //    oResponse.ErrDesc = "Duplicate Entry";
                //    break;

                if (oResponse.ErrCode != 0)
                {
                    LogManager.WriteLog("ProcessVouchers Response: " + oResponse.ToString(), LogManager.enumLogLevel.Debug);
                    return oResponse;
                }

                //var sqlParameters = new SqlParameter[9];

                //sqlParameters[0] = new SqlParameter("@BarCode", request.BarCode);
                //sqlParameters[1] = new SqlParameter("@Amount", request.Amount);
                //sqlParameters[2] = new SqlParameter("@SiteID", request.SiteID);
                //sqlParameters[3] = new SqlParameter("@PaidDateTime", request.RedeemedDateTime);
                //sqlParameters[4] = new SqlParameter("@RedeemedAsset", request.RedeemedAsset);
                //sqlParameters[5] = new SqlParameter("@PrintedAsset", request.PrintedAsset);
                //sqlParameters[6] = new SqlParameter("@PrintedDateTime", request.PrintedDateTime);
                //sqlParameters[7] = new SqlParameter("@ExpiryDate", request.ExpiryDate);
                //sqlParameters[8] = new SqlParameter("@Ticket_Type", request.Type);

                var sqlParameters = new SqlParameter[4];
                sqlParameters[0] = new SqlParameter("@EventId", (int)request.Type);
                sqlParameters[1] = new SqlParameter("@EventDescription", request.Type.ToString().ToUpper());
                sqlParameters[2] = new SqlParameter("@XML", outStream.ToString());
                sqlParameters[3] = new SqlParameter("@Device", request.RedeemedAsset);
                int retval =  int.Parse(SqlHelper.ExecuteScalar(GetConnectionString(), CommandType.StoredProcedure, "usp_Vault_UpdateGenericMessage", sqlParameters).ToString());

                //if (SqlHelper.ExecuteNonQuery(GetConnectionString(), CommandType.StoredProcedure, "usp_UpdateVoucherInfo", sqlParameters) < 0)
                if (retval == 1)
                {
                    LogManager.WriteLog("Voucher Updated Successfully BarCode:" + request.BarCode + " Amount: " + request.Amount, LogManager.enumLogLevel.Info);
                }
                else
                {
                    LogManager.WriteLog("Unable to update Voucher:" + request.BarCode + " Amount: " + request.Amount, LogManager.enumLogLevel.Error);
                    if (retval == -701)
                    {
                        oResponse.ErrCode = 701;
                        oResponse.ErrDesc = "Vault not enrolled/invalid serial number";

                    }
                    else if (retval == -702)
                    {
                        oResponse.ErrCode = 702;
                        oResponse.ErrDesc = "Feature not enabled";

                    }
                    else
                    {
                        oResponse.ErrCode = -100;
                        oResponse.ErrDesc = "Unable to process request";
                    }
                }
                LogManager.WriteLog("ProcessVouchers Response: " + oResponse.ToString(), LogManager.enumLogLevel.Debug);

            }
            catch (Exception ex)
            {
                LogManager.WriteLog("Error in reading Voucher Info", LogManager.enumLogLevel.Error);
                ExceptionManager.Publish(ex);
                oResponse.ErrCode = -100;
                oResponse.ErrDesc = "Error Occured";
            }

            return oResponse; ;
        }
        public Response ProcessEvents(EventModel request)
        {
            Response oResponse = new Response();
            LogManager.WriteLog("VaultService: ProcessEvents -- Entered", LogManager.enumLogLevel.Info);
            try
            {
                StringWriter outStream = new StringWriter();

                XmlSerializer s = new XmlSerializer(typeof(EventModel));
                s.Serialize(outStream, request);
                string xml = outStream.ToString();
                LogManager.WriteLog("VaultService: ProcessEvents Xml" + xml.ToString(), LogManager.enumLogLevel.Info);
                outStream.Close();
                using (SqlConnection oConn = new SqlConnection(GetConnectionString()))
                {

                    try
                    {
                        oConn.Open();

                        if (request.DeviceID.IsNullOrEmpty())
                        {
                            oResponse.ErrCode = 1;
                            oResponse.ErrDesc = "Invalid DeviceID";
                        }
                        if (request.SiteID.ToString().Length < 4)
                        {
                            oResponse.ErrCode = 2;
                            oResponse.ErrDesc = "Invalid SiteID(Must be a integer with 4 digits)";
                        }
                        if (request.EventID < 1)
                        {
                            oResponse.ErrCode = 3;
                            oResponse.ErrDesc = "Invalid EventID";
                        }
                        if (request.EventDescription.IsNullOrEmpty())
                        {
                            oResponse.ErrCode = 4;
                            oResponse.ErrDesc = "Invalid EventDescription";
                        }


                        foreach (CassetteDetails cd in request.CassetteDetail)
                        {

                            if (cd.CassetteNumber.IsNullOrEmpty())
                            {
                                oResponse.ErrCode = 6;
                                oResponse.ErrDesc = "Invalid CassetteNumber";
                                break;
                            }

                            if (cd.CassetteLevel < 0)
                            {
                                oResponse.ErrCode = 7;
                                oResponse.ErrDesc = "Invalid CassetteLevel";
                                break;
                            }
                            if (cd.CassetteDenom < 1)
                            {
                                oResponse.ErrCode = 8;
                                oResponse.ErrDesc = "Invalid CassetteDenom";
                                break;
                            }

                            if (decimal.Parse( cd.CassetteLevel.ToString()) %decimal.Parse( cd.CassetteDenom.ToString()) > 0 )
                            {
                                oResponse.ErrCode = 8;
                                oResponse.ErrDesc = "Amount did not match CassetteDenom";
                                break;
                            }

                            if (cd.CassetteDescription.IsNullOrEmpty())
                            {
                                oResponse.ErrCode = 9;
                                oResponse.ErrDesc = "Invalid CassetteDescription";
                                break;
                            }
                        }


                        if (oResponse.ErrCode != 0)
                        {
                            LogManager.WriteLog("ProcessEvents Response: " + oResponse.ToString(), LogManager.enumLogLevel.Debug);
                            return oResponse;
                        }

                        //var sqlParameters = new SqlParameter[7];
                        //sqlParameters[0] = new SqlParameter("@DeviceID", request.DeviceID);
                        //sqlParameters[1] = new SqlParameter("@SiteID", request.SiteID);
                        //sqlParameters[2] = new SqlParameter("@EventID", request.EventID);
                        //sqlParameters[3] = new SqlParameter("@EventDescription", request.EventDescription);
                        //sqlParameters[4] = new SqlParameter("@EventDateTime", request.EventDateTime);
                        //sqlParameters[5] = new SqlParameter("@VaultEventID", SqlDbType.Int);
                        //sqlParameters[5].Direction = ParameterDirection.Output;
                        //sqlParameters[6] = new SqlParameter("@xml", xml);

                        //DataSet dtVaultEvent = SqlHelper.ExecuteDataset(oConn, CommandType.StoredProcedure, "usp_UpdateEventsInfo", sqlParameters);
                        var sqlParameters = new SqlParameter[4];
                        sqlParameters[0] = new SqlParameter("@EventId", request.EventID);
                        sqlParameters[1] = new SqlParameter("@EventDescription", request.EventDescription);
                        sqlParameters[2] = new SqlParameter("@XML", outStream.ToString());
                        sqlParameters[3] = new SqlParameter("@Device", request.DeviceID);
                        int retval = int.Parse(SqlHelper.ExecuteScalar(GetConnectionString(), CommandType.StoredProcedure, "usp_Vault_UpdateGenericMessage", sqlParameters).ToString());

                        if (retval == 1)
                        {
                            LogManager.WriteLog("Event Updated Successfully eventID:" + request.EventID, LogManager.enumLogLevel.Info);
                        }
                        else
                        {
                            LogManager.WriteLog("Event Update failed for  eventID:" + request.EventID, LogManager.enumLogLevel.Info);
                            if (retval == -701)
                            {
                                oResponse.ErrCode = 701;
                                oResponse.ErrDesc = "Vault not enrolled/invalid serial number";

                            }
                            else if (retval == -702)
                            {
                                oResponse.ErrCode = 702;
                                oResponse.ErrDesc = "Feature not enabled";

                            }
                            else
                            {
                                oResponse.ErrCode = -100;
                                oResponse.ErrDesc = "Unable to process request";
                            }
                        }



                    }
                    catch (Exception Ex)
                    {
                        ExceptionManager.Publish(Ex);
                    }
                }


            }
            catch (Exception ex)
            {
                LogManager.WriteLog("Error in reading Event Info", LogManager.enumLogLevel.Error);
                ExceptionManager.Publish(ex);
                oResponse.ErrCode = -100;
                oResponse.ErrDesc = "Error Occured";

            }
            LogManager.WriteLog("ProcessEvents Response: " + oResponse.ToString(), LogManager.enumLogLevel.Debug);
            return oResponse;
        }
        public Response ProcessHandpays(HandpayModel request)
        {
            Response oResponse = new Response();
            LogManager.WriteLog("VaultService: ProcessHandpays -- Entered", LogManager.enumLogLevel.Info);
            try
            {
                StringWriter outStream = new StringWriter();
                XmlSerializer s = new XmlSerializer(typeof(HandpayModel));

                s.Serialize(outStream, request);
                LogManager.WriteLog("VaultService: Handpays Xml" + outStream.ToString(), LogManager.enumLogLevel.Info);
                outStream.Close();


                if (request.Asset.IsNullOrEmpty())
                {
                    oResponse.ErrCode = 1;
                    oResponse.ErrDesc = "Invalid Asset";
                }
                if (request.RedeemedAsset.IsNullOrEmpty())
                {
                    oResponse.ErrCode = 2;
                    oResponse.ErrDesc = "Invalid Redeemed Asset";
                }
                if (request.SiteID.ToString().Length < 4)
                {
                    oResponse.ErrCode = 3;
                    oResponse.ErrDesc = "Invalid SiteID(Must be a integer with 4 digits)";
                }
                if (request.Amount < 1)
                {

                    oResponse.ErrCode = 4;
                    oResponse.ErrDesc = "Invalid Amount(Must be greater than 0)";
                }

                if (request.Type.GetType() != typeof(HandpayTypeModel))
                {
                    oResponse.ErrCode = 7;
                    oResponse.ErrDesc = "Invalid Type";
                }

                //case -5:
                //    oResponse.ErrCode = 5;
                //    oResponse.ErrDesc = "Invalid RedeemDateTime";
                //    break;
                //case -6:
                //    oResponse.ErrCode = 6;
                //    oResponse.ErrDesc = "Invalid GeneratedDateTime";
                //    break;

                if (oResponse.ErrCode != 0)
                {
                    LogManager.WriteLog("ProcessHandpays Response: " + oResponse.ToString(), LogManager.enumLogLevel.Debug);
                    return oResponse;

                }

                var sqlParameters = new SqlParameter[4];

                sqlParameters[0] = new SqlParameter("@EventId", (int)request.Type);
                sqlParameters[1] = new SqlParameter("@EventDescription", request.Type.ToString().ToUpper());
                sqlParameters[2] = new SqlParameter("@XML", outStream.ToString());
                sqlParameters[3] = new SqlParameter("@Device", request.RedeemedAsset);
                int retval = int.Parse( SqlHelper.ExecuteScalar(GetConnectionString(), CommandType.StoredProcedure, "usp_Vault_UpdateGenericMessage", sqlParameters).ToString());
                //var sqlParameters = new SqlParameter[7];

                //sqlParameters[0] = new SqlParameter("@Asset", request.Asset);
                //sqlParameters[1] = new SqlParameter("@RedeemedAsset", request.RedeemedAsset);
                //sqlParameters[2] = new SqlParameter("@SiteID", request.SiteID);
                //sqlParameters[3] = new SqlParameter("@Amount", request.Amount);
                //sqlParameters[4] = new SqlParameter("@RedeemDateTime", request.RedeemDateTime);
                //sqlParameters[5] = new SqlParameter("@GeneratedDateTime", request.GeneratedDateTime);
                //sqlParameters[6] = new SqlParameter("@Type", request.Type);

                //int iStatus = int.Parse(SqlHelper.ExecuteScalar(GetConnectionString(), CommandType.StoredProcedure, "usp_UpdateHandpayInfo", sqlParameters).ToString());
                //if (iStatus == -1)
                //{
                //    oResponse.ErrCode = 1;
                //    oResponse.ErrDesc = "Invalid Asset";
                //}
                //if (iStatus == 0)
                //{
                //    LogManager.WriteLog("Handpay Updated Successfully Asset:" + request.Asset + " Amount: " + request.Amount, LogManager.enumLogLevel.Info);
                //}
                if (retval == 1)
                {
                    LogManager.WriteLog("Handpay Updated Successfully Asset:" + request.Asset + " Amount: " + request.Amount, LogManager.enumLogLevel.Info);
                }
                else
                {
                    LogManager.WriteLog("Handpay Updated Failed Asset:" + request.Asset + " Amount: " + request.Amount, LogManager.enumLogLevel.Info);
                    if (retval == -701)
                    {
                        oResponse.ErrCode = 701;
                        oResponse.ErrDesc = "Vault not enrolled/invalid serial number";

                    }
                    else if (retval == -702)
                    {
                        oResponse.ErrCode = 702;
                        oResponse.ErrDesc = "Feature not enabled";

                    }
                    else
                    {
                        oResponse.ErrCode = -100;
                        oResponse.ErrDesc = "Unable to process request";
                    }
                }

            }
            catch (Exception ex)
            {
                LogManager.WriteLog("Error in reading Handpay Info", LogManager.enumLogLevel.Error);
                ExceptionManager.Publish(ex);
                oResponse.ErrCode = -100;
                oResponse.ErrDesc = "Error Occured";
            }
            LogManager.WriteLog("ProcessHandpays Response: " + oResponse.ToString(), LogManager.enumLogLevel.Debug);
            return oResponse;
        }