// GET: Expense/Create
        public async Task<ActionResult> Create()
        {
            Expense exp = new Expense();
            exp.Date = DateTime.Now;
            ViewBag.dateInit = DateTime.Now.ToString("dd/MM/yyyy");

            await GetCategorySelectListAsync();
            await GetPaymentTypesSelectListAsync();

            return View(exp);
        }
        public async Task<ActionResult> Create(Expense expense)
        {
            await GetCategorySelectListAsync();
            await GetPaymentTypesSelectListAsync();
            
            try
            {
                if (ModelState.IsValid)
                {
                    string url = base.GetApiServiceURL("Expenses");
                    var httpClient = new HttpClient();
                    httpClient.DefaultRequestHeaders.Add("User-Agent", "Other");
                    var response = await httpClient.PostAsJsonAsync(url, expense);

                    if (response.IsSuccessStatusCode)
                    {
                        ShowMessage("Expense added.", EnumMessageType.INFO);
                    }
                    else
                    {
                        ShowMessage("Expense Create : Server error.", EnumMessageType.ERROR);
                    }

                    return RedirectToAction("Index", "Balance");
                }
                else
                {
                    return View();
                }
                                
                
            }
            catch
            {
                ShowMessage("Error creating new expense.", EnumMessageType.ERROR);
                return View();
            }
        }
        public async Task<ActionResult> Edit(string id, Expense expensePut)
        {           
            try
            {
                string url = base.GetApiServiceURL("Expenses");

                expensePut.Id = ObjectId.Parse(id);

                var httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Add("User-Agent", "Other");
                var response = await httpClient.PutAsJsonAsync(url + "/" + id, expensePut);

                if (response.IsSuccessStatusCode)
                {
                    ShowMessage("Expense updated.", EnumMessageType.INFO);
                }
                else
                {
                    await GetCategorySelectListAsync();
                    await GetPaymentTypesSelectListAsync();

                    ShowMessage("Expense Edit : Server error.", EnumMessageType.ERROR);
                }

                return RedirectToAction("Index", "Balance");

            }
            catch
            {
                await GetCategorySelectListAsync();
                await GetPaymentTypesSelectListAsync();

                ShowMessage("Error updating expense.", EnumMessageType.ERROR);
                return View();
            }
        }