public DashboardComponent Get(int id) { const string sql = @"SELECT * FROM [dbo].[DashboardComponents] WHERE [Id] = @id"; using (var command = new SqlCommand(sql, _connection)) { _connection.Open(); command.Parameters.AddWithValue("@id", id); using (var reader = command.ExecuteReader()) { reader.Read(); var component = new DashboardComponent(); component.Id = reader.GetInt32(0); component.DashboardId = reader.GetInt32(1); component.Title = reader.GetString(2); component.Type = reader.GetInt32(3); component.Definition = reader.GetString(4); component.CreationDate = reader.GetString(5); component.ModificationDate = reader.GetString(6); _connection.Close(); return(component); } } }
public int Add(DashboardComponent component) { const string sql = @"INSERT INTO [dbo].[DashboardComponents] (DashboardId, Title, Type, Definition, CreationDate, ModificationDate) VALUES (@dashboardId, @title, @type, @definition, @creationDate, @modificationDate); SELECT @@IDENTITY;"; using (var command = new SqlCommand(sql, _connection)) { _connection.Open(); command.Parameters.AddWithValue("@dashboardId", component.DashboardId); command.Parameters.AddWithValue("@title", component.Title); command.Parameters.AddWithValue("@type", component.Type); command.Parameters.AddWithValue("@definition", component.Definition); command.Parameters.AddWithValue("@creationDate", component.CreationDate); command.Parameters.AddWithValue("@modificationDate", DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss")); int id = 0; object result = command.ExecuteScalar(); _connection.Close(); if (result != null) { id = Convert.ToInt32(result); } component.Id = id; return(id); } }
public DashboardComponentDto DashboardComponentToDto(DashboardComponent component) { var dto = new DashboardComponentDto(); dto.DashboardId = component.DashboardId; dto.Definition = component.Definition; dto.Id = component.Id; dto.CreationDate = component.CreationDate; dto.Title = component.Title; dto.Type = component.Type; dto.ModificationDate = component.ModificationDate; return(dto); }
public DashboardComponent DtoToDashboardComponent(DashboardComponentDto dto) { var component = new DashboardComponent(); component.DashboardId = dto.DashboardId; component.Definition = dto.Definition; component.Id = dto.Id; component.CreationDate = dto.CreationDate; component.Title = dto.Title; component.Type = dto.Type; component.ModificationDate = dto.ModificationDate; return(component); }
public DashboardComponent ReportComponentToDashboardComponent(ReportComponent reportComponent) { var dashboardComponent = new DashboardComponent(); dashboardComponent.Title = reportComponent.Title; dashboardComponent.Type = reportComponent.Type; dashboardComponent.CreationDate = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss"); dashboardComponent.ModificationDate = dashboardComponent.CreationDate; var serializer = new JavaScriptSerializer(); dashboardComponent.Definition = serializer.Serialize(reportComponent.Data); return(dashboardComponent); }
public void UpdateDashboardAfterRemoval(DashboardComponent component) { var componentDefinition = new List <int>(); const string sql = @"SELECT Definition FROM [dbo].[Dashboards] WHERE [Id] = @dashboardId"; using (var command = new SqlCommand(sql, _connection)) { _connection.Open(); command.Parameters.AddWithValue("@dashboardId", component.DashboardId); using (var reader = command.ExecuteReader()) { reader.Read(); try { componentDefinition = _serializer.Deserialize <List <int> >(reader.GetString(0)); } finally { if (componentDefinition == null) { componentDefinition = new List <int>(); } } } _connection.Close(); } for (int i = 0; i < componentDefinition.Count; i++) { if (componentDefinition[i] == component.Id) { componentDefinition.RemoveAt(i); break; } } const string update = @"UPDATE [dbo].[Dashboards] SET [Definition] = @definition, [ModificationDate] = @modificationDate WHERE [Id] = @id"; using (var command = new SqlCommand(update, _connection)) { _connection.Open(); command.Parameters.AddWithValue("@definition", _serializer.Serialize(componentDefinition)); command.Parameters.AddWithValue("@id", component.DashboardId); command.Parameters.AddWithValue("@modificationDate", DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss")); command.ExecuteNonQuery(); _connection.Close(); } }
public int Update(DashboardComponent component) { const string sql = @"UPDATE [dbo].[DashboardComponents] SET [DashboardId] = @dashboardId, [Title] = @title, [Type] = @type, [Definition] = @definition, [ModificationDate] = @modificationDate WHERE [Id] = @id"; using (var command = new SqlCommand(sql, _connection)) { _connection.Open(); command.Parameters.AddWithValue("@dashboardId", component.DashboardId); command.Parameters.AddWithValue("@title", component.Title); command.Parameters.AddWithValue("@type", component.Type); command.Parameters.AddWithValue("@definition", component.Definition); command.Parameters.AddWithValue("@id", component.Id); command.Parameters.AddWithValue("@modificationDate", DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss")); command.ExecuteNonQuery(); _connection.Close(); return(component.Id); } }
private DashboardViewBase GetNewViewFor(DashboardComponent component) { // TODO: remove BaseType? chain var classList = (from domainAssembly in AppDomain.CurrentDomain.GetAssemblies() from assemblyType in domainAssembly.GetTypes() where assemblyType.IsSubclassOf(typeof(DashboardViewBase)) && (assemblyType.BaseType?.BaseType?.GenericTypeArguments.Contains(component.GetType())).GetValueOrDefault() && !assemblyType.IsAbstract select assemblyType).ToArray(); Type target = classList.FirstOrDefault(); if (target == null) { return(null); } else { return((DashboardViewBase)Activator.CreateInstance(target, component)); } }
public void ShouldGetDashboardComponent() { //Arrange var repository = new Mock <IDashboardComponentRepository>(); var dashboardComponent = new DashboardComponent { Id = 1, CreationDate = "deittaim.nao", DashboardId = 1, Definition = "[]", Title = "test", Type = 1 }; repository.Setup(x => x.Get(It.IsAny <int>())).Returns(dashboardComponent); var handler = new DashboardComponentGetHandler(repository.Object); //Act var result = handler.HandleCore(1); //Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(DashboardComponentResponse)); }
public void SetUp() { _testEntity = new DashboardComponent(); _privateObject = new PrivateObject(_testEntity); }