示例#1
0
        /// <summary>
        /// Find all matching datasets within the database based on the
        /// given dataset and the DSFindBy method.
        /// </summary>
        /// <param name="data">The dataset is used as the sought value</param>
        /// <param name="findBy">The method to search by</param>
        /// <param name="db">The active database context to seach</param>
        /// <returns>The datasets that match</returns>
        private static MovingAverageDS[] Find(MovingAverageDS data, DSFindBy findBy, DatasetContext db)
        {
            MovingAverageDS[] toReturn = null;

            switch (findBy)
            {
            case DSFindBy.Data:
                toReturn = (from MovingAverageDS ds in db.dataSets
                            where data.data == ds.data
                            select ds).ToArray();
                break;

            case DSFindBy.Id:
                toReturn = (from MovingAverageDS ds in db.dataSets
                            where data.id == ds.id
                            select ds).ToArray();
                break;

            case DSFindBy.WindowSize:
                toReturn = (from MovingAverageDS ds in db.dataSets
                            where data.windowSize == ds.windowSize
                            select ds).ToArray();
                break;

            case DSFindBy.Name:
                toReturn = (from MovingAverageDS ds in db.dataSets
                            where data.name == ds.name
                            select ds).ToArray();
                break;
            }

            return(toReturn);
        }
示例#2
0
        /// <summary>
        /// Handle a database operation for the datasets.
        /// </summary>
        /// <param name="operation">The operation to perform</param>
        /// <param name="data">The data to be used for the operation. Ignored by GetAll operation</param>
        /// <param name="findBy">The method by which to find the data. Only used by the Find operation</param>
        /// <returns>The output of the operation</returns>
        public static MovingAverageDS[] Operation(DSOperation operation, MovingAverageDS data = null, DSFindBy findBy = DSFindBy.Id)
        {
            MovingAverageDS[] toReturn = null;

            using (DatasetContext db = new DatasetContext())
            {
                switch (operation)
                {
                case DSOperation.Add:
                    toReturn = new MovingAverageDS[] { Add(data, db) };
                    break;

                case DSOperation.Delete:
                    Delete(data, db);
                    break;

                case DSOperation.Modify:
                    Modify(data, db);
                    break;

                case DSOperation.Find:
                    toReturn = Find(data, findBy, db);
                    break;

                case DSOperation.GetAll:
                    toReturn = GetAll(db);
                    break;
                }

                db.SaveChanges();
            }

            return(toReturn);
        }