示例#1
0
        public void Data_ReadOnlyDatabase_CountAny()
        {
            var db = ReadOnlyDatabase <CustomerType> .Construct();

            // GetAll() count and any
            var resultsAll = db.GetAll();

            Assert.IsTrue(resultsAll.Count() > 0);
            Assert.IsTrue(resultsAll.Any() == true);

            // GetAll().Take(1) count and any
            var resultsTake = db.GetAll().Take(1);

            Assert.IsTrue(resultsTake.Count() == 1);
            Assert.IsTrue(resultsTake.Any() == true);

            // Get an ID to test
            var id = db.GetAllExcludeDefault().FirstOrDefaultSafe().ID;

            Assert.IsTrue(id != TypeExtension.DefaultInteger);

            // GetAll().Where count and any
            var resultsWhere = db.GetAll().Where(x => x.ID == id);

            Assert.IsTrue(resultsWhere.Count() > 0);
            Assert.IsTrue(resultsWhere.Any() == true);
        }
示例#2
0
        public ActionResult Summary(CustomerModel model)
        {
            var reader = ReadOnlyDatabase <CustomerInfo> .Construct();

            model.Fill(reader.GetByID(model.ID));
            return(View(CustomerController.EditView, model));
        }
示例#3
0
        public void Data_ReadOnlyDatabase_GetAll()
        {
            var typeDB = ReadOnlyDatabase <CustomerType> .Construct();

            var typeResults = typeDB.GetAll().Take(1);

            Assert.IsTrue(typeResults.Count() > 0);
        }
示例#4
0
        /// <summary>
        /// Loads an existing object MyBased on ID.
        /// </summary>
        /// <param name="key">The unique GUID of this object. ID and Key are both identifiers.</param>
        public TEntity GetByKey(Guid key)
        {
            var db = ReadOnlyDatabase <TEntity> .Construct();

            var returnValue = new TEntity();

            returnValue = db.Data.Where(x => x.Key == key).FirstOrDefaultSafe();

            return(returnValue);
        }
示例#5
0
        /// <summary>
        /// Loads an existing object MyBased on ID.
        /// </summary>
        /// <param name="id">The unique ID of the object</param>
        public TEntity GetByID(int id)
        {
            var db = ReadOnlyDatabase <TEntity> .Construct();

            var returnValue = new TEntity();

            returnValue = db.Data.Where(x => x.ID == id).FirstOrDefaultSafe();

            return(returnValue);
        }
示例#6
0
        /// <summary>
        /// Returns all entities
        /// </summary>
        /// <returns></returns>
        public IQueryable <TEntity> GetAllExcludeDefault()
        {
            var db = ReadOnlyDatabase <TEntity> .Construct();

            var returnValue = default(IQueryable <TEntity>);

            returnValue = db.GetAllExcludeDefault();

            return(returnValue);
        }
示例#7
0
        public void Data_ReadOnlyDatabase_GetByKey()
        {
            var custData = ReadOnlyDatabase <CustomerType> .Construct();

            // ByKey Should return 1 record
            var existingKey  = custData.GetAll().FirstOrDefaultSafe().Key;
            var custWhereKey = custData.GetAll().Where(x => x.Key == existingKey);

            Assert.IsTrue(custWhereKey.Count() > 0);
        }
示例#8
0
        /// <summary>
        /// Retrieves data with purpose of displaying results over multiple pages (i.e. in Grid/table)
        /// </summary>
        /// <param name="whereClause">Expression for where clause</param>
        /// <returns></returns>
        public IQueryable <TEntity> GetByWhere(Expression <Func <TEntity, Boolean> > whereClause)
        {
            var db = ReadOnlyDatabase <TEntity> .Construct();

            var returnValue = default(IQueryable <TEntity>);

            returnValue = (whereClause != null) ? db.Data.Where <TEntity>(whereClause) : db.Data;

            return(returnValue);
        }
示例#9
0
        /// <summary>
        /// Reads this object from the database, using the passed predicate
        /// </summary>
        /// <returns>Objects found</returns>
        public virtual IQueryable <TEntity> Read()
        {
            var db = ReadOnlyDatabase <TEntity> .Construct();

            var returnValue = default(IQueryable <TEntity>);

            returnValue = db.Data;

            return(returnValue);
        }
示例#10
0
        /// <summary>
        /// Gets all records that equal first + last + birth date
        /// Does == style search
        /// </summary>
        /// <param name="firstName">First name of customer</param>
        /// <param name="lastName">Last Name of customer</param>
        /// <param name="birthDate">Birth Date of customer</param>
        /// <returns></returns>
        public static IQueryable <CustomerInfo> GetByNameBirthdayKey(string firstName, string lastName, DateTime birthDate)
        {
            var reader = ReadOnlyDatabase <CustomerInfo> .Construct();

            IQueryable <CustomerInfo> returnValue = reader.GetAll()
                                                    .Where(x => (firstName != TypeExtension.DefaultString && x.FirstName == firstName) &&
                                                           (lastName != TypeExtension.DefaultString && x.LastName == lastName) &&
                                                           (birthDate != TypeExtension.DefaultDate && x.BirthDate == birthDate));

            return(returnValue);
        }
