public async Task Update(InstallationCheckingPnDbContext dbContext) { Installation installation = await dbContext.Installations.FirstOrDefaultAsync(x => x.Id == Id); if (installation == null) { throw new NullReferenceException($"Could not find item with id: {Id}"); } installation.CadastralNumber = CadastralNumber; installation.CadastralType = CadastralType; installation.PropertyNumber = PropertyNumber; installation.ApartmentNumber = ApartmentNumber; installation.LivingFloorsNumber = LivingFloorsNumber; installation.YearBuilt = YearBuilt; installation.CompanyName = CompanyName; installation.CompanyAddress = CompanyAddress; installation.CompanyAddress2 = CompanyAddress2; installation.CityName = CityName; installation.CountryCode = CountryCode; installation.ZipCode = ZipCode; installation.Type = Type; installation.State = State; installation.DateInstall = DateInstall; installation.DateRemove = DateRemove; installation.DateActRemove = DateActRemove; installation.InstallationEmployeeId = InstallationEmployeeId; installation.RemovalEmployeeId = RemovalEmployeeId; installation.CustomerId = CustomerId; installation.InstallationSdkCaseId = InstallationSdkCaseId; installation.RemovalSdkCaseId = RemovalSdkCaseId; installation.WorkflowState = WorkflowState; installation.UpdatedAt = UpdatedAt; installation.UpdatedByUserId = UpdatedByUserId; installation.Meters = Meters; if (dbContext.ChangeTracker.HasChanges()) { installation.UpdatedAt = DateTime.UtcNow; installation.Version += 1; dbContext.InstallationVersions.Add(MapInstallationVersion(installation)); await dbContext.SaveChangesAsync(); } }
public async Task Delete(InstallationCheckingPnDbContext dbContext) { Installation installation = await dbContext.Installations.FirstOrDefaultAsync(x => x.Id == Id); if (installation == null) { throw new NullReferenceException($"Could not find Installation with id: {Id}"); } installation.WorkflowState = Constants.WorkflowStates.Removed; if (dbContext.ChangeTracker.HasChanges()) { installation.UpdatedAt = DateTime.UtcNow; installation.Version += 1; dbContext.InstallationVersions.Add(MapInstallationVersion(installation)); await dbContext.SaveChangesAsync(); } }
private InstallationVersion MapInstallationVersion(Installation installation) { InstallationVersion installationVersion = new InstallationVersion { InstallationId = installation.Id, CadastralNumber = installation.CadastralNumber, CadastralType = installation.CadastralType, PropertyNumber = installation.PropertyNumber, ApartmentNumber = installation.ApartmentNumber, LivingFloorsNumber = installation.LivingFloorsNumber, YearBuilt = installation.YearBuilt, CompanyName = installation.CompanyName, CompanyAddress = installation.CompanyAddress, CompanyAddress2 = installation.CompanyAddress2, CityName = installation.CityName, CountryCode = installation.CountryCode, ZipCode = installation.ZipCode, Type = installation.Type, State = installation.State, DateInstall = installation.DateInstall, DateRemove = installation.DateRemove, DateActRemove = installation.DateActRemove, InstallationEmployeeId = installation.InstallationEmployeeId, RemovalEmployeeId = installation.RemovalEmployeeId, CustomerId = installation.CustomerId, InstallationSdkCaseId = installation.InstallationSdkCaseId, RemovalSdkCaseId = installation.RemovalSdkCaseId, RemovalFormId = installation.RemovalFormId, InstallationImageName = installation.InstallationImageName, CreatedAt = installation.CreatedAt, UpdatedAt = installation.UpdatedAt, Version = installation.Version, WorkflowState = installation.WorkflowState, UpdatedByUserId = installation.UpdatedByUserId, CreatedByUserId = installation.CreatedByUserId }; return(installationVersion); }