Exemplo n.º 1
0
        public bool WtrieData(BoughtItem obj)
        {
            AccountBook result;


            int      amounttt;
            DateTime dateee;

            if (int.TryParse(obj.Price.ToString(), out amounttt) &&
                String.IsNullOrWhiteSpace(obj.ItemCategory) == false &&
                DateTime.TryParseExact(obj.ItemDate, "yyyy-MM-dd", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out dateee) &&
                String.IsNullOrWhiteSpace(obj.Remark) == false)
            {
                result = new AccountBook()
                {
                    Categoryyy = obj.ItemCategory == "支出" ? 0 : 1,
                    Amounttt   = amounttt,
                    Dateee     = dateee,
                    Remarkkk   = obj.Remark
                };
                if (accountBookRes.WriteData(result))
                {
                    __hmw.SaveChanges();
                    return(true);
                }
            }


            return(false);
        }
Exemplo n.º 2
0
        public void AddToBoughtItems(Item item)
        {
            var boughtItem = this.BoughtItems.FirstOrDefault(x => x.Title == item.Title);

            if (boughtItem != null)
            {
                ++boughtItem.BoughtCount;
                var bi = _sqliteConnection.Table <BoughtItem>().FirstOrDefault(x => x.Title == item.Title);
                bi.BoughtCount++;
                lock (_locker)
                {
                    _sqliteConnection.Update(bi);
                    _sqliteConnection.Commit();
                }
            }
            else
            {
                var newBoughtItem = new BoughtItem()
                {
                    Title       = item.Title,
                    BoughtCount = 1
                };
                this.BoughtItems.Add(newBoughtItem);
            }

            this.BoughtItems = new ObservableCollection <BoughtItem>(this.BoughtItems.OrderByDescending(x => x.BoughtCount));
            BoughtItems.CollectionChanged += BoughtItems_CollectionChanged;
        }
Exemplo n.º 3
0
        public void UpdateCell(BoughtItem item, bool isOnShoppingList)
        {
            _countLabel.Text = item.BoughtCount.ToString();

            var addedToShoppingListString = " (added to shopping list)";

            var titleLabel = new NSMutableAttributedString($"{item.Title}{(isOnShoppingList ? addedToShoppingListString : "")}");

            titleLabel.SetAttributes(new UIStringAttributes
            {
                ForegroundColor = UIColor.Black,
                Font            = UIFont.SystemFontOfSize(18)
            }, new NSRange(0, item.Title.Length));

            if (isOnShoppingList)
            {
                titleLabel.SetAttributes(new UIStringAttributes
                {
                    ForegroundColor = UIColor.Gray,
                    Font            = UIFont.SystemFontOfSize(13)
                }, new NSRange(item.Title.Length, addedToShoppingListString.Length));
            }

            _titleLabel.AttributedText = titleLabel;
        }
Exemplo n.º 4
0
        public async Task <Item> PutItem(BoughtItem newItem)
        {
            Product product = new Product
            {
                Amount         = newItem.Amount,
                ExpirationDate = newItem.ExpirationDate,
            };

            Fridge fridge = await RetrieveFridge(newItem.FridgeId);

            Model.Item item = fridge.Items.FirstOrDefault(val => val.Name == newItem.ItemName);

            if (item == null)
            {
                item = new Model.Item
                {
                    Name     = newItem.ItemName,
                    Products = new List <Product>()
                };
                (fridge.Items as IList <Item>).Add(item);
            }
            (item.Products as IList <Product>).Add(product);

            var updateRequest = await repo.UpdateAsync(fridge);

            if (!updateRequest.Success)
            {
                throw new Exception($"{item.Name} coulnd't be updated");
            }

            return(updateRequest.Success ? item : null);
        }
Exemplo n.º 5
0
        public void TestApplyDiscount(decimal priceShouldBe, int quantity)
        {
            var boughtItem         = new BoughtItem();
            var calculationService = new CalculationService();

            boughtItem.Quantity = quantity;
            calculationService.ApplyDiscount(boughtItem);
            boughtItem.Price.Should().Be(priceShouldBe);
        }
Exemplo n.º 6
0
        public void Should_Init_Item_With_Count_1()
        {
            // Arrange
            var title = "some bought item";

            // Act
            var boughtItem = new BoughtItem(title);

            // Assert
            Assert.Equal(1, boughtItem.BoughtCount);
        }
Exemplo n.º 7
0
        public void TestCalculateTotalPrice()
        {
            //Arange
            var boughtItem         = new BoughtItem();
            var calculationService = new CalculationService();

            //Act
            calculationService.CalculateTotalPrice(boughtItem);
            //Assert
            boughtItem.TotalPrice.Should().Be(300);
        }
