Exemplo n.º 1
0
        private async void Save()
        {
            try
            {
                var amount = decimal.Parse(this.SimpleIncome.Amount);
                var income = this.incomesFactory.Create(Guid.NewGuid(), this.Date, amount, this.SimpleIncome.Side, this.SimpleIncome.Description, this.PaymentType);

                var responseExpense = JsonConvert.DeserializeObject <GeneralResponse>(await HttpRequestHelper.CreateIncomeRemote(ViewBag.Email, income));

                if (responseExpense.Status == "0")
                {
                    throw new Exception();
                }

                var user = JsonConvert.DeserializeObject <User>(await HttpRequestHelper.GetUserByEmailRemote(ViewBag.Email));

                ViewBag.Balance = user.LocalizedBalance;

                this.Message      = Constants.SuccessfulfulIncomeCreation;
                this.MessageColor = Constants.MessagePositiveColor;

                this.SuccessfulIncomeRequested();

                this.SimpleIncome = this.modelFactory.CreateSimpleIncome();
                this.Date         = DateTime.Today;
            }
            catch
            {
                this.Message      = Constants.UnsuccessfulIncomeCreation;
                this.MessageColor = Constants.MessageNegativeColor;
            }
            finally
            {
                await Task.Factory.StartNew(() => Thread.Sleep(2 * 1000))
                .ContinueWith((t) =>
                {
                    this.Message = string.Empty;
                });
            }
        }