Exemplo n.º 1
0
        public async Task SaveChangesAsync()
        {
            bool _saveOk = true;

            using (UnitOfWork uow = new UnitOfWork(this.dbFilePath))
            {
                if (this.IsNew)
                {
                    var _resultsSaveNew = await uow.AddBudgetCategoryAsync(model);

                    _saveOk = _resultsSaveNew.Successful;
                    if (_saveOk)
                    {
                        this.IsDirty   = false;
                        this.IsNew     = false;
                        this.CanEdit   = true;
                        this.CanDelete = true;
                    }
                    else
                    {
                        if (_resultsSaveNew.WorkException != null)
                        {
                            WriteErrorCondition(_resultsSaveNew.WorkException);
                        }
                        else if (!string.IsNullOrEmpty(_resultsSaveNew.Message))
                        {
                            WriteErrorCondition(_resultsSaveNew.Message);
                        }
                        else
                        {
                            WriteErrorCondition("An unknown error has occurred saving the Budget Category");
                        }
                    }
                }
                else
                {
                    var _resultsUpdate = await uow.UpdateBudgetCategoryAsync(model);

                    _saveOk = _resultsUpdate.Successful;
                    if (_saveOk)
                    {
                        this.IsDirty   = false;
                        this.IsNew     = false;
                        this.CanEdit   = true;
                        this.CanDelete = true;
                    }
                    else
                    {
                        if (_resultsUpdate.WorkException != null)
                        {
                            WriteErrorCondition(_resultsUpdate.WorkException);
                        }
                        else if (!string.IsNullOrEmpty(_resultsUpdate.Message))
                        {
                            WriteErrorCondition(_resultsUpdate.Message);
                        }
                        else
                        {
                            WriteErrorCondition("An unknown error has occurred saving the Budget Category");
                        }
                    }
                }
            }

            if (_saveOk)
            {
                foreach (var item in BudgetItems)
                {
                    if (item.IsDirty)
                    {
                        await item.SaveChangesAsync();
                    }
                }
            }
        }