/// <summary> /// Method to update country - SS /// </summary> /// <param name="updateAdministrationCountry">country detail</param> /// <param name="instituteId">institute id</param> /// <returns>message</returns> public async Task <SharedLookUpResponse> UpdateInstituteCountryAsync(UpdateAdministrationCountryAc updateAdministrationCountry, int instituteId) { var countries = await _iMSDbContext.AdministrationCountries.Where(x => x.InstituteId == instituteId && x.Id != updateAdministrationCountry.CountryId).ToListAsync(); var isDuplicate = countries.Any(x => x.Code.ToLowerInvariant() == updateAdministrationCountry.Code.ToLowerInvariant()); if (isDuplicate) { return new SharedLookUpResponse() { HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Duplicate code of country. Please use unique code" } } ; else { var country = await _iMSDbContext.AdministrationCountries.FirstAsync(x => x.Id == updateAdministrationCountry.CountryId); country.Name = updateAdministrationCountry.Name; country.Code = updateAdministrationCountry.Code; country.Description = updateAdministrationCountry.Description; country.Status = updateAdministrationCountry.Status; _iMSDbContext.AdministrationCountries.Update(country); await _iMSDbContext.SaveChangesAsync(); return(new SharedLookUpResponse() { HasError = false, Message = "Country updated successfully" }); } }
public async Task <IActionResult> UpdateInstituteCountryAsync([FromBody] UpdateAdministrationCountryAc country) { if (string.IsNullOrEmpty(country.Name.Trim())) { return(Ok(new SharedLookUpResponse { ErrorType = SharedLookUpResponseType.Name, HasError = true, Message = "Country name can't be null or empty" })); } else if (string.IsNullOrEmpty(country.Code.Trim())) { return(Ok(new SharedLookUpResponse { ErrorType = SharedLookUpResponseType.Code, HasError = true, Message = "Country code can't be null or empty" })); } else { var loggedInUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync(); if (await _iMSDbContext.AdministrationCountries.AnyAsync(x => x.Id == country.CountryId && x.InstituteId == loggedInUserInstituteId)) { return(Ok(await _instituteCountryStateCityManagementRepository.UpdateInstituteCountryAsync(country, loggedInUserInstituteId))); } else { return(Ok(new SharedLookUpResponse { HasError = true, ErrorType = SharedLookUpResponseType.Other, Message = "Country not found" })); } } }