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