public async Task <ActionResult> LibraryUser(string id = null)
        {
            LibraryUserViewModel viewModel = null;

            if (!string.IsNullOrEmpty(id))
            {
                LibraryUserResponse result = await _libraryUserClient.GetLibraryUserByLibraryUserCode(id);

                if (result.StatusIsSuccessful)
                {
                    viewModel = LibraryUserViewModel.CreateLibraryUserViewModel(result.Data);
                }
                else
                {
                    AddResponseErrorsToModelState(result);
                }
            }

            if (viewModel == null)
            {
                viewModel = new LibraryUserViewModel();
            }

            viewModel.Counties  = Counties.PopulateCountySelectList(viewModel.County);
            viewModel.Countries = Countries.PopulateCountrySelectList(viewModel.Country);

            return(View(viewModel));
        }
        public async Task <ActionResult> SaveLibraryUser(LibraryUserViewModel viewModel)
        {
            if (viewModel.CountyIds != null && viewModel.CountyIds.Length > 0)
            {
                viewModel.County = viewModel.CountyIds[0];
            }
            if (viewModel.CountryIds != null && viewModel.CountryIds.Length > 0)
            {
                viewModel.Country = viewModel.CountryIds[0];
            }

            if (!ModelState.IsValid)
            {
                viewModel.Counties  = Counties.PopulateCountySelectList(viewModel.County);
                viewModel.Countries = Countries.PopulateCountrySelectList(viewModel.Country);
                return(View("LibraryUser", viewModel));
            }

            string currentCode = string.Empty;

            if (string.IsNullOrEmpty(viewModel.LibraryUserCode))
            {
                var insertResponse = await _libraryUserClient.Insert(viewModel.GetApiModel());

                if (!insertResponse.StatusIsSuccessful)
                {
                    AddResponseErrorsToModelState(insertResponse);
                }
                else
                {
                    //viewModel.Id = insertResponse.ResponseResult;
                    currentCode = insertResponse.ResponseResult;
                    TempData["SuccessMessage"] = "Record Inserted";
                }
            }
            else
            {
                currentCode = viewModel.LibraryUserCode;
                var response = await _libraryUserClient.Update(viewModel.GetApiModel());

                if (!response.StatusIsSuccessful)
                {
                    AddResponseErrorsToModelState(response);
                }
                else
                {
                    TempData["SuccessMessage"] = "Record Updated";
                }
            }

            viewModel.Counties  = Counties.PopulateCountySelectList(viewModel.County);
            viewModel.Countries = Countries.PopulateCountrySelectList(viewModel.Country);

            return(View("LibraryUser", viewModel));
        }