public IActionResult AddState(AddStateRequestModel stateRequest)
        {
            try
            {
                bool   status = false;
                string message;

                AddStateResponseModel addState = _stateBusiness.AddState(stateRequest);

                if (addState != null)
                {
                    if (addState.ErrorResponse.ErrorStatus)
                    {
                        message = addState.ErrorResponse.Message;
                        return(Ok(new { status, message }));
                    }
                    status  = true;
                    message = "State Added Sucessfully";
                    StateAddResponseModel data = addState.StateAdd;
                    return(Ok(new { status, message, data }));
                }

                message = "Unable to Add the State";
                return(Ok(new { status, message }));
            }
            catch (Exception e)
            {
                return(BadRequest(new { e.Message }));
            }
        }
        /// <summary>
        /// It fetch all the State available in the db
        /// </summary>
        /// <returns>list of all the state</returns>
        public List <StateAddResponseModel> GetAllState()
        {
            try
            {
                int           statusCode;
                SqlDataReader reader;
                List <StateAddResponseModel> states = null;

                using (SqlConnection connection = new SqlConnection(sqlConnection))
                {
                    SqlCommand sqlCommand = new SqlCommand("spState", connection)
                    {
                        CommandType = System.Data.CommandType.StoredProcedure
                    };
                    sqlCommand.Parameters.AddWithValue("@StateId", -1);
                    sqlCommand.Parameters.AddWithValue("@Name", "");
                    sqlCommand.Parameters.AddWithValue("@ActionType", "GetAll");

                    SqlParameter cmdExecuteSuccess = sqlCommand.Parameters.Add("@return_value", System.Data.SqlDbType.Int);
                    cmdExecuteSuccess.Direction = System.Data.ParameterDirection.ReturnValue;

                    connection.Open();

                    reader     = sqlCommand.ExecuteReader();
                    statusCode = Convert.ToInt32(sqlCommand.Parameters["@return_Value"].Value);

                    if (statusCode == 0)
                    {
                        states = new List <StateAddResponseModel>();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                StateAddResponseModel createParty = new StateAddResponseModel
                                {
                                    StateId    = Convert.ToInt32(reader[0]),
                                    Name       = reader[1].ToString(),
                                    CreatedAt  = Convert.ToDateTime(reader[2]),
                                    ModifiedAt = Convert.ToDateTime(reader[3])
                                };
                                states.Add(createParty);
                            }
                        }
                    }
                }

                return(states);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// It fetches the specific state by its id
        /// </summary>
        /// <param name="StateId">State Id</param>
        /// <returns>State Add Response Model</returns>
        public StateAddResponseModel GetStateById(int StateId)
        {
            try
            {
                SqlDataReader         reader;
                StateAddResponseModel State = null;

                using (SqlConnection connection = new SqlConnection(sqlConnection))
                {
                    SqlCommand sqlCommand = new SqlCommand("spState", connection)
                    {
                        CommandType = System.Data.CommandType.StoredProcedure
                    };
                    sqlCommand.Parameters.AddWithValue("@StateId", StateId);
                    sqlCommand.Parameters.AddWithValue("@Name", "");
                    sqlCommand.Parameters.AddWithValue("@ActionType", "GetById");

                    connection.Open();

                    reader = sqlCommand.ExecuteReader();

                    if (reader.HasRows)
                    {
                        State = new StateAddResponseModel();

                        while (reader.Read())
                        {
                            State.StateId    = Convert.ToInt32(reader[0]);
                            State.Name       = reader[1].ToString();
                            State.CreatedAt  = Convert.ToDateTime(reader[2]);
                            State.ModifiedAt = Convert.ToDateTime(reader[3]);
                        }
                    }
                }

                return(State);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public IActionResult GetStateById(int StateId)
        {
            try
            {
                bool   status = false;
                string message;

                StateAddResponseModel data = _stateBusiness.GetStateById(StateId);

                if (data != null)
                {
                    status  = true;
                    message = "Here is the State Details";
                    return(Ok(new { status, message, data }));
                }
                message = "Unable to Fetch the State Details";
                return(Ok(new { status, message }));
            }
            catch (Exception e)
            {
                return(BadRequest(new { e.Message }));
            }
        }