public void SetFailed()
 {
     if (this.State == ProductState.Purchasing)
     {
         this.State = this.details == null ? ProductState.Unknown : ProductState.Loaded;
     }
 }
Beispiel #2
0
        public void ProductCanBePurchased_NotEnoughStock_ReturnsNotInStock()
        {
            ProductState expected = ProductState.NotInStock;

            Mock <Cart>        cart        = new Mock <Cart>();
            Mock <CartProduct> cartProduct = new Mock <CartProduct>();

            cartProduct.SetupGet(x => x.Quantity).Returns(3);
            cart.SetupGet(x => x.Products).Returns(new List <CartProduct>()
            {
                cartProduct.Object
            }.AsReadOnly());

            Mock <ICustomerRepository>     customerRepository = new Mock <ICustomerRepository>();
            Mock <IRepository <Purchase> > purchaseRepository = new Mock <IRepository <Purchase> >();
            Mock <IRepository <Product> >  productRepository  = new Mock <IRepository <Product> >();

            Mock <Product> product = new Mock <Product>();

            product.SetupGet(x => x.Quantity).Returns(1);
            product.SetupGet(x => x.Active).Returns(true);
            productRepository.Setup(x => x.FindById(It.IsAny <Guid>())).Returns(product.Object);

            CheckoutService checkoutService = new CheckoutService(customerRepository.Object, purchaseRepository.Object,
                                                                  productRepository.Object);

            ProductState actual = checkoutService.ProductCanBePurchased(cart.Object);

            Assert.AreEqual(expected, actual);
        }
Beispiel #3
0
        private async Task <DialogTurnResult> ShoesSuggestionPromptAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            productState = await UserProfileAccessor.GetAsync(stepContext.Context);

            var ShoesList = await ShoesSuggestionListAsync();

            //var dc = stepContext.Context.Activity;
            //var lowerCasePrice = stepContext.Result as string ;

            //if (string.IsNullOrWhiteSpace(productState.Categorie) && lowerCasePrice != null)
            //{
            //    productState.PriceMin = Convert.ToDouble(lowerCasePrice);
            //    await UserProfileAccessor.SetAsync(stepContext.Context, productState);
            //}

            var opts = new PromptOptions
            {
                Prompt = new Activity
                {
                    Text             = ShoesList.Count == 0? $"could not find anything" : $"What do you think of these?",
                    Type             = ActivityTypes.Message,
                    Attachments      = ShoesList,
                    AttachmentLayout = AttachmentLayoutTypes.Carousel,
                },
            };

            return(await stepContext.PromptAsync(ShoesListPrompt, opts));
        }
        public Task SaveAsync(Product product, CancellationToken ct = default(CancellationToken))
        {
            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

            ProductState state = product.GetCurrentState();

            var filter = Builders <ProductMongoDocument> .Filter.Eq(p => p.ProductId, state.ProductId.Value);

            var update = Builders <ProductMongoDocument> .Update.Set(p => p.ProductName, state.ProductName)
                         .Set(p => p.ProductDescription, state.ProductDescription)
                         .Set(p => p.Price.Amount, state.Price.Amount)
                         .Set(p => p.Price.Currency, state.Price.Currency)
                         .Set(p => p.Stock.Quantity, state.Stock.Quantity)
                         .Set(p => p.Categories, state.Categories.Select(c => new CategoryMongoDocument()
            {
                CategoryName = c.Name
            }).ToList())
                         .Set(p => p.IsForSale, state.IsForSale)
                         .Set(p => p.IsUnregistered, state.IsUnregistered);

            return(_productCollection.FindOneAndUpdateAsync(filter,
                                                            update,
                                                            new FindOneAndUpdateOptions <ProductMongoDocument, ProductMongoDocument>()
            {
                IsUpsert = true
            },
                                                            ct));
        }
