public async Task <SharedLookUpResponse> UpdateHostelAsync(UpdateHostelAc updateHostelAc, int instituteId) { var componentGroups = await iMSDbContext.Hostels.Where(x => x.InstituteId == instituteId && x.Id != updateHostelAc.Id).ToListAsync(); var isDuplicated = componentGroups.Any(x => x.Code.ToLowerInvariant() == updateHostelAc.Code.ToLowerInvariant() && x.Name.ToLowerInvariant() == updateHostelAc.Name.ToLowerInvariant()); if (isDuplicated) { return new SharedLookUpResponse() { HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Duplicate Code of Hostel, please use unique code" } } ; else { var hostel = await iMSDbContext.Hostels.FirstAsync(x => x.Id == updateHostelAc.Id); hostel.Name = updateHostelAc.Name; hostel.Code = updateHostelAc.Code; hostel.HostelType = updateHostelAc.HostelType; hostel.ContactMobile = updateHostelAc.ContactMobile; hostel.ContactPerson = updateHostelAc.ContactPerson; hostel.CountryId = updateHostelAc.CountryId; hostel.StateId = updateHostelAc.StateId; hostel.CityId = updateHostelAc.CityId; hostel.ZipCode = updateHostelAc.ZipCode; hostel.Address1 = updateHostelAc.Address1; hostel.Address2 = updateHostelAc.Address2; hostel.HostelCautionDeposit = updateHostelAc.HostelCautionDeposit; hostel.PlaceName = updateHostelAc.PlaceName; hostel.Status = updateHostelAc.Status; iMSDbContext.Hostels.Update(hostel); await iMSDbContext.SaveChangesAsync(); return(new SharedLookUpResponse() { HasError = false, Message = "Hostel updated successfully" }); } }
public async Task <IActionResult> UpdateGroupAsync([FromBody] UpdateHostelAc updateHostelAc) { if (string.IsNullOrEmpty(updateHostelAc.Name.Trim())) { return(Ok(new SharedLookUpResponse() { HasError = true, ErrorType = SharedLookUpResponseType.Name, Message = "Hostel name can't be null or empty" })); } else if (string.IsNullOrEmpty(updateHostelAc.Code.Trim())) { return(Ok(new SharedLookUpResponse() { HasError = true, ErrorType = SharedLookUpResponseType.Name, Message = "Hostel code can't be null or empty" })); } else { var instituteId = await GetUserCurrentSelectedInstituteIdAsync(); if (await iMSDbContext.Hostels.AnyAsync(x => x.Id == updateHostelAc.Id && x.InstituteId == instituteId)) { return(Ok(await hostelManagementRepository.UpdateHostelAsync(updateHostelAc, instituteId))); } else { return(Ok(new SharedLookUpResponse() { HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Hostel not found" })); } } }