public static IEnumerable <WaterTransferRegistrationParcelDto> SaveParcels(RioDbContext dbContext, int waterTransferID, WaterTransferRegistrationDto waterTransferRegistrationDto) { // get the registration record var waterTransferRegistration = dbContext.WaterTransferRegistration.Single(x => x.WaterTransferID == waterTransferID && x.WaterTransferTypeID == waterTransferRegistrationDto.WaterTransferTypeID); // delete existing parcels registered var existingWaterTransferRegistrationParcels = dbContext.WaterTransferRegistrationParcel.Where(x => x.WaterTransferRegistrationID == waterTransferRegistration.WaterTransferRegistrationID); if (existingWaterTransferRegistrationParcels.Any()) { dbContext.WaterTransferRegistrationParcel.RemoveRange(existingWaterTransferRegistrationParcels); dbContext.SaveChanges(); } foreach (var waterTransferParcelDto in waterTransferRegistrationDto.WaterTransferRegistrationParcels) { var waterTransferRegistrationParcel = new WaterTransferRegistrationParcel { WaterTransferRegistrationID = waterTransferRegistration.WaterTransferRegistrationID, ParcelID = waterTransferParcelDto.ParcelID, AcreFeetTransferred = waterTransferParcelDto.AcreFeetTransferred }; dbContext.WaterTransferRegistrationParcel.Add(waterTransferRegistrationParcel); } dbContext.SaveChanges(); return(ListByWaterTransferRegistrationID(dbContext, waterTransferRegistration.WaterTransferRegistrationID)); }
public static WaterTransferRegistrationParcelDto AsDto(this WaterTransferRegistrationParcel waterTransferRegistrationParcel) { return(new WaterTransferRegistrationParcelDto { ParcelID = waterTransferRegistrationParcel.ParcelID, ParcelNumber = waterTransferRegistrationParcel.Parcel.ParcelNumber, AcreFeetTransferred = waterTransferRegistrationParcel.AcreFeetTransferred }); }