Beispiel #5
0
    public void SetProductState(ProductState state)
    {
        switch (state)
        {
        case ProductState.AVAILABLE:
            mainImage.raycastTarget = true;
            mainImage.color         = AVAILABLE_COLOR;
            priceText?.gameObject.SetActive(true);
            break;

        case ProductState.PURCHASED:
            mainImage.raycastTarget = true;
            mainImage.color         = AVAILABLE_COLOR;
            priceText?.gameObject.SetActive(false);
            break;

        case ProductState.INACTIVE:
            mainImage.raycastTarget = false;
            mainImage.color         = INACTIVE_COLOR;
            priceText?.gameObject.SetActive(true);
            break;

        case ProductState.CONSUMED:
            mainImage.raycastTarget = false;
            mainImage.color         = PURCHASED_COLOR;
            priceText?.gameObject.SetActive(false);
            break;

        default:
            break;
        }
    }
Beispiel #6
0
        public void UpdateState(IDbConnection connection, ProductState productState, IDbTransaction transaction = null)
        {
            Product product = this.productRepository.SelectByName(connection, productState.Name);

            product.State = productState.State;
            this.productRepository.Update(connection, product, transaction);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            ProductState ss = new ProductState();

            Console.WriteLine($"Unit Cost: {ss.GetProductView(1, 10)}");
            InventoryDbContext context = new InventoryDbContext();

            /*
             * var ss = context.Orders.Add(new Order()
             * {
             *  CustomerId = 1,
             *  OrderedDate = DateTime.UtcNow
             * });
             * context.SaveChanges();
             */
            #region Products
            ProductRepository prds = new ProductRepository();
            Console.WriteLine("------------Product List----------------");

            foreach (var prd in prds.GetProducts())
            {
                Console.WriteLine($"ID: {prd.Id} \t Name: {prd.Name} \t Unit Price: {prd.UnitPrice}");
            }
            Console.WriteLine("------------End of Product List----------------\n");

            Console.WriteLine("------------Stock List----------------");
            foreach (var stk in prds.GetStocks())
            {
                Console.WriteLine($"ID: {stk.Id} \t ProductID: {stk.ProductId} \t Quanity: {stk.Quantity}" +
                                  $"\t Unit Cost: {stk.UnitCost} \t Date: {stk.PurchaseDate.ToShortDateString()} \t Total: {stk.Quantity * stk.UnitCost}");
            }
            Console.WriteLine("------------End of Stock List----------------\n");
            #endregion Products

            #region Orders
            Console.WriteLine("------------Order List----------------");
            OrderRepository ords = new OrderRepository();
            //ords.AddOrderDetail(2, 1, 3);
            // ords.AddOrderDetail(2, 1, 3);

            foreach (var ord in ords.GetOrders())
            {
                Console.WriteLine($"Id: {ord.Id} \t CustomerId: {ord.CustomerId} \t Date: {ord.OrderedDate.ToShortDateString()}");
            }
            Console.WriteLine("------------End Order List----------------\n");
            Console.WriteLine("------------Order Details List----------------");

            foreach (var ord in ords.GetOrderDetails())
            {
                Console.WriteLine($"ID: {ord.Id} \t OrderID: {ord.OrderId} \t Product Id: {ord.ProductId} " +
                                  $"\t Quantity: {ord.Quantity} \t Unit Price: {ord.UnitPrice} \t Unit Cost: {ord.UnitCost} " +
                                  $"\t Total Price {ord.Quantity * ord.UnitPrice} ");
            }
            Console.WriteLine("------------End Order Details List----------------\n");


            #endregion
            Console.ReadLine();
        }
        public ProductState UpdateProductState(ProductState productState)
        {
            var oldState = _context.ProductStates.FirstOrDefault(p => p.Id == productState.Id);

            _context.Entry(oldState).CurrentValues.SetValues(productState);
            _context.SaveChanges();
            return(productState);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ProductState productState = db.ProductStates.Find(id);

            db.ProductStates.Remove(productState);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public void SetState(ProductStateDto productStateDto)
 {
     using (NpgsqlConnection connection = this.databaseConnectionFactory.Instance.Create())
     {
         ProductState productState = this.dtoToEntityMapper.Map <ProductStateDto, ProductState>(productStateDto);
         this.productService.UpdateState(connection, productState);
     }
 }
        void Setup_the_SUT()
        {
            DomainEventPublisherMock = new Moq.Mock <IPublishDomainEvents>(Moq.MockBehavior.Loose);

            State = new ProductState(DomainEventPublisherMock.Object);

            SUT = new Product(State);
        }
Beispiel #12
0
 /// <summary>
 /// 修改商品状态
 /// </summary>
 /// <param name="pidList">商品id</param>
 /// <param name="state">商品状态</param>
 public static bool UpdateProductState(int[] pidList, ProductState state)
 {
     if (pidList != null && pidList.Length > 0)
     {
         return(BrnShop.Data.Products.UpdateProductState(CommonHelper.IntArrayToString(pidList), state));
     }
     return(false);
 }
Beispiel #13
0
        public Product GetValidOne(long id, ProductState state)
        {
            Hashtable ht = new Hashtable(2);

            ht["Id"]       = id;
            ht["StateVal"] = state;
            return(GetOne(ht));
        }
Beispiel #14
0
 public void Publish()
 {
     if (this.State != ProductState.Draft)
     {
         throw new ValidationException("A non-draft product cannot be published.");
     }
     this.State = ProductState.Published;
 }
Beispiel #15
0
        void Setup_the_SUT_and_activate_the_tenants()
        {
            State = new ProductState(null);

            SUT = new Product(State);

            State.TenantActivated(a_tenant_id);
            State.TenantActivated(another_tenant_id);
        }
 public void SetDetails(SKProduct productDetails)
 {
     this.lastDetailsRequest = DateTime.Now;
     this.details            = productDetails;
     if (this.State == ProductState.Unknown)
     {
         this.State = ProductState.Loaded;
     }
 }
Beispiel #17
0
 protected Product(string name, decimal price, int pointRate, Seller seller, ProductState state)
 {
     this.ProductId = Guid.NewGuid();
     this.Name      = name;
     this.Price     = price;
     this.PointRate = pointRate;
     this.Seller    = seller;
     this.State     = state;
 }
Beispiel #18
0
        public void Init()
        {
            var state = new ProductState(null);

            SUT = state;

            state.ProductActivated(a_tenant_id, a_product_id, a_product_name, a_product_description);
            state.ProductActivated(another_tenant_id, another_product_id, another_product_name, another_product_description);
        }
Beispiel #19
0
 public async Task <List <Product> > ProductByCategorie([FromBody] ProductState product)
 {
     if (product.PriceMax == 0)
     {
         product.PriceMax = int.MaxValue;
     }
     return(await _context.Products
            .Where(p => p.Brand.Contains(product.Categorie) && p.Price > product.PriceMin && p.Price < product.PriceMax)
            .ToListAsync());
 }
 public ActionResult Edit([Bind(Include = "productStateID,state")] ProductState productState)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productState).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productState));
 }
