Example #1
0
        public UpdateCountryViewModel GetCountryForUpdateById(short CountryID)
        {
            try
            {
                UpdateCountryViewModel model = new UpdateCountryViewModel();

                var entity = db.MasterCountries.Find(CountryID);
                if (entity != null)
                {
                    model.CountryRowID               = entity.CountryRowID;
                    model.CountryCode                = entity.CountryCode;
                    model.CountryName                = entity.CountryName;
                    model.CountryCallingCode         = entity.CountryCallingCode;
                    model.InternationalDialingPrefix = entity.InternationalDialingPrefix;
                    model.Status = entity.Status;
                }
                else
                {
                    throw new Exception("Invalid Id");
                }

                return(model);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public async Task UpdateCountryAsync(UpdateCountryViewModel updateCountryViewModel)
        {
            string jsonString = JsonSerializer.Serialize(updateCountryViewModel);

            using StringContent stringContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await _httpClient.PutAsync("country/update-country", stringContent);

            if (!response.IsSuccessStatusCode)
            {
                throw new ApplicationException($"{response.ReasonPhrase}: The status code is: {(int)response.StatusCode}");
            }
        }
Example #3
0
 public void UpdateCountry(UpdateCountryViewModel model)
 {
     try
     {
         if (model != null && model.CountryRowID > 0)
         {
             db.MasterCountries.Single(c => c.CountryRowID == model.CountryRowID).CountryName                = model.CountryName;
             db.MasterCountries.Single(c => c.CountryRowID == model.CountryRowID).CountryCode                = model.CountryCode;
             db.MasterCountries.Single(c => c.CountryRowID == model.CountryRowID).CountryCallingCode         = model.CountryCallingCode;
             db.MasterCountries.Single(c => c.CountryRowID == model.CountryRowID).InternationalDialingPrefix = model.InternationalDialingPrefix;
         }
         else
         {
             throw new Exception("Country could not be blank!");
         }
     }
     catch (Exception)
     {
         throw;
     }
 }