Ejemplo n.º 1
0
        /// <summary>
        /// The get.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <returns>
        /// The <see cref="Product"/>.
        /// </returns>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public Product Get(object id)
        {
            var result = this.DbSet.Find((int)id);

            if (result == null)
            {
                throw new Exception("No product found with that ID");
            }

            // Mapping should be moved to another class
            return(new Product()
            {
                Id = result.Id,
                Depth = result.Depth,
                Description = result.Description,
                Height = result.Height,
                Name = result.Name,
                Price = result.Price,
                Priority = PriorityFactory.GetPriority(result.PriorityId),
                Sku = result.Sku,
                State = result.State,
                Weight = result.Weight,
                Width = result.Width
            });
        }
Ejemplo n.º 2
0
 /// <summary>
 /// The map product model to domain.
 /// </summary>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <returns>
 /// The <see cref="Product"/>.
 /// </returns>
 public static Product MapProductModelToDomain(ProductModel model)
 {
     return(new Product()
     {
         Id = model.Id,
         Depth = model.Depth,
         Description = model.Description,
         Height = model.Height,
         Name = model.Name,
         Price = model.Price,
         Sku = model.Sku,
         State = model.State,
         Weight = model.Weight,
         Width = model.Width,
         Priority = PriorityFactory.GetPriority(model.PriorityId)
     });
 }
Ejemplo n.º 3
0
        /// <summary>
        /// The get multiple products.
        /// </summary>
        /// <param name="productIds">
        /// The product ids.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task <ICollection <Product> > GetMultipleProducts(ICollection <int> productIds)
        {
            var domainProducts = new ConcurrentBag <Product>();
            var missingProduct = false;
            var timer          = new Stopwatch();

            timer.Start();
            Console.WriteLine("Timer has started");
            foreach (var productId in productIds)
            {
                var productModel = this.DbSet.Find(productId);
                if (productModel == null)
                {
                    missingProduct = true;
                    break;
                }

                domainProducts.Add(new Product()
                {
                    Id          = productModel.Id,
                    Depth       = productModel.Depth,
                    Description = productModel.Description,
                    Height      = productModel.Height,
                    Name        = productModel.Name,
                    Price       = productModel.Price,
                    Priority    = PriorityFactory.GetPriority(productModel.PriorityId),
                    Sku         = productModel.Sku,
                    State       = productModel.State,
                    Weight      = productModel.Weight,
                    Width       = productModel.Width
                });
            }

            timer.Stop();
            Console.WriteLine(timer.Elapsed);

            if (missingProduct)
            {
                return(null);
            }
            return(domainProducts.ToList());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The get all products.
        /// </summary>
        /// <returns>
        /// The <see cref="ICollection"/>.
        /// </returns>
        public ICollection <Product> GetAllProducts()
        {
            var productModels = this.DbSet.ToList();
            var productList   = new List <Product>();

            foreach (var product in productModels)
            {
                productList.Add(new Product()
                {
                    Id          = product.Id,
                    Depth       = product.Depth,
                    Description = product.Description,
                    Height      = product.Height,
                    Name        = product.Name,
                    Price       = product.Price,
                    Sku         = product.Sku,
                    State       = product.State,
                    Weight      = product.Weight,
                    Width       = product.Width,
                    Priority    = PriorityFactory.GetPriority(product.PriorityId)
                });
            }
            return(productList);
        }
Ejemplo n.º 5
0
        public void PrioriryFactoryTest()
        {
            var priority = PriorityFactory.GetPriority(1);

            Assert.AreNotEqual(priority, null);
        }