Beispiel #21
0
        /// <summary>
        /// 修改商品状态
        /// </summary>
        /// <param name="pidList">商品id</param>
        /// <param name="state">商品状态</param>
        public static bool UpdateProductState(string pidList, ProductState state)
        {
            bool result = BrnShop.Core.BSPData.RDBS.UpdateProductState(pidList, state);

            if (_productnosql != null)
            {
                _productnosql.UpdateProductState(pidList, state);
            }
            return(result);
        }
        public ActionResult Create([Bind(Include = "productStateID,state")] ProductState productState)
        {
            if (ModelState.IsValid)
            {
                db.ProductStates.Add(productState);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(productState));
        }
        private void UpdateProducts(IEnumerable <Product> products, ProductState state)
        {
            foreach (var product in products)
            {
                product.SetState(state);
            }

            _db.Products.UpdateRange(products);

            _db.SaveChanges();
        }
Beispiel #24
0
        public static IEnumerable <IProductState> ToProductStateCollection(IEnumerable <string> ids)
        {
            var states = new List <ProductState>();

            foreach (var id in ids)
            {
                var s = new ProductState();
                s.ProductId = id;
                states.Add(s);
            }
            return(states);
        }
        internal static string ToSerializedValue(this ProductState value)
        {
            switch (value)
            {
            case ProductState.NotPublished:
                return("notPublished");

            case ProductState.Published:
                return("published");
            }
            return(null);
        }
