Esempio n. 1
0
        public async Task Clear()
        {
            if (isInitialized && !string.IsNullOrEmpty(userToken) && items.Count > 0)
            {
                items.Clear();

                var apiresult = await WebApiProvider.ClearHistory(userToken);

                if (!string.IsNullOrEmpty(apiresult.ErrorMessage))
                {
                    throw new Exception(apiresult.ErrorMessage);
                }
            }
        }
Esempio n. 2
0
        public async Task RemoveItem(HistoryItem item)
        {
            if (isInitialized && !string.IsNullOrEmpty(userToken))
            {
                items.Remove(item);
                var serverObj = mapper.Map <APIReport>(item);
                serverObj.UserToken = userToken;
                var apiresult = await WebApiProvider.RemoveHistoryItem(serverObj);

                if (!string.IsNullOrEmpty(apiresult.ErrorMessage))
                {
                    throw new Exception(apiresult.ErrorMessage);
                }
            }
        }
Esempio n. 3
0
        public async Task AddItem(HistoryItem item)
        {
            if (isInitialized && !string.IsNullOrEmpty(userToken) &&
                this.GetItemByContentAndIgnores(item.Content.Text, item.IgnoreRules) == null)
            {
                items.Insert(0, item);
                var serverObj = mapper.Map <APIReport>(item);
                serverObj.UserToken = userToken;
                var apiresult = await WebApiProvider.SaveHistoryItem(serverObj);

                if (!string.IsNullOrEmpty(apiresult.ErrorMessage))
                {
                    throw new Exception(apiresult.ErrorMessage);
                }
            }
        }
Esempio n. 4
0
        public async Task Refresh()
        {
            if (isInitialized && !string.IsNullOrEmpty(userToken))
            {
                var apiresult = await WebApiProvider.GetHistory(userToken);

                if (!string.IsNullOrEmpty(apiresult.ErrorMessage))
                {
                    throw new Exception(apiresult.ErrorMessage);
                }
                else
                {
                    var serverItems = apiresult.Content as List <APIReport>;
                    if (serverItems != null)
                    {
                        var mappedItems = mapper.Map <List <HistoryItem> >(serverItems);
                        if (mappedItems?.Count > 0)
                        {
                            if (items.Count > 0)
                            {
                                foreach (var report in mappedItems)
                                {
                                    if (!items.Contains(report))
                                    {
                                        this.items.Add(report);
                                    }
                                }
                            }
                            else
                            {
                                foreach (var item in mappedItems)
                                {
                                    this.items.Add(item);
                                }
                            }
                            this.items = new ObservableCollection <HistoryItem>(this.items.OrderByDescending(item => item.Date));
                        }
                    }
                }
            }
        }