/// <summary> /// Method to update look up mapping - SS /// </summary> /// <param name="updateLookUpManagement">look up detail</param> /// <param name="instituteId">isntitute id</param> /// <returns>response</returns> public async Task <LookUpManagementResponse> UpdateLookUpMappingAsync(UpdateLookUpManagementAc updateLookUpManagement, int instituteId) { var subjects = await _iMSDbContext.LookUpMappings.Where(x => x.LookUp.InstituteId == instituteId && x.Id != updateLookUpManagement.Id).ToListAsync(); var isDuplicate = subjects.Any(x => x.Code.ToLowerInvariant() == updateLookUpManagement.Code.ToLowerInvariant()); if (isDuplicate) { return new LookUpManagementResponse() { HasError = true, Message = "Duplicate look up code. Please use unique look up code", ErrorType = LookUpManagementResponseType.Code } } ; else { var lookUpMapping = await _iMSDbContext.LookUpMappings.FirstAsync(x => x.Id == updateLookUpManagement.Id); lookUpMapping.Code = updateLookUpManagement.Code; lookUpMapping.Description = updateLookUpManagement.Description; lookUpMapping.Name = updateLookUpManagement.Name; lookUpMapping.IsDefault = updateLookUpManagement.IsDefault; lookUpMapping.IsDeleted = updateLookUpManagement.IsDeleted; lookUpMapping.IsSystemRow = updateLookUpManagement.IsSystemRow; lookUpMapping.Status = updateLookUpManagement.Status; lookUpMapping.LookUpId = updateLookUpManagement.LookUpId; _iMSDbContext.LookUpMappings.Update(lookUpMapping); await _iMSDbContext.SaveChangesAsync(); return(new LookUpManagementResponse() { HasError = false, Message = "Look up updated successfully" }); } }
public async Task <IActionResult> UpdateLookUpMappingAsync([FromBody] UpdateLookUpManagementAc updateLookUpManagement) { if (string.IsNullOrEmpty(updateLookUpManagement.Name.Trim())) { return(Ok(new LookUpManagementResponse { ErrorType = LookUpManagementResponseType.Name, HasError = true, Message = "Look up name can't be null or empty" })); } else if (string.IsNullOrEmpty(updateLookUpManagement.Code.Trim())) { return(Ok(new LookUpManagementResponse { ErrorType = LookUpManagementResponseType.Code, HasError = true, Message = "Look up code name can't be null or empty" })); } else { var loggedInUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync(); if (await _iMSDbContext.LookUps.AnyAsync(x => x.InstituteId == loggedInUserInstituteId)) { if (await _iMSDbContext.LookUpMappings.AnyAsync(x => x.Id == updateLookUpManagement.Id && x.LookUp.InstituteId == loggedInUserInstituteId)) { return(Ok(await _lookUpManagementRepository.UpdateLookUpMappingAsync(updateLookUpManagement, loggedInUserInstituteId))); } else { return(Ok(new LookUpManagementResponse { ErrorType = LookUpManagementResponseType.Other, HasError = true, Message = "Look up not found" })); } } else { return(Ok(new LookUpManagementResponse() { ErrorType = LookUpManagementResponseType.Other, HasError = true, Message = "Look up not found" })); } } }