Beispiel #26
0
        private string SaveModel(ProductState store, string fileName)
        {
            var result   = new Dsl.SerializationResult();
            var itemName = Path.GetFileName(fileName);

            if (solution.IsOpen)
            {
                // First do the quick lookup in the default location.
                IItemContainer itemParent = this.solution.SolutionFolders.FirstOrDefault(folder =>
                                                                                         folder.Name.Equals(SolutionExtensions.SolutionItemsFolderName, StringComparison.OrdinalIgnoreCase) &&
                                                                                         folder.Items.Any(item => item.PhysicalPath == fileName));

                if (itemParent == null)
                {
                    // Try the slow probing anywhere in the solution.
                    itemParent = (from item in this.solution.Traverse().OfType <IItem>()
                                  where item.PhysicalPath == fileName
                                  select item.Parent)
                                 .FirstOrDefault();
                }

                if (itemParent == null)
                {
                    tracer.Verbose(Resources.PatternManager_TraceSavingDefaultEmptyState, fileName);

                    // Default to SolutionItems.
                    itemParent = this.solution.Items.OfType <ISolutionFolder>().FirstOrDefault(x => x.IsSolutionItemsFolder());
                    if (itemParent == null)
                    {
                        tracer.Verbose(Resources.PatternManager_SaveNoSolutionItems);
                        itemParent = this.solution.CreateSolutionFolder(SolutionExtensions.SolutionItemsFolderName);
                    }
                }

                // Serialize to temp to add or override content next.
                var tempFileName = Path.GetTempFileName();
                ProductStateStoreSerializationHelper.Instance.SaveModel(result, store, tempFileName);

                var addedItem = this.AddStateToSolution(itemParent, itemName, tempFileName);

                // Cleanup the temporary file.
                File.Delete(tempFileName);

                return(addedItem.PhysicalPath);
            }
            else
            {
                ProductStateStoreSerializationHelper.Instance.SaveModel(result, store, fileName);
                return(fileName);
            }
        }
        // GET: ProductState/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductState productState = db.ProductStates.Find(id);

            if (productState == null)
            {
                return(HttpNotFound());
            }
            return(View(productState));
        }
 public Product(
     TenantId tenantId,
     ProductId productId,
     ProductOwnerId productOwnerId,
     string name,
     string description)
 {
     State                = new ProductState();
     State.ProductKey     = tenantId.Id + ":" + productId.Id;
     State.ProductOwnerId = productOwnerId;
     State.Name           = name;
     State.Description    = description;
     State.BacklogItems   = new List <ProductBacklogItem>();
 }
Beispiel #29
0
        public static string ToText(this ProductState enumModel)
        {
            switch (enumModel)
            {
            case ProductState.OnSale:
                return("在售");

            case ProductState.UnderCarriage:
                return("下架");

            default:
                return("");
            }
        }
