Esempio n. 1
0
        /// <summary>
        /// Gets a customer
        /// </summary>
        /// <param name="customerKey"></param>
        /// <returns></returns>
        public Sample.Azure.Model.Customer.CustomerModel Select(Guid customerId)
        {
            CustomerDataServiceContext context = new CustomerDataServiceContext();
            Customer customer = context.Select(customerId);

            if (customer == null)
            {
                return(null);
            }
            else
            {
                // Copy from Azure model to POCO model
                Sample.Azure.Model.Customer.CustomerModel customerModel = new Model.Customer.CustomerModel();

                customerModel.CustomerId      = customerId;
                customerModel.CustomerName    = customer.CustomerName;
                customerModel.CustomerAddress = customer.CustomerAddress;
                customerModel.CustomerCity    = customer.CustomerCity;
                customerModel.CustomerState   = customer.CustomerState;
                customerModel.CustomerZip     = customer.CustomerZip;
                customerModel.CustomerRanking = customer.CustomerRanking;


                customerModel.DateCreated = customer.DateCreated;
                customerModel.DateDeleted = customer.DateDeleted;
                customerModel.DateUpdated = customer.DateUpdated;
                customerModel.IsDeleted   = customer.IsDeleted;
                customerModel.UserCreated = customer.UserCreated;
                customerModel.UserDeleted = customer.UserDeleted;
                customerModel.UserUpdated = customer.UserUpdated;
                customerModel.RowVersion  = customer.RowVersion;
                return(customerModel);
            }
        } // Select
Esempio n. 2
0
        /// <summary>
        /// Validates and saves a customer
        /// </summary>
        /// <param name="customerModel"></param>
        public void Save(Model.Customer.CustomerModel customerModel)
        {
            Common.Validation.ValidationService validationService = new Common.Validation.ValidationService();
            validationService.ValidateObject(customerModel);

            customerRepository.InsertOrReplace(customerModel);
        }
Esempio n. 3
0
        public void CustomerAzureSearch()
        {
            Model.Customer.CustomerModel customerModel = this.CreateCustomerModel();

            Interface.Service.ICustomerService customerService = DI.Container.Resolve <Interface.Service.ICustomerService>();
            customerService.Save(customerModel);

            Model.Search.SearchCustomerModel searchCustomerModel = new Model.Search.SearchCustomerModel();
            searchCustomerModel.CustomerId   = customerModel.CustomerId.ToString().ToLower();
            searchCustomerModel.CustomerName = customerModel.CustomerName;

            Interface.Repository.IIndexerRepository azureSearch = DI.Container.Resolve <Interface.Repository.IIndexerRepository>();

            azureSearch.UpsertCustomer(Interface.GlobalEnum.IndexerIndexName.Customer, searchCustomerModel);

            List <Model.Search.SearchCustomerModel> list = azureSearch.CustomerSearch(Interface.GlobalEnum.IndexerIndexName.Customer, customerModel.CustomerName);

            bool found = false;

            foreach (var item in list)
            {
                if (item.CustomerName == customerModel.CustomerName)
                {
                    Assert.AreEqual(list[0].CustomerName, customerModel.CustomerName);
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                Assert.Fail("Could not find customer in Azure Search");
            }
        } // CustomerAzureSearch
Esempio n. 4
0
        public void CustomerRedisCache()
        {
            Model.Customer.CustomerModel customerModel = this.CreateCustomerModel();

            Interface.Repository.ICacheRepository cacheManager = DI.Container.Resolve <Interface.Repository.ICacheRepository>();
            string cacheKey = Guid.NewGuid().ToString();

            cacheManager.Set(cacheKey, customerModel, TimeSpan.FromMinutes(1));

            Model.Customer.CustomerModel loadedModel = cacheManager.Get <Model.Customer.CustomerModel>(cacheKey);
            Assert.AreEqual(loadedModel.CustomerName, customerModel.CustomerName);
        } // CustomerRedisCache
Esempio n. 5
0
        private Model.Customer.CustomerModel CreateCustomerModel()
        {
            Model.Customer.CustomerModel customerModel = new Model.Customer.CustomerModel();

            customerModel.CustomerName    = string.Format("{0} - {1:mm-dd-yyyy}", customerModel.CustomerId, DateTime.Now);
            customerModel.CustomerRanking = (int)DateTime.Now.Millisecond;
            customerModel.CustomerCity    = "Gotham";
            customerModel.CustomerState   = "FL";
            customerModel.CustomerZip     = "33000";
            customerModel.CustomerAddress = "123 Anywhere St";

            return(customerModel);
        }
Esempio n. 6
0
        public void CustomerEntityFramework()
        {
            // Register Repository (Override existing regristation)
            Sample.Azure.DI.Container.RegisterType <Sample.Azure.Interface.Repository.ICustomerRepository, Sample.Azure.Repository.SqlServer.Customer.CustomerRepository>();

            Model.Customer.CustomerModel customerModel = this.CreateCustomerModel();

            Interface.Service.ICustomerService customerService = DI.Container.Resolve <Interface.Service.ICustomerService>();
            customerService.Save(customerModel);

            Model.Customer.CustomerModel loadedModel = customerService.Get(customerModel.CustomerId);
            Assert.AreEqual(loadedModel.CustomerName, customerModel.CustomerName);
        } // CustomerEntityFramework
Esempio n. 7
0
        public void CustomerQueue()
        {
            Model.Customer.CustomerModel customerModel = this.CreateCustomerModel();
            Common.JSON.JSONService      jsonService   = new Common.JSON.JSONService();
            string json = jsonService.Serialize <Model.Customer.CustomerModel>(customerModel);

            Interface.Repository.IQueueRepository queueRepository = DI.Container.Resolve <Interface.Repository.IQueueRepository>();
            queueRepository.Enqueue("customer", json); // Typically you would just put an id in the queue since they have size limits on their payload

            Model.Queue.QueueModel queueModel = new Model.Queue.QueueModel();
            queueModel = queueRepository.Dequeue("customer", TimeSpan.FromMinutes(1));
            Model.Customer.CustomerModel loadedModel = jsonService.Deserialize <Model.Customer.CustomerModel>(queueModel.Item);
            Assert.AreEqual(loadedModel.CustomerName, customerModel.CustomerName);
            queueRepository.DeleteItem("customer", queueModel);
        } // CustomerEntityFramework
        public Sample.Azure.Model.Customer.CustomerModel Select(Guid customerId)
        {
            string fileName  = customerId.ToString().ToLower() + ".json";
            string container = "customer";

            Common.JSON.JSONService jsonService     = new Common.JSON.JSONService();
            Model.File.FileModel    loadedFileModel = fileRepository.GetFileAsText(container, fileName);

            if (loadedFileModel == null)
            {
                return(null);
            }
            else
            {
                string loadedJson = loadedFileModel.Text;
                Model.Customer.CustomerModel loadedModel = jsonService.Deserialize <Model.Customer.CustomerModel>(loadedJson);
                return(loadedModel);
            }
        }