public ActionResult Users(int?Id)
        {
            if (ErrorHelpers.IdIsInvalid(Id, TempData))
            {
                return(RedirectToAction("Index", "Household"));
            }

            var url = $"{ProjectConstants.APIURL}/api/household/getallusers/{Id}";

            var response       = HttpClientContext.httpClient.GetAsync(url).Result;
            var responseResult = response.Content.ReadAsStringAsync().Result;

            if (response.IsSuccessStatusCode)
            {
                var datas     = JsonConvert.DeserializeObject <List <UserViewModel> >(responseResult);
                var viewModel = new HouseholdUserViewModel
                {
                    UserViewModels = datas,
                    HouseholdId    = (int)Id,
                    IsCreator      = HouseholdHelpers.IsUserCreator((int)Id, Request, TempData)
                };

                return(View(viewModel));
            }
            else
            {
                ErrorHelpers.HandleResponseErrors(response, TempData, ModelState);
                return(RedirectToAction("Index", "Household"));
            }
        }
Example #2
0
        // Only household owner can create, edit, delete BankAccounts
        // Other members of the household can view the bank accounts

        // GET: HouseholdBankAccounts
        public ActionResult HouseholdBankAccounts(int?Id)
        {
            if (Id is null)
            {
                TempData.Add("Message", "Improper Id");
                TempData.Add("MessageColour", "danger");
                return(RedirectToAction("Index", "Household"));
            }

            var url = $"{ProjectConstants.APIURL}/api/bankaccount/getallbyhousehold/{Id}";

            var token      = Request.Cookies["UserAuthCookie"].Value;
            var authHeader = new AuthenticationHeaderValue("Bearer", token);

            HttpClientContext.httpClient.DefaultRequestHeaders.Authorization = authHeader;

            // Handling lack of connection??? try catch?
            var response = HttpClientContext.httpClient.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                var responseResult = response.Content.ReadAsStringAsync().Result;

                var datas     = JsonConvert.DeserializeObject <List <BankAccountViewModel> >(responseResult);
                var viewModel = new BankAccountListViewModel
                {
                    BankAccounts     = datas,
                    HouseholdId      = (int)Id,
                    IsHouseholdOwner = HouseholdHelpers.IsUserCreator((int)Id, Request, TempData)
                };
                return(View(viewModel));
            }
            else
            {
                ErrorHelpers.HandleResponseErrors(response, TempData, ModelState);
                return(RedirectToAction("Index", "Household"));
            }
        }