Exemplo n.º 8
0
        public async Task <Item> TakeItem(BoughtItem item)
        {
            Fridge fridge = await RetrieveFridge(item.FridgeId);

            Model.Item persistedItem = fridge.Items.FirstOrDefault(val => val.Name.ToLower() == item.ItemName.ToLower());

            //item not present.
            if (persistedItem == null)
            {
                throw new Exception($"There is no {item.ItemName} in your fridge");
            }

            //not enough items present
            if (item.Amount > persistedItem.GetTotalAmount())
            {
                throw new Exception($"Not enough {item.ItemName} present");
            }

            int neededItems = item.Amount;
            //take items
            var products = persistedItem.Products.OrderBy(product => product.ExpirationDate).ThenBy(product => product.ExpirationDate == null);

            foreach (Product product in products.TakeWhile(product => neededItems >= 0))
            {
                int residue = product.Amount - neededItems;
                //delete entry
                if (residue <= 0)
                {
                    (persistedItem.Products as IList <Product>).Remove(product);
                    neededItems = Math.Abs(residue);
                }
                //change entry
                else
                {
                    product.Amount = residue;
                    neededItems    = 0;
                }
            }

            if ((persistedItem.Products as IList <Product>).Count == 0)
            {
                (fridge.Items as IList <Item>).Remove(persistedItem);
            }

            var updateRequest = await repo.UpdateAsync(fridge);

            if (!updateRequest.Success)
            {
                throw new Exception($"{persistedItem.Name} coulnd't be updated");
            }

            return(updateRequest.Success ? persistedItem : null);
        }
        public void Add_Item()
        {
            // Arrange
            var vm   = new PastPurchasesViewModel(_shoppingService);
            var item = new BoughtItem("item 1");

            // Act
            vm.Add(item);

            // Assert
            Assert.Contains <BoughtItem>(vm.Items, x => x == item);
        }
Exemplo n.º 10
0
        public void Add(BoughtItem item)
        {
            var boughtItem = Items.FirstOrDefault(x => x.Title == item.Title);

            if (boughtItem == null)
            {
                this.Items.Add(item);
            }
            else
            {
                boughtItem.BoughtCount++;
            }
        }
Exemplo n.º 11
0
        private View GetItemView(int position, BoughtItem item, View convertView)
        {
            var view = convertView ?? this._inflater.Inflate(Resource.Layout.PurchasedItem, null);

            var count = view.FindViewById <TextView>(Resource.Id.Count);

            count.Text = item.BoughtCount.ToString();

            var title = view.FindViewById <TextView>(Resource.Id.Title);

            title.Text = item.Title;

            return(view);
        }