Beispiel #30
0
        public void InitializeContextWithData(ShopContext context)
        {
            var names = new List <string>()
            {
                "Buddy",
                "Peter",
                "Tonny",
                "Janick",
                "Johnny"
            };
            var lastNames = new List <string>()
            {
                "Guy",
                "Green",
                "Iommi",
                "Gers",
                "Cash"
            };
            var products = new Product[5];
            var states   = new ProductState[5];

            products[0] = new Product("Fender Stratocaster");
            states[0]   = new ProductState(products[0], 5, (decimal)2200, new Percentage(23));
            products[1] = new Product("Fender Telecaster");
            states[1]   = new ProductState(products[1], 2, (decimal)2101.12, new Percentage(23));
            products[2] = new Product("Jaydee SG");

            for (int i = 0; i < names.Count; i++)
            {
                context.Clients.Add(new Client(
                                        names[i],
                                        lastNames[i]
                                        ));
            }
            for (int i = 0; i < 2; i++)
            {
                context.Products.Add(products[i].Id, products[i]);
                context.ProductStates.Add(states[i]);
            }
            var clients = context.Clients;

            context.Invoices.Add(new Invoice(
                                     clients[0],
                                     products[1],
                                     1,
                                     (decimal)123.123,
                                     new Percentage(21)
                                     ));
        }
            public void SetPurchased()
            {
                if (this.State == ProductState.Purchased)
                    return;

                this.State = ProductState.Purchased;

                // Whilst we could do something more secure than
                // using NSUserDefaults here it is simple and the
                // majority of people who would actually pay will
                // not be looking to try and hack it in the first place.
                NSUserDefaults.StandardUserDefaults.SetBool(true, this.iapKey);
                NSUserDefaults.StandardUserDefaults.Synchronize();
            }
Beispiel #32
0
 /// <summary>
 /// 修改商品状态
 /// </summary>
 /// <param name="pidList">商品id</param>
 /// <param name="state">商品状态</param>
 public static bool UpdateProductState(int[] pidList, ProductState state)
 {
     if (pidList != null && pidList.Length > 0)
         return BrnMall.Data.Products.UpdateProductState(CommonHelper.IntArrayToString(pidList), state);
     return false;
 }
Beispiel #33
0
 public Product(ProductState State)
     : this(State, State)
 {
 }
 public void SetDetails(SKProduct productDetails)
 {
     this.lastDetailsRequest = DateTime.Now;
     this.details = productDetails;
     if (this.State == ProductState.Unknown)
         this.State = ProductState.Loaded;
 }
Beispiel #35
0
        /// <summary>
        /// Konwertuje status produktu na wartość zapisaną do bazy danych.
        /// </summary>
        /// <param name="stateEnum"><see cref="ProductState"/></param>
        /// <returns></returns>
        private Int32 GetProductStateValue(ProductState stateEnum)
        {
            Int32 value = 0;

            if (stateEnum == ProductState.Private)
                value = 0;
            else if (stateEnum == ProductState.Pending)
                value = 1;
            else if (stateEnum == ProductState.Denied)
                value = 2;
            else if (stateEnum == ProductState.Accepted)
                value = 3;
            else
                throw new NotSupportedException(nameof(stateEnum));

            return value;
        }
Beispiel #36
0
 /// <summary>
 /// 修改商品状态
 /// </summary>
 /// <param name="pidList">商品id</param>
 /// <param name="state">商品状态</param>
 public bool UpdateProductState(string pidList, ProductState state)
 {
     string commandText = string.Format("UPDATE [{0}products] SET [state]={1} WHERE [pid] IN ({2})",
                                         RDBSHelper.RDBSTablePre,
                                         (int)state,
                                         pidList);
     return TypeHelper.ObjectToInt(RDBSHelper.ExecuteNonQuery(CommandType.Text, commandText), -1) > 0;
 }
 public void SetInvalid() { this.State = ProductState.Invalid; }
Beispiel #38
0
 /// <summary>
 /// 修改商品状态
 /// </summary>
 /// <param name="pidList">商品id</param>
 /// <param name="state">商品状态</param>
 public static bool UpdateProductState(string pidList, ProductState state)
 {
     bool result = BrnMall.Core.BMAData.RDBS.UpdateProductState(pidList, state);
     if (_productnosql != null)
         _productnosql.UpdateProductState(pidList, state);
     return result;
 }
 public void SetPurchasing() { this.State = ProductState.Purchasing; }
 public void SetFailed()
 {
     if (this.State == ProductState.Purchasing)
         this.State = this.details == null ? ProductState.Unknown : ProductState.Loaded;
 }