public async Task <ISingleResponse <ServiceEnvironmentStatusLog> > CreateServiceEnvironmentStatusLogAsync(ServiceEnvironmentStatusLog entity, int?serviceEnvironmentID) { Logger?.LogDebug("'{0}' has been invoked", nameof(CreateServiceEnvironmentStatusLogAsync)); var response = new SingleResponse <ServiceEnvironmentStatusLog>(); using (var txn = await DbContext.Database.BeginTransactionAsync()) { try { var serviceEnvStatus = await DbContext.GetByServiceEnvironmentAsync(new ServiceEnvironment(serviceEnvironmentID)); if (serviceEnvStatus == null) { serviceEnvStatus = new ServiceEnvironmentStatus { ServiceEnvironmentID = serviceEnvironmentID, Success = entity.Success, WatchCount = 1, LastWatch = DateTime.Now }; DbContext.ServiceEnvironmentStatuses.Add(serviceEnvStatus); await DbContext.SaveChangesAsync(); Logger?.LogInformation("The status for service environment was saved successfully"); } else { serviceEnvStatus.Success = entity.Success; serviceEnvStatus.WatchCount += 1; serviceEnvStatus.LastWatch = DateTime.Now; Logger?.LogInformation("The status for service environment was updated successfully"); } entity.ServiceEnvironmentStatusID = serviceEnvStatus.ServiceEnvironmentStatusID; entity.Date = DateTime.Now; DbContext.ServiceEnvironmentStatusLogs.Add(entity); await DbContext.SaveChangesAsync(); Logger?.LogInformation("The status details for service environment was created successfully"); txn.Commit(); response.Model = entity; } catch (Exception ex) { txn.Rollback(); response.SetError(Logger, nameof(CreateServiceEnvironmentStatusLogAsync), ex); } } return(response); }
public async Task <ISingleViewModelResponse <ServiceEnvironmentStatusLog> > CreateServiceEnvironmentStatusLogAsync(ServiceEnvironmentStatusLog entity, Int32?serviceEnvironmentID) { Logger?.LogDebug("'{0}' has been invoked", nameof(CreateServiceEnvironmentStatusLogAsync)); var response = new SingleViewModelResponse <ServiceEnvironmentStatusLog>(); using (var transaction = await DbContext.Database.BeginTransactionAsync()) { try { var serviceEnvStatus = await Repository.GetByServiceEnvironmentAsync(new ServiceEnvironment { ServiceEnvironmentID = serviceEnvironmentID }); if (serviceEnvStatus == null) { serviceEnvStatus = new ServiceEnvironmentStatus(); serviceEnvStatus.ServiceEnvironmentID = serviceEnvironmentID; serviceEnvStatus.Success = entity.Success; serviceEnvStatus.WatchCount = 1; serviceEnvStatus.LastWatch = DateTime.Now; await Repository.CreateServiceEnvironmentStatusAsync(serviceEnvStatus); Logger?.LogInformation("The status for service environment was saved successfully"); } else { serviceEnvStatus.Success = entity.Success; serviceEnvStatus.WatchCount += 1; serviceEnvStatus.LastWatch = DateTime.Now; Logger?.LogInformation("The status for service environment was updated successfully"); } entity.ServiceEnvironmentStatusID = serviceEnvStatus.ServiceEnvironmentStatusID; await Repository.CreateServiceEnvironmentStatusLogAsync(entity); Logger?.LogInformation("The status details for service environment was created successfully"); transaction.Commit(); response.Model = entity; } catch (Exception ex) { transaction.Rollback(); response.SetError(Logger, ex); } } return(response); }
public async Task <ISingleViewModelResponse <ServiceEnvironmentStatusLog> > CreateServiceEnvironmentStatusLogAsync(ServiceEnvironmentStatusLog entity, Int32?serviceEnvironmentID) { var response = new SingleViewModelResponse <ServiceEnvironmentStatusLog>(); using (var transaction = await DbContext.Database.BeginTransactionAsync()) { try { var serviceEnvStatus = await Repository.GetByServiceEnvironmentAsync(new ServiceEnvironment { ServiceEnvironmentID = serviceEnvironmentID }); if (serviceEnvStatus == null) { serviceEnvStatus = new ServiceEnvironmentStatus(); serviceEnvStatus.ServiceEnvironmentID = serviceEnvironmentID; serviceEnvStatus.Success = entity.Success; serviceEnvStatus.WatchCount = 1; serviceEnvStatus.LastWatch = DateTime.Now; await Repository.CreateServiceEnvironmentStatusAsync(serviceEnvStatus); } else { serviceEnvStatus.Success = entity.Success; serviceEnvStatus.WatchCount += 1; serviceEnvStatus.LastWatch = DateTime.Now; } entity.ServiceEnvironmentStatusID = serviceEnvStatus.ServiceEnvironmentStatusID; await Repository.CreateServiceEnvironmentStatusLogAsync(entity); transaction.Commit(); response.Model = entity; } catch (Exception ex) { transaction.Rollback(); response.DidError = true; response.ErrorMessage = ex.Message; } } return(response); }
public async Task <ISingleViewModelResponse <ServiceEnvironmentStatus> > GetServiceStatusAsync(ServiceEnvironmentStatus entity) { var response = new SingleViewModelResponse <ServiceEnvironmentStatus>(); try { response.Model = await Repository.GetServiceEnvironmentStatusAsync(entity); } catch (Exception ex) { response.DidError = true; response.ErrorMessage = ex.Message; } return(response); }
public static ServiceStatusResponse ToRequestModel(this ServiceEnvironmentStatus entity) => ViewModelMapper.ConfigMapper.Map <ServiceEnvironmentStatus, ServiceStatusResponse>(entity);
public async Task <ServiceEnvironmentStatus> GetServiceEnvironmentStatusAsync(ServiceEnvironmentStatus entity) { return(await DbContext .Set <ServiceEnvironmentStatus>() .FirstOrDefaultAsync(item => item.ServiceEnvironmentStatusID == entity.ServiceEnvironmentStatusID)); }
public static async Task <ServiceEnvironmentStatus> GetServiceEnvironmentStatusAsync(this ServiceMonitorDbContext dbContext, ServiceEnvironmentStatus entity) => await dbContext.ServiceEnvironmentStatuses.FirstOrDefaultAsync(item => item.ID == entity.ID);
public static ServiceStatusVm ToViewModel(this ServiceEnvironmentStatus entity) => ViewModelMapper.ConfigMapper.Map <ServiceEnvironmentStatus, ServiceStatusVm>(entity);
public async Task <ISingleResponse <ServiceEnvironmentStatus> > GetServiceStatusAsync(ServiceEnvironmentStatus entity) { Logger?.LogDebug("'{0}' has been invoked", nameof(GetServiceStatusAsync)); var response = new SingleResponse <ServiceEnvironmentStatus>(); try { response.Model = await DbContext.GetServiceEnvironmentStatusAsync(entity); } catch (Exception ex) { response.SetError(Logger, nameof(GetServiceStatusAsync), ex); } return(response); }
public async Task <Int32> CreateServiceEnvironmentStatusAsync(ServiceEnvironmentStatus entity) { DbContext.Set <ServiceEnvironmentStatus>().Add(entity); return(await DbContext.SaveChangesAsync()); }