Пример #1
0
        //private ObservableAsPropertyHelper<decimal> change;
        //private ObservableAsPropertyHelper<double> percentChange;

        public WatchListItemViewModel(WatchListItem item)
        {
            this.WatchListItem = item;

            Symbol          = item.Symbol;
            Name            = item.Name;
            PriceSales      = item.PriceSales;
            PriceBook       = item.PriceBook;
            ChangeInPercent = item.ChangeInPercent;
            DailyLow        = item.DailyLow;
            DailyHigh       = item.DailyHigh;
            LastUpdate      = item.LastUpdate;

            //this.WhenAnyValue(v => v.PriceSales, v => v.DayOpen, (p, o) => p - o)
            //    .ToProperty(this, v => v.Change, out change);

            //this.WhenAnyValue(v => v.Change, v => v.Price, (c, p) => p != 0 ? (double)Math.Round(c / p, 4) : 0)
            //    .ToProperty(this, v => v.PercentChange, out percentChange);
        }
        //private ObservableAsPropertyHelper<decimal> change;
        //private ObservableAsPropertyHelper<double> percentChange; 

        public WatchListItemViewModel(WatchListItem item)
        {
            this.WatchListItem = item;

            Symbol = item.Symbol;
            Name = item.Name;
            PriceSales = item.PriceSales;
            PriceBook = item.PriceBook;
            ChangeInPercent = item.ChangeInPercent;
            DailyLow = item.DailyLow;
            DailyHigh = item.DailyHigh;
            LastUpdate = item.LastUpdate;

            //this.WhenAnyValue(v => v.PriceSales, v => v.DayOpen, (p, o) => p - o)
            //    .ToProperty(this, v => v.Change, out change);

            //this.WhenAnyValue(v => v.Change, v => v.Price, (c, p) => p != 0 ? (double)Math.Round(c / p, 4) : 0)
            //    .ToProperty(this, v => v.PercentChange, out percentChange);
        }
        private async Task<Unit> AddStock()
        {
            var newItem = new WatchListItem();
            newItem.Symbol =Symbol;
            newItem.Name = Name;
            newItem.PriceSales = PriceSales;
            newItem.PriceBook = PriceBook;
            newItem.ChangeInPercent = ChangeInPercent;
            newItem.DailyHigh = DailyHigh;
            newItem.DailyLow = DailyLow;
            newItem.LastUpdate = LastUpdate;

            // Add to DB
            await DataManager.Current.AddStock(newItem);   //note: await will return to the UI-Thread

            // Navigate to WatchListItemDetail
            var app = Locator.CurrentMutable.GetService<IApp>();
            app.Navigate(new WatchListItemDetailViewModel(new WatchListItemViewModel(newItem)));

            return Unit.Default;
        }
        /// <summary>
        /// Saves the watch list item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public async Task<int> SaveWatchListItem(WatchListItem item)
        {
            if (item == null) return -1;
            if (item.Id <= 0)
            {
                var id = await InsertAsync(item).ConfigureAwait(false);

                // Publish Create
                WatchListItemChange.OnNext(Tuple.Create(DbChangeTypeEnum.Create, item));

                return id;
            }

            await UpdateAsync(item).ConfigureAwait(false);

            // Publish Update
            WatchListItemChange.OnNext(Tuple.Create(DbChangeTypeEnum.Update, item));

            return item.Id;

        }
        /// <summary>
        /// Saves the watch list item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public async Task <int> SaveWatchListItem(WatchListItem item)
        {
            if (item == null)
            {
                return(-1);
            }
            if (item.Id <= 0)
            {
                var id = await InsertAsync(item).ConfigureAwait(false);

                // Publish Create
                WatchListItemChange.OnNext(Tuple.Create(DbChangeTypeEnum.Create, item));

                return(id);
            }

            await UpdateAsync(item).ConfigureAwait(false);

            // Publish Update
            WatchListItemChange.OnNext(Tuple.Create(DbChangeTypeEnum.Update, item));

            return(item.Id);
        }
Пример #6
0
        private async Task <Unit> AddStock()
        {
            var newItem = new WatchListItem();

            newItem.Symbol          = Symbol;
            newItem.Name            = Name;
            newItem.PriceSales      = PriceSales;
            newItem.PriceBook       = PriceBook;
            newItem.ChangeInPercent = ChangeInPercent;
            newItem.DailyHigh       = DailyHigh;
            newItem.DailyLow        = DailyLow;
            newItem.LastUpdate      = LastUpdate;

            // Add to DB
            await DataManager.Current.AddStock(newItem);   //note: await will return to the UI-Thread

            // Navigate to WatchListItemDetail
            var app = Locator.CurrentMutable.GetService <IApp>();

            app.Navigate(new WatchListItemDetailViewModel(new WatchListItemViewModel(newItem)));

            return(Unit.Default);
        }
Пример #7
0
 /// <summary>
 /// Adds the stock.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns></returns>
 public async Task <int> AddStock(WatchListItem item)
 {
     return(await AppDb.SaveWatchListItem(item).ConfigureAwait(false));
 }
 /// <summary>
 /// Adds the stock.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns></returns>
 public async Task<int> AddStock(WatchListItem item)
 {
     return await AppDb.SaveWatchListItem(item).ConfigureAwait(false);
 }