示例#11
0
        /// <summary>
        /// Gets all records that contain any of the passed fields.
        /// Does contains/like style search
        /// </summary>
        /// <param name="searchFields">ICustomer with data to search</param>
        /// <returns>All records matching the passed ICustomer</returns>
        public static IQueryable <CustomerInfo> GetByAny(ICustomer searchFields)
        {
            var reader = ReadOnlyDatabase <CustomerInfo> .Construct();

            IQueryable <CustomerInfo> returnValue = reader.GetAll()
                                                    .Where(x => (searchFields.FirstName != TypeExtension.DefaultString && x.FirstName.Contains(searchFields.FirstName)) ||
                                                           (searchFields.LastName != TypeExtension.DefaultString && x.LastName.Contains(searchFields.LastName)) ||
                                                           (searchFields.BirthDate != TypeExtension.DefaultDate && x.BirthDate == searchFields.BirthDate) ||
                                                           (x.ID == searchFields.ID));

            return(returnValue);
        }
示例#12
0
        public ActionResult Summary(string id)
        {
            var reader = ReadOnlyDatabase <CustomerInfo> .Construct();

            var model = new CustomerModel();

            model.Fill(reader.GetByID(id.TryParseInt32()));
            if (model.ID == TypeExtension.DefaultInteger)
            {
                ModelState.AddModelError("", "No customer found");
            }
            return(View(CustomerController.SummaryView, model));
        }
        public CustomerModel Post(CustomerModel model)
        {
            var reader = ReadOnlyDatabase <CustomerInfo> .Construct();

            CustomerInfo customer = new CustomerInfo();

            customer = reader.GetByID(model.ID);
            customer.Fill(model); // Overlay all screen edits on-top of the data-access-object, to preserve untouched original data
            customer.Save();
            model.Fill(customer); // Go back to model for transport

            return(model);
        }
示例#14
0
        public void Data_ReadOnlyDatabase_Lists()
        {
            var emptyGuid = TypeExtension.DefaultGuid;

            // List Type
            var typeDB = ReadOnlyDatabase <CustomerType> .Construct();

            var typeResults = typeDB.GetAllExcludeDefault();

            Assert.IsTrue(typeResults.Count() > 0);
            Assert.IsTrue(typeResults.Any(x => x.Key == emptyGuid) == false);
            Assert.IsTrue(typeResults.Any(x => x.ID == -1) == false);
        }
示例#15
0
        public void Data_ReadOnlyDatabase_GetWhere()
        {
            // Plain EntityInfo object
            var typeData = ReadOnlyDatabase <CustomerType> .Construct();

            var testType = new CustomerType();
            var testId   = typeData.GetAllExcludeDefault().FirstOrDefaultSafe().ID;

            testType = typeData.GetAll().Where(x => x.ID == testId).FirstOrDefaultSafe();
            Assert.IsTrue(testType.IsNew == false);
            Assert.IsTrue(testType.ID != TypeExtension.DefaultInteger);
            Assert.IsTrue(testType.Key != TypeExtension.DefaultGuid);
        }
        public CustomerModel Delete(string id)
        {
            var reader = ReadOnlyDatabase <CustomerInfo> .Construct();

            CustomerInfo  customer = new CustomerInfo();
            CustomerModel model    = new CustomerModel();

            customer = reader.GetByID(id.TryParseInt32());
            customer.Delete();
            customer = reader.GetByID(id.TryParseInt32()); // Verify delete, success returns empty object
            model.Fill(customer);

            return(model);
        }
示例#17
0
        /// <summary>
        /// Retrieves data with purpose of displaying results over multiple pages (i.e. in Grid/table)
        /// </summary>
        /// <param name="whereClause">Expression for where clause</param>
        /// <param name="orderByClause">Expression for order by clause</param>
        /// <param name="pageSize">Size of each result</param>
        /// <param name="pageNumber">Page number</param>
        /// <returns></returns>
        public IQueryable <TEntity> GetByPage(Expression <Func <TEntity, Boolean> > whereClause, Expression <Func <TEntity, Boolean> > orderByClause, int pageSize, int pageNumber)
        {
            var db = ReadOnlyDatabase <TEntity> .Construct();

            var datastore = ReadOnlyDatabase <TEntity> .Construct();

            var returnValue = default(IQueryable <TEntity>);

            returnValue = (datastore.Data).AsQueryable();
            returnValue = (whereClause != null) ? returnValue.Where <TEntity>(whereClause).AsQueryable() : returnValue;
            returnValue = (orderByClause != null) ? returnValue.OrderBy(orderByClause).AsQueryable() : returnValue;
            returnValue = (pageNumber > 0 && pageSize > 0) ? returnValue.Skip((pageNumber * pageSize)).Take(pageSize).AsQueryable() : returnValue;

            return(returnValue);
        }
        public CustomerModel Get(string id)
        {
            var reader = ReadOnlyDatabase <CustomerInfo> .Construct();

            CustomerInfo  customer = new CustomerInfo();
            CustomerModel model    = new CustomerModel();

            customer = reader.GetByID(id.TryParseInt32());
            if (customer.ID != TypeExtension.DefaultInteger)
            {
                model.Fill(customer); // Go back to model for transport
            }

            return(model);
        }
