Exemplo n.º 1
0
        public ActionResult UpdateBank(EditBankAccount data)
        {
            string userID = HttpContext.Session.GetString(SessionKeyID);
            EditBankAccountInputModel dataBankAccount = new EditBankAccountInputModel();

            dataBankAccount.ID            = data.input.ID;
            dataBankAccount.BankID        = data.input.BankID;
            dataBankAccount.AccountNumber = data.input.AccountNumber;
            dataBankAccount.AccountName   = data.input.AccountName;
            dataBankAccount.isSelected    = true;
            dataBankAccount.UserID        = Guid.Parse(userID);
            JsonConvert.SerializeObject(dataBankAccount);
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(BaseAPI + "Profile/");
                //HTTP POST
                var postTask = client.PostAsJsonAsync <EditBankAccountInputModel>("EditBankAccount", dataBankAccount);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index", "BankAccount"));
                }
                else
                {
                    TempData["CustomError"] = "Gagal memperbarui data. Mohon hubungi admin.";
                }
            }
            TempData["CustomError"] = "Terjadi kesalahan. Mohon hubungi admin.";
            return(RedirectToAction("Update", "BankAccount", new { @id = HttpContext.Session.GetString(SessionKeyEdit) }));
        }
Exemplo n.º 2
0
        public ActionResult Update(string id)
        {
            if (HttpContext.Session.GetString(SessionKeyID) != null && HttpContext.Session.GetString(SessionKeyID) != "")
            {
                HttpContext.Session.SetString(SessionKeyEdit, id);
                var ID = Guid.Parse(id);
                IEnumerable <GetUserBankOutputModel> accounts = null;
                EditBankAccount data = new EditBankAccount();
                if (TempData["CustomError"] != null)
                {
                    ModelState.AddModelError(string.Empty, TempData["CustomError"].ToString());
                }
                else
                {
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(BaseAPI + "Profile/");
                        GetUserBankInputModel filter = new GetUserBankInputModel();
                        filter.UserID = Guid.Parse(HttpContext.Session.GetString(SessionKeyID).ToString());
                        var responseTask = client.PostAsJsonAsync <GetUserBankInputModel>("GetUserBankAccount", filter);
                        responseTask.Wait();

                        var result = responseTask.Result;
                        if (result.IsSuccessStatusCode)
                        {
                            var content = result.Content.ReadAsStringAsync();
                            GetUserBankResponseModel resutl = Newtonsoft.Json.JsonConvert.DeserializeObject <GetUserBankResponseModel>(content.Result);
                            accounts  = resutl.data;
                            data.item = accounts.Where(x => x.UserBankID == ID).First();
                        }
                        else                         //web api sent error response
                        {
                            ModelState.AddModelError(string.Empty, "Terjadi kesalahan. Mohon hubungi admin.");
                        }
                    }
                }
                return(View(data));
            }
            else
            {
                TempData["CustomError"] = "Silakan masuk sebelum menggunakan situs web.";
                //if (HttpContext.Session.GetString(Loginfrom) == "ADM/SPV")
                //{
                //	return RedirectToAction("AdminLogon", "Login");
                //}
                //else if (HttpContext.Session.GetString(Loginfrom) == "MDO")
                //{
                //	return RedirectToAction("OwnerLogon", "Login");
                //}
                //else
                //{
                //	return RedirectToAction("OwnerLogon", "Login");
                //}
                return(RedirectToAction("Logon", "Login"));
            }
        }