public async Task <SharedLookUpResponse> UpdateComponentAsync(UpdateBedAllocation updateComponentAc, int instituteId) { var componentGroups = await iMSDbContext.BedAllocations.Where(x => x.InstituteId == instituteId && x.Id != updateComponentAc.Id).ToListAsync(); var isDuplicated = componentGroups.Any(x => x.BedId == updateComponentAc.BedId && x.StudentId == updateComponentAc.StudentId); if (isDuplicated) { return new SharedLookUpResponse() { HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Duplicate allocation of Bed Allocation, please use unique code" } } ; else { var componentGroup = await iMSDbContext.BedAllocations.FirstAsync(x => x.Id == updateComponentAc.Id); componentGroup.BedId = updateComponentAc.BedId; componentGroup.StudentId = updateComponentAc.StudentId; componentGroup.Status = updateComponentAc.Status; iMSDbContext.BedAllocations.Update(componentGroup); await iMSDbContext.SaveChangesAsync(); return(new SharedLookUpResponse() { HasError = false, Message = "Bed Allocation updated successfully" }); } }
public async Task <IActionResult> UpdateGroupAsync([FromBody] UpdateBedAllocation updateComponentGroupAc) { var instituteId = await GetUserCurrentSelectedInstituteIdAsync(); if (await iMSDbContext.BedAllocations.AnyAsync(x => x.Id == updateComponentGroupAc.Id && x.InstituteId == instituteId)) { return(Ok(await bedAllocationManagementRepository.UpdateComponentAsync(updateComponentGroupAc, instituteId))); } else { return(Ok(new SharedLookUpResponse() { HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Bed Allocation not found" })); } }