示例#19
0
        public void Data_ReadOnlyDatabase_GetByID()
        {
            var custData = ReadOnlyDatabase <CustomerType> .Construct();

            var custEntity = new CustomerType();

            var existingID  = custData.GetAllExcludeDefault().FirstOrDefaultSafe().ID;
            var custWhereID = custData.GetAll().Where(x => x.ID == existingID);

            Assert.IsTrue(custWhereID.Count() > 0);
            Assert.IsTrue(custWhereID.Any() == true);

            custEntity = custWhereID.FirstOrDefaultSafe();
            Assert.IsTrue(custEntity.ID == existingID);
            Assert.IsTrue(custEntity.IsNew == false);
        }
        public CustomerModel Get(string id)
        {
            var reader = ReadOnlyDatabase <CustomerInfo> .Construct();

            var customer = new CustomerInfo();

            if (id.IsInteger())
            {
                customer = reader.GetByID(id.TryParseInt32());
            }
            else
            {
                customer = reader.GetByKey(id.TryParseGuid());
            }

            return(customer.CastOrFill <CustomerModel>());
        }
示例#21
0
        public void Data_ReadOnlyDatabase_Singles()
        {
            var typeDB = ReadOnlyDatabase <CustomerType> .Construct();

            var testItem  = new CustomerType();
            var emptyGuid = TypeExtension.DefaultGuid;

            // By ID
            testItem = typeDB.GetByID(typeDB.GetAllExcludeDefault().FirstOrDefaultSafe().ID);
            Assert.IsTrue(testItem.IsNew == false);
            Assert.IsTrue(testItem.ID != TypeExtension.DefaultInteger);
            Assert.IsTrue(testItem.Key != TypeExtension.DefaultGuid);

            // By Key
            testItem = typeDB.GetByKey(typeDB.GetAllExcludeDefault().FirstOrDefaultSafe().Key);
            Assert.IsTrue(testItem.IsNew == false);
            Assert.IsTrue(testItem.ID != TypeExtension.DefaultInteger);
            Assert.IsTrue(testItem.Key != TypeExtension.DefaultGuid);
        }
示例#22
0
        public ActionResult Delete(CustomerModel model)
        {
            var reader = ReadOnlyDatabase <CustomerInfo> .Construct();

            var customer = new CustomerInfo();

            customer = reader.GetByID(model.ID);
            customer.Delete();
            customer = reader.GetByID(model.ID); // Verify delete, success returns empty object
            if (customer.ID == TypeExtension.DefaultInteger)
            {
                model.Fill(customer); // Fill the CustomerModel view model, so the class can be specific to the screen's needs and drop the heavy data access items.
                ModelState.AddModelError("", "Successfully deleted");
            }
            else
            {
                ModelState.AddModelError("", "Failed to delete");
            }

            return(View(CustomerController.SummaryView, model));
        }
示例#23
0
        public ActionResult Edit(CustomerModel model)
        {
            var reader = ReadOnlyDatabase <CustomerInfo> .Construct();

            var customer = new CustomerInfo();

            customer = reader.GetByID(model.ID);
            customer.Fill(model); // Overlay all screen edits on-top of the data-access-object, to preserve untouched original data
            customer.Save();
            model.Fill(customer); // Go back to screen model for ui-specific functionality to be available to view/page
            if (customer.IsNew == false)
            {
                ModelState.AddModelError("", "Successfully saved");
            }
            else
            {
                ModelState.AddModelError("", "Failed to save");
            }

            return(View(CustomerController.SummaryView, model));
        }
示例#24
0
        /// <summary>
        /// Gets all records that exactly equal passed name
        /// </summary>
        /// <param name="name">Value to search CustomerTypeName field </param>
        /// <returns>All records matching the passed name</returns>
        public static IQueryable <CustomerType> GetByName(string name)
        {
            var reader = ReadOnlyDatabase <CustomerType> .Construct();

            return(reader.GetAll().Where(x => x.Name == name));
        }
示例#25
0
        /// <summary>
        /// Gets database record with exact ID match
        /// </summary>
        /// <param name="id">Database ID of the record to pull</param>
        /// <returns>Single entity that matches by id, or an empty entity for not found</returns>
        public static TEntity GetByID(int id)
        {
            var db = ReadOnlyDatabase <TEntity> .Construct();

            return(db.GetByID(id));
        }
示例#26
0
        /// <summary>
        /// Gets database record with exact Key match
        /// </summary>
        /// <param name="key">Database Key of the record to pull</param>
        /// <returns>Single entity that matches by Key, or an empty entity for not found</returns>
        public static TEntity GetByKey(Guid key)
        {
            var db = ReadOnlyDatabase <TEntity> .Construct();

            return(db.GetByKey(key));
        }