Beispiel #1
0
        /// <summary>
        /// Gets the object ids for the dashboard
        /// </summary>
        Dictionary <string, List <int> > GetObjectIdsForDashboard(int userId, DateTime searchOlderThan, int numberToReturn)
        {
            if (userId <= 0)
            {
                throw new ArgumentOutOfRangeException("userId");
            }

            using (var command = StoredProcedureCommand.Make("GetObjectIdsForDashboard")
                                 .UsingConnection(this.DataContextActivationInfo.ConnectionString)
                                 .WithParam("@UserId", userId)
                                 .WithParam("@Amount", numberToReturn)
                                 .WithParam("@OlderThanDate", searchOlderThan))
            {
                var results = command.GetDataSet();

                var dictionary = new Dictionary <string, List <int> >();

                // if no results just grab the newest recipes and brews
                if (results.Tables[0].Rows.Count < 1)
                {
                    var resultsNewest = StoredProcedureCommand.Make("GetObjectIdsForDashboardNewest")
                                        .UsingConnection(this.DataContextActivationInfo.ConnectionString)
                                        .WithParam("@Amount", numberToReturn)
                                        .WithParam("@OlderThanDate", searchOlderThan)
                                        .GetDataSet();

                    dictionary.Add("Recipe", resultsNewest.Tables[0].Rows.Cast <DataRow>().Where(x => x["Type"].ToString() == "Recipe").Select(x => Convert.ToInt32(x["Id"])).ToList());
                    dictionary.Add("BrewSession", resultsNewest.Tables[0].Rows.Cast <DataRow>().Where(x => x["Type"].ToString() == "BrewSession").Select(x => Convert.ToInt32(x["Id"])).ToList());
                    dictionary.Add("TastingNote", resultsNewest.Tables[0].Rows.Cast <DataRow>().Where(x => x["Type"].ToString() == "TastingNote").Select(x => Convert.ToInt32(x["Id"])).ToList());
                }
                else
                {
                    dictionary.Add("Recipe", results.Tables[0].Rows.Cast <DataRow>().Where(x => x["Type"].ToString() == "Recipe").Select(x => Convert.ToInt32(x["Id"])).ToList());
                    dictionary.Add("BrewSession", results.Tables[0].Rows.Cast <DataRow>().Where(x => x["Type"].ToString() == "BrewSession").Select(x => Convert.ToInt32(x["Id"])).ToList());
                    dictionary.Add("TastingNote", results.Tables[0].Rows.Cast <DataRow>().Where(x => x["Type"].ToString() == "TastingNote").Select(x => Convert.ToInt32(x["Id"])).ToList());
                }

                return(dictionary);
            }
        }
        private CommandBase createCommandBase(StructureMapCommandType commandType, string commandText)
        {
            CommandBase returnValue = null;

            switch (commandType)
            {
            case StructureMapCommandType.Parameterized:
                returnValue = new ParameterizedCommand(commandText);
                break;

            case StructureMapCommandType.Templated:
                returnValue = new TemplatedCommand(commandText, _database);
                break;

            case StructureMapCommandType.StoredProcedure:
                returnValue = new StoredProcedureCommand(commandText, this);
                break;
            }

            returnValue.Attach(this);

            return(returnValue);
        }