public async Task <SharedLookUpResponse> UpdateComponentAsync(UpdateUOM updateComponentAc, int instituteId) { var componentGroups = await iMSDbContext.UOMs.Where(x => x.InstituteId == instituteId && x.Id != updateComponentAc.Id).ToListAsync(); var isDuplicated = componentGroups.Any(x => x.Code.ToLowerInvariant() == updateComponentAc.Code.ToLowerInvariant()); if (isDuplicated) { return new SharedLookUpResponse() { HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Duplicate Code of UOM, please use unique code" } } ; else { var componentGroup = await iMSDbContext.UOMs.FirstAsync(x => x.Id == updateComponentAc.Id); componentGroup.Name = updateComponentAc.Name; componentGroup.Code = updateComponentAc.Code; componentGroup.Description = updateComponentAc.Description; componentGroup.Status = updateComponentAc.Status; iMSDbContext.UOMs.Update(componentGroup); await iMSDbContext.SaveChangesAsync(); return(new SharedLookUpResponse() { HasError = false, Message = "UOM updated successfully" }); } }
public async Task <IActionResult> UpdateGroupAsync([FromBody] UpdateUOM updateComponentGroupAc) { if (string.IsNullOrEmpty(updateComponentGroupAc.Name.Trim())) { return(Ok(new SharedLookUpResponse() { HasError = true, ErrorType = SharedLookUpResponseType.Name, Message = "UOM name can't be null or empty" })); } else if (string.IsNullOrEmpty(updateComponentGroupAc.Code.Trim())) { return(Ok(new SharedLookUpResponse() { HasError = true, ErrorType = SharedLookUpResponseType.Name, Message = "UOM code can't be null or empty" })); } else { var instituteId = await GetUserCurrentSelectedInstituteIdAsync(); if (await iMSDbContext.UOMs.AnyAsync(x => x.Id == updateComponentGroupAc.Id && x.InstituteId == instituteId)) { return(Ok(await uOMManagementRepository.UpdateComponentAsync(updateComponentGroupAc, instituteId))); } else { return(Ok(new SharedLookUpResponse() { HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "UOM not found" })); } } }