public async Task <IActionResult> UpdateAdministrationCurrencyAsync([FromBody] UpdateAdministrationCurrencyAc updateAdministrationCurrency) { if (string.IsNullOrEmpty(updateAdministrationCurrency.Name.Trim())) { return(Ok(new SharedLookUpResponse { ErrorType = SharedLookUpResponseType.Name, HasError = true, Message = "Currency name can't be null or empty" })); } else if (string.IsNullOrEmpty(updateAdministrationCurrency.Code.Trim())) { return(Ok(new SharedLookUpResponse { ErrorType = SharedLookUpResponseType.Code, HasError = true, Message = "Currency symbol can't be null or empty" })); } else { var loggedInUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync(); if (await _iMSDbContext.AdministrationCurrencies.AnyAsync(x => x.Id == updateAdministrationCurrency.CurrencyId && x.InstituteId == loggedInUserInstituteId)) { return(Ok(await _administrationCurrencyManagementRepository.UpdateAdministrationCurrencyAsync(updateAdministrationCurrency, loggedInUserInstituteId))); } else { return(Ok(new SharedLookUpResponse { HasError = true, ErrorType = SharedLookUpResponseType.Other, Message = "Currency not found" })); } } }
/// <summary> /// Method to update currency - SS /// </summary> /// <param name="updateAdministrationCurrency">currency detail</param> /// <param name="instituteId">institute id</param> /// <returns>message</returns> public async Task <SharedLookUpResponse> UpdateAdministrationCurrencyAsync(UpdateAdministrationCurrencyAc updateAdministrationCurrency, int instituteId) { var currencies = await _iMSDbContext.AdministrationCurrencies.Where(x => x.InstituteId == instituteId && x.Id != updateAdministrationCurrency.CurrencyId).ToListAsync(); var isDuplicateSymbol = currencies.Any(x => x.Symbol.ToLowerInvariant() == updateAdministrationCurrency.Code.ToLowerInvariant()); if (isDuplicateSymbol) { return new SharedLookUpResponse() { HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Duplicate symbol of currency. Please use unique name" } } ; else { var currency = await _iMSDbContext.AdministrationCurrencies.FirstAsync(x => x.Id == updateAdministrationCurrency.CurrencyId); currency.CurrencyName = updateAdministrationCurrency.Name; currency.Symbol = updateAdministrationCurrency.Code; currency.Description = updateAdministrationCurrency.Description; currency.Status = updateAdministrationCurrency.Status; _iMSDbContext.AdministrationCurrencies.Update(currency); await _iMSDbContext.SaveChangesAsync(); return(new SharedLookUpResponse() { HasError = false, Message = "Currency updated successfully" }); } }