コード例 #1
0
        public ActionResult AddOwnIncome()
        {
            string uri = "https://localhost:44320/api/webApi/GetOwnIncomeCategory";

            var model = new AddOwnIncomeViewModel {
            };

            hc.BaseAddress = new Uri(uri);

            var cunsume_income = hc.GetAsync("GetOwnIncomeCategory");

            try { cunsume_income.Wait(); }
            catch (Exception e) { }

            var test = cunsume_income.Result;

            if (test.IsSuccessStatusCode)
            {
                Console.WriteLine("OK !!");
                var display = test.Content.ReadAsAsync <IList <o_income> >();

                foreach (var category in display.Result)
                {
                    model.categories.Add(category.oinc_name);
                }

                return(View(model));
            }
            return(View());
        }
コード例 #2
0
        public ActionResult AddOwnIncome(AddOwnIncomeViewModel model)
        {
            if (model.flag)
            {
                hc.BaseAddress = new Uri("https://localhost:44320/Api/WebApi/AddOwnIncomeCategory");

                o_income obj = new o_income
                {
                    oinc_name = model.oinc_name,
                    uid       = model.uid
                };

                var consume = hc.PostAsJsonAsync("AddOwnIncomeCategory", obj);
                consume.Wait();
                var test = consume.Result;
                if (test.IsSuccessStatusCode)
                {
                    return(RedirectToAction("AddOwnIncome", "Consume"));
                }
                return(RedirectToAction("AddOwnIncome", "Consume"));
            }
            else
            {
                hc.BaseAddress = new Uri("https://localhost:44320/Api/WebApi/AddTrasaction");
                trasaction data    = budgetManagerEntities.trasactions.Where(x => x.uid.Equals(model.uid)).OrderByDescending(x => x.ttime).FirstOrDefault();
                string     date    = System.DateTime.Now.ToString("dd/MM/yyyy");
                string     time    = System.DateTime.Now.ToString("ddd, dd MMM yyy HH�:�mm�:�ss �GMT�");
                string     cat     = model.oinc_name;
                int        amount  = 0;
                int        expense = 0;
                if (data.Equals(null))
                {
                    amount += model.inc_amount;
                }
                else
                {
                    amount  = data.tot_inc + model.inc_amount;
                    expense = data.tot_exp;
                }

                int userid = model.uid;

                trasaction tObj = new trasaction
                {
                    tdate   = date,
                    ttime   = time,
                    t_cat   = cat,
                    tot_inc = amount,
                    tot_exp = expense,
                    uid     = userid
                };

                var consume = hc.PostAsJsonAsync("AddTrasaction", tObj);
                consume.Wait();

                var test = consume.Result;

                if (test.IsSuccessStatusCode)
                {
                    return(RedirectToAction("AddOwnIncome", "Consume"));
                }
                else
                {
                    return(RedirectToAction("AddOwnIncome", "Consume"));
                }
            }
        }