예제 #1
0
        public void TryParse_NegativeInteger()
        {
            var input  = "-5";
            var result = ValueUnit.TryParse(input, out var valueUnit);

            Assert.IsTrue(result);
            Assert.AreEqual(-5, valueUnit.GetResult());
        }
예제 #2
0
        public void TryParse_NegativeDecimal()
        {
            var input  = "-1.3";
            var result = ValueUnit.TryParse(input, out var valueUnit);

            Assert.IsTrue(result);
            Assert.AreEqual(-1.3, valueUnit.GetResult());
        }
예제 #3
0
        public async Task CreateOrMergeItemAsync(ShoppingListItem item)
        {
            ShoppingListItem itemOnList = await GetItemByNameAsync(item.OwnerId, item.Name);

            // check if items could be merged
            if (itemOnList != null && (ValueUnit.TryParse(itemOnList.Quantity, out ValueUnit onlistValue) && ValueUnit.TryParse(item.Quantity, out ValueUnit coreDataValue)))
            {
                // merge items
                ValueUnit newValueUnit = ValueUnit.Add(onlistValue, coreDataValue);

                itemOnList.Quantity = newValueUnit.ToString();
            }
            else
            {
                // create new item
                _context.ShoppingListItems.Add(item);
            }
            await _context.SaveChangesAsync();
        }