Exemplo n.º 1
0
        public void Register_ReturnedWithGet()
        {
            const string key = "Key";

            _service.RegisterPersistentEntity(key, _entity);

            Assert.AreSame(_entity, _service.GetEntities()[key]);
        }
Exemplo n.º 2
0
        public UserViewModel(UserAccount user) : base(user)
        {
            this.person = user.getPerson();
            var svc = new PersistenceService();

            AvailableRoles   = from role in svc.GetEntities <Employee>() select new RoleViewModel(role);
            this.dateOfBirth = this.person.getDOB()?.ToShortDateString();
        }
Exemplo n.º 3
0
        public void Start()
        {
            _persistenceService = new PersistenceService("red", "Tastyred1");

            //Subscribe to general entity changed events
            _persistenceService.AddAllEntityTypesUpdatedHandler(x => OnAnyEntitiesUpdated(x));

            string input = null;

            while (input != "q" && _exiting == false)
            {
                Console.WriteLine("Ready to send data. Type any key to send, or q to quit.");
                input = Console.ReadLine().ToLower();
                if (input == "q" || _exiting == true)
                {
                    break;
                }

                var owner = new Owner
                {
                    OwnerID = 1,
                    State   = ObjectState.Unchanged
                };

                ProductPhysicalAttribute physicalAttribute = new ProductPhysicalAttribute
                {
                    Weight          = 200,
                    Height          = 100,
                    Length          = 300,
                    Width           = 50,
                    PackagedWeight  = 400,
                    PackagingHeight = 110,
                    PackagingWidth  = 100,
                    PackagingLength = 310,
                    State           = ObjectState.Unchanged
                };

                Product strangeProduct = new Product
                {
                    Barcode           = "X443543454435",
                    Owner             = owner,
                    PhysicalAttribute = physicalAttribute,
                    Description       = "Strange one",
                    Name  = "Whatevs",
                    State = ObjectState.Modified
                };

                ProductCategory category = new ProductCategory
                {
                    Name                  = "Wij Category",
                    Description           = "Just testing categories",
                    ProductAttribute1Name = "Hands",
                    ProductAttribute2Name = "Shoulders",
                    ProductAttribute3Name = "Knees",
                    ProductAttribute4Name = "Toes",
                    CategoryProducts      = new List <Product> {
                        strangeProduct
                    },
                    State = ObjectState.Unchanged,
                };

                strangeProduct.Category = category;

                Product nonExistentOwnerProduct = new Product
                {
                    Barcode           = "X545646465645",
                    Owner             = owner,
                    PhysicalAttribute = physicalAttribute,
                    Description       = "Wrong one.",
                    Name     = "Jabba the hut",
                    Category = category,
                    State    = ObjectState.Added
                };



                //ProductCategory category = new ProductCategory
                //{
                //    Name = "Test category",
                //    Description = null,
                //    ProductAttribute1Name = "Fish Type",
                //    ProductAttribute2Name = "No of Elbows",
                //    ProductAttribute3Name = "Favourite Biscuit",
                //    State = ObjectState.Added
                //};

                //Product okProduct = new Product
                //{
                //    Barcode = "X545646465623",
                //    Owner = ownerNew,
                //    PhysicalAttribute = physicalAttribute,
                //    Description = "Right one.",
                //    Name = "Pricess Leia",
                //    Category = category,
                //    State = ObjectState.Added
                //};

                ////Do some updates
                Guid requestId;
                //requestId = _persistenceService.UpdateEntities(x => OnEntitiesUpdated(x), new List<Owner> { ownerNew, ownerNew2 });
                //_logger.Log(LogLevel.Debug, string.Format("Sending entity update request: {0}", requestId.ToString()));

                requestId = _persistenceService.UpdateEntities(x => OnEntitiesUpdated(x), new List <Product> {
                    nonExistentOwnerProduct
                });
                _logger.Log(LogLevel.Debug, string.Format("Sending entity update request: {0}", requestId.ToString()));

                //requestId = _persistenceService.UpdateEntities(x => OnEntitiesUpdated(x), new List<Product> { editButDoesntExistProduct, okProduct });
                //_logger.Log(LogLevel.Debug, string.Format("Sending entity update request: {0}", requestId.ToString()));



                ////Grab some warehouse products
                //requestId = _persistenceService.GetEntities<WarehouseProduct>(
                //    response => OnGetEntities(response),
                //    x => true, // Get everything (no filter)
                //    x => x.Warehouse); //Include warehouse nav property
                //_logger.Log(LogLevel.Debug, string.Format("Sending entity list request: {0}", requestId.ToString()));

                ////Grab some products
                //requestId = _persistenceService.GetEntities<Product>(
                //    response => OnGetEntities(response),
                //    x => true, // Get everything (no filter)
                //    x => x.Owner,
                //    x => x.MarketplaceProducts,
                //    x => x.Category); //Include warehouse nav property
                //_logger.Log(LogLevel.Debug, string.Format("Sending entity list request: {0}", requestId.ToString()));

                //Grab some markeplace products
                requestId = _persistenceService.GetEntities <MarketplaceProduct>(
                    response => OnGetEntities(response),
                    marketplaceProduct => true, // Get everything (no filter)
                    marketplaceProduct => marketplaceProduct.Marketplace,
                    marketplaceProduct => marketplaceProduct.Product,
                    marketplaceProduct => marketplaceProduct.VariationTheme,
                    marketplaceProduct => marketplaceProduct.Product.PhysicalAttribute,
                    marketplaceProduct => marketplaceProduct.Product.Owner);
                _logger.Log(LogLevel.Debug, string.Format("Sending entity list request: {0}", requestId.ToString()));


                requestId = _persistenceService.GetEntities <Product>(
                    response => OnGetEntities(response),
                    product => true,              // Get everything (no filter)
                    product => product.Owner,     //Include owner nav property
                    product => product.PhysicalAttribute,
                    Product => Product.Category); //Include physical attribute nav property
                _logger.Log(LogLevel.Debug, string.Format("Sending entity list request: {0}", requestId.ToString()));


                ////Grab some markeplace products
                //requestId = _persistenceService.GetPagedEntities<MarketplaceProduct>(
                //    response => OnGetPagedEntities(response),
                //    1,
                //    50,
                //    x => true, // Get everything (no filter)
                //    x => x.Marketplace,
                //    x => x.Product); //Include product nav property
                //_logger.Log(LogLevel.Debug, string.Format("Sending paged entity list request: {0}", requestId.ToString()));


                //requestId = _persistenceService.GetEntities<MarketplaceProduct>(
                //    a => OnGetEntities(a),
                //    b => b.Product.Barcode == "5060248979266",
                //    f => f.Product.Owner.Products,
                //    f => f.Product,
                //    f => f.Product.Owner,
                //    f => f.ProductCondition,
                //    f => f.Product.MarketplaceProducts,
                //    f => f.FulfilmentWarehouse);
                //_logger.Log(LogLevel.Debug, string.Format("Sending entity list request: {0}", requestId.ToString()));

                //requestId = _persistenceService.GetEntities<Product>(
                //    a => OnGetEntities(a),
                //    b => true,
                //    null);
                //_logger.Log(LogLevel.Debug, string.Format("Sending entity list request: {0}", requestId.ToString()));

                //requestId = _persistenceService.GetEntities<MarketplaceProduct>(
                //    a => OnGetEntities(a),
                //    b => true,
                //    null);
                //_logger.Log(LogLevel.Debug, string.Format("Sending entity list request: {0}", requestId.ToString()));

                //requestId = _persistenceService.GetEntities<Country>(
                //    a => OnGetEntities(a),
                //    b => true,
                //    c => c.Warehouses, d => d.StateProvinces);
                //_logger.Log(LogLevel.Debug, string.Format("Sending entity list request: {0}", requestId.ToString()));
            }

            Stop();
        }
        /// <summary>
        /// Gets a user by the specified login.
        /// </summary>
        /// <param name="login">User login.</param>
        /// <returns>User account instance, or null, if no user for the specified login found.</returns>
        internal static UserAccount GetUser(string login)
        {
            var users = PersistenceService.GetEntities <UserAccount>();

            return(users.FirstOrDefault(user => user.getUserId().ToLower() == login.ToLower()));
        }
 /// <summary>
 /// Gets a list of models of the specified type.
 /// </summary>
 /// <typeparam name="T">The model type.</typeparam>
 /// <returns>A list of model instances.</returns>
 internal static IList <T> Get <T>() where T : PersistentEntity => PersistenceService.GetEntities <T>();