public ActionResult Create(CreateEditHouseholdViewModel model)
        {
            var cookie = Request.Cookies["MyFirstCookie"];

            if (cookie == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var parameters = new List <KeyValuePair <string, string> >();

            parameters.Add(
                new KeyValuePair <string, string>("Name", model.Name));
            parameters.Add(
                new KeyValuePair <string, string>("Description", model.Description));

            var encodedParameters = new FormUrlEncodedContent(parameters);

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Add("Authorization",
                                                 $"Bearer {cookie.Value}");

            var response = httpClient
                           .PostAsync("http://localhost:64310/api/household/create",
                                      encodedParameters)
                           .Result;

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(RedirectToAction("Index"));
            }
            else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
            {
                var data = response.Content.ReadAsStringAsync().Result;

                var errors = JsonConvert.DeserializeObject <APIErroData>(data);

                foreach (var key in errors.ModelState)
                {
                    foreach (var error in key.Value)
                    {
                        ModelState.AddModelError(key.Key, error);
                    }
                }

                return(View(model));
            }
            else
            {
                //Create a log for the error message
                ModelState.AddModelError("", "Sorry. An unexpected error has occured. Please try again later");
                return(View(model));
            }
        }
        public ActionResult Edit(int id)
        {
            var cookie = Request.Cookies["MyFirstCookie"];

            if (cookie == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Add("Authorization",
                                                 $"Bearer {cookie.Value}");

            var response = httpClient
                           .GetAsync($"http://localhost:64310/api/household/ViewById/{id}")
                           .Result;

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var data = response.Content.ReadAsStringAsync().Result;

                var result = JsonConvert.DeserializeObject <HouseholdsViewModel>(data);

                if (!result.IsOwner)
                {
                    return(RedirectToAction("Index"));
                }

                var editViewModel = new CreateEditHouseholdViewModel();
                editViewModel.Name        = result.Name;
                editViewModel.Description = result.Description;
                editViewModel.DateUpdated = DateTime.Now;
                return(View(editViewModel));
            }
            else
            {
                //Create a log for the error message
                return(RedirectToAction("Index"));
            }
        }