public async Task <GroupZoneResponse> DeleteGroupZone(int id, int brandId) { GroupZoneResponse groupZone = null; var result = await _unitOfWork.Repository <GroupZone>().GetAll().Where(x => x.Id == id && x.BrandId == brandId).Select(x => new { x.Id, x.BrandId, x.Geom, x.Name, x.TradeZones }).AsNoTracking().SingleOrDefaultAsync(); var tradezoneVersionsId = result.TradeZones.DistinctBy(c => c.TradeZoneVersionId).Select(x => x.TradeZoneVersionId); var tradezoneVersion = await _unitOfWork.Repository <TradeZoneVersion>().GetAll().Where(x => tradezoneVersionsId.Any(c => c == x.Id)).ToListAsync(); var isDeleteActive = tradezoneVersion.Any(x => x.IsActive); if (result != null) { groupZone = new GroupZoneResponse() { Id = result.Id, BrandId = result.BrandId, Geom = result.Geom, Name = result.Name, IsDeleteActive = isDeleteActive }; await _unitOfWork.Repository <GroupZone>().HardDelete(result.Id); _unitOfWork.Repository <TradeZoneVersion>().DeleteRange(tradezoneVersion.AsQueryable()); await _unitOfWork.CommitAsync(); } return(groupZone); }
public async Task <GroupZoneResponse> PutGroupZone(int id, PutGroupZoneRequest model, int brandId) { var result = await _unitOfWork.Repository <GroupZone>().GetAll().Where(x => x.Id == id && x.BrandId == brandId).SingleOrDefaultAsync(); if (result != null) { result.Name = model.Name; await _unitOfWork.Repository <GroupZone>().Update(result, result.Id); await _unitOfWork.CommitAsync(); GroupZoneResponse groupZone = new GroupZoneResponse() { Id = result.Id, BrandId = result.BrandId, Geom = result.Geom, Name = result.Name }; return(groupZone); } return(null); }