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