Exemplo n.º 12
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            BoughtItem = await _context.BoughtItem.SingleOrDefaultAsync(m => m.ID == id);

            if (BoughtItem == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemplo n.º 13
0
        public ActionResult Buy(int Id, int Quantity)
        {
            var Item       = GetItem(Id);
            var boughtItem = new BoughtItem()
            {
                Quantity = Quantity,
                UserId   = (Guid)Session["userId"],
                Item     = Item,
                ItemId   = Id
            };

            data.BoughtItems.Add(boughtItem);
            data.SaveChanges();

            return(View(boughtItem));
        }
        public void Add_Item_Already_Added()
        {
            // Arrange
            var vm   = new PastPurchasesViewModel(_shoppingService);
            var item = new BoughtItem("item 1");

            vm.Add(item);
            var item2 = new BoughtItem("item 1");

            // Act
            vm.Add(item);

            // Assert
            Assert.Equal(1, vm.Items.Count);
            Assert.Equal(2, vm.Items.First().BoughtCount);
        }
        public void Copy_Item_To_Shopping_List()
        {
            // Arrange
            var vm        = new PastPurchasesViewModel(_shoppingService);
            var itemTitle = "item1";
            var item      = new BoughtItem(itemTitle);

            vm.Add(item);

            // Act
            vm.CopyItemToShoppingList(item);

            // Assert
            Assert.Equal(1, _shoppingService.Items.Count);
            Assert.Contains <Item>(_shoppingService.Items, x => x.Title == itemTitle);
        }
Exemplo n.º 16
0
 private void TryToBuyItem(Item.ItemType itemType, int itemCost, string itemElement)
 {
     if (!Player.gameIsPaused)
     {
         if (TrySpendSouls(itemCost, itemElement))
         {
             AudioManager.PlaySound(AudioManager.Sound.Buy);
             BoughtItem?.Invoke(itemType);
         }
         else
         {
             AudioManager.PlaySound(AudioManager.Sound.CantBuy);
             TooltipWarningScreenSpaceUI.ShowTooltip_Static("You don't have " + itemCost + " " + itemElement + " Souls!", 1);
         }
     }
 }
Exemplo n.º 17
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            BoughtItem = await _context.BoughtItem.FindAsync(id);

            if (BoughtItem != null)
            {
                _context.BoughtItem.Remove(BoughtItem);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 18
0
 public void ApplyDiscount(BoughtItem item)
 {
     if (item.Quantity >= 5 && item.Quantity < 10)
     {
         item.Discount = 10;
         item.Price    = item.Price * (100 - item.Discount) / 100;
     }
     else if (item.Quantity >= 10)
     {
         item.Discount = 20;
         item.Price    = item.Price * (100 - item.Discount) / 100;
     }
     else
     {
         item.Discount = 0;
         item.Price    = item.Price;
     }
 }
Exemplo n.º 19
0
        public ActionResult ListingItems(int ItemId = 0, int Quantity = 0)
        {
            if (ItemId == 0 || Quantity == 0)
            {
                return(RedirectToAction("Customer"));
            }
            var checking = _context.Stocks.FirstOrDefault(c => c.ItemId == ItemId);

            if (checking.Quantity < Quantity)
            {
                return(RedirectToAction("Customer"));
            }
            else
            {
                var listingItems      = new BoughtItem();
                var listingItemsAdmin = new BoughtItemAdmin();
                var checkIfExists     = _context.BoughtItems.FirstOrDefault(c => c.ItemId == ItemId);
                // var checkIfExistsAdmin = _context.BoughtItemAdmins.FirstOrDefault(c => c.ItemId == ItemId);
                if (checkIfExists != null)
                {
                    //checkIfExistsAdmin.Quantity += Quantity;
                    checkIfExists.Quantity += Quantity;
                    checking.Quantity      -= Quantity;
                    _context.SaveChanges();
                    return(RedirectToAction("Customer"));
                }
                else
                {
                    listingItems.ItemId        = ItemId;
                    listingItemsAdmin.ItemId   = ItemId;
                    listingItems.Quantity      = Quantity;
                    listingItemsAdmin.Quantity = Quantity;
                    _context.BoughtItems.Add(listingItems);
                    _context.BoughtItemAdmins.Add(listingItemsAdmin);
                    checking.Quantity -= Quantity;
                    _context.SaveChanges();
                    return(RedirectToAction("Customer"));
                }
            }
        }
Exemplo n.º 20
0
        //[Route("POS/ListingItems/{ItemId}")]
        public ActionResult ListingItems(int ItemId, int quantity)
        {
            var checking = context.Stocks.FirstOrDefault(p => p.ItemId == ItemId);

            if (checking.Quantity < quantity)
            {
                return(RedirectToAction("Customer"));
            }
            else
            {
                var listingItems  = new BoughtItem();
                var checkIfExists = context.BoughtItems.FirstOrDefault(p => p.ItemId == ItemId);

                checkIfExists.Quantity += quantity;
                checking.Quantity      -= quantity;
                context.SaveChanges();
                return(RedirectToAction("Customer"));

                /*
                 * if (checkIfExists != null)
                 * {
                 *  checkIfExists.Quantity += quantity;
                 *  checking.Quantity -= quantity;
                 *  context.SaveChanges();
                 *  return RedirectToAction("Customer");
                 * }
                 * else
                 * {
                 *  listingItems.ItemId = ItemId;
                 *  listingItems.Quantity = quantity;
                 *  context.BoughtItems.Add(listingItems);
                 *  checking.Quantity -= quantity;
                 *  context.SaveChanges();
                 *  return RedirectToAction("Customer");
                 * } */
            }
        }
Exemplo n.º 21
0
 public void CalculateTotalPrice(BoughtItem item)
 {
     item.TotalPrice = item.Quantity * item.Price;
 }
Exemplo n.º 22
0
 // PUT api/<controller>
 public async Task <Item> Put([FromBody] BoughtItem item)
 {
     return(await Dal.PutItem(item));
 }
Exemplo n.º 23
0
 public void AddToNewCart(BoughtItem boughtItems)
 {
     _context.BoughtItems.Add(boughtItems);
     _context.SaveChanges();
 }
Exemplo n.º 24
0
 public void AddToExistingCart(BoughtItem boughtItems)
 {
     _context.SaveChanges();
 }