diff --git a/src/TaskTracker.Common/Class1.cs b/src/TaskTracker.Common/Class1.cs deleted file mode 100644 index 67a17ca..0000000 --- a/src/TaskTracker.Common/Class1.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace TaskTracker.Common -{ - public class Class1 - { - } -} diff --git a/src/TaskTracker.Common/DataStrategy/ICacheStrategy.cs b/src/TaskTracker.Common/DataStrategy/ICacheStrategy.cs new file mode 100644 index 0000000..c5af4de --- /dev/null +++ b/src/TaskTracker.Common/DataStrategy/ICacheStrategy.cs @@ -0,0 +1,11 @@ +using System; + +namespace TaskTracker.Common.DataStrategy +{ + public interface ICacheStrategy where T : class + { + bool InsertOrUpdate(T entity); + T Get(string id); + bool Invalidate(string id); + } +} \ No newline at end of file diff --git a/src/TaskTracker.Common/DataStrategy/IDbStrategy.cs b/src/TaskTracker.Common/DataStrategy/IDbStrategy.cs new file mode 100644 index 0000000..35042c5 --- /dev/null +++ b/src/TaskTracker.Common/DataStrategy/IDbStrategy.cs @@ -0,0 +1,10 @@ +using System; +using TaskTracker.Common.Repository; + +namespace TaskTracker.Common.DataStrategy +{ + public interface IDbStrategy : IRepository where T : class + { + + } +} \ No newline at end of file diff --git a/src/TaskTracker.Common/DataStrategy/IInMemoryDbStrategy.cs b/src/TaskTracker.Common/DataStrategy/IInMemoryDbStrategy.cs new file mode 100644 index 0000000..eda5574 --- /dev/null +++ b/src/TaskTracker.Common/DataStrategy/IInMemoryDbStrategy.cs @@ -0,0 +1,10 @@ +using System; +using TaskTracker.Common.Repository; + +namespace TaskTracker.Common.DataStrategy +{ + public interface IInMemoryDbStrategy : IDbStrategy where T : class + { + + } +} \ No newline at end of file diff --git a/src/TaskTracker.Common/DataStrategy/INoSqlDbStrategy.cs b/src/TaskTracker.Common/DataStrategy/INoSqlDbStrategy.cs new file mode 100644 index 0000000..c0bc1b7 --- /dev/null +++ b/src/TaskTracker.Common/DataStrategy/INoSqlDbStrategy.cs @@ -0,0 +1,10 @@ +using System; +using TaskTracker.Common.Repository; + +namespace TaskTracker.Common.DataStrategy +{ + public interface INoSqlDbStrategy : IDbStrategy where T : class + { + + } +} \ No newline at end of file diff --git a/src/TaskTracker.Common/DataStrategy/ISqlDbStrategy.cs b/src/TaskTracker.Common/DataStrategy/ISqlDbStrategy.cs new file mode 100644 index 0000000..2adbb33 --- /dev/null +++ b/src/TaskTracker.Common/DataStrategy/ISqlDbStrategy.cs @@ -0,0 +1,9 @@ +using System; + +namespace TaskTracker.Common.DataStrategy +{ + public interface ISqlDbStrategy : IDbStrategy where T : class + { + + } +} \ No newline at end of file diff --git a/src/TaskTracker.Common/Models/FeatureModel.cs b/src/TaskTracker.Common/Models/FeatureModel.cs new file mode 100644 index 0000000..639d4ca --- /dev/null +++ b/src/TaskTracker.Common/Models/FeatureModel.cs @@ -0,0 +1,22 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace TaskTracker.Common.Models +{ + public class FeatureModel + { + public string FeatureName { get; set; } + public string FeatureDescription { get; set; } + [Key] + public Guid FeatureID { get; set; } + public Guid ProjectID { get; set; } + public Guid SprintID { get; set; } + //public string[] Tags { get; set; } + public int RankID { get; set; } + public Guid FeatureOwnerID { get; set; } + public DateTime CreatedDate { get; set; } + public Guid CreatedBy { get; set; } + public DateTime LastModifiedDate { get; set; } + public string LastModifiedBy { get; set; } + } +} \ No newline at end of file diff --git a/src/TaskTracker.Common/Models/ProjectModel.cs b/src/TaskTracker.Common/Models/ProjectModel.cs new file mode 100644 index 0000000..68bf553 --- /dev/null +++ b/src/TaskTracker.Common/Models/ProjectModel.cs @@ -0,0 +1,17 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace TaskTracker.Common.Models +{ + public class ProjectModel + { + [Key] + public Guid ProjectID { get; set; } + public string ProjectName { get; set; } + public string ProjectDescription { get; set; } + public DateTime CreatedDate { get; set; } + public Guid CreatedBy { get; set; } + public DateTime LastModifiedDate { get; set; } + public Guid LastModifiedBy { get; set; } + } +} \ No newline at end of file diff --git a/src/TaskTracker.Common/Models/SprintModel.cs b/src/TaskTracker.Common/Models/SprintModel.cs new file mode 100644 index 0000000..7b10bf5 --- /dev/null +++ b/src/TaskTracker.Common/Models/SprintModel.cs @@ -0,0 +1,17 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace TaskTracker.Common.Models +{ + public class SprintModel + { + [Key] + public Guid SprintID { get; set; } + public DateTime StartDate { get; set; } + public DateTime EndDate { get; set; } + public DateTime CreatedDate { get; set; } + public Guid CreatedBy { get; set; } + public DateTime LastModifiedDate { get; set; } + public Guid LastModifiedBy { get; set; } + } +} \ No newline at end of file diff --git a/src/TaskTracker.Common/Models/TaskModel.cs b/src/TaskTracker.Common/Models/TaskModel.cs new file mode 100644 index 0000000..9c83a9d --- /dev/null +++ b/src/TaskTracker.Common/Models/TaskModel.cs @@ -0,0 +1,22 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace TaskTracker.Common.Models +{ + public class TaskModel + { + public string TaskName { get; set; } + public string TaskDescription { get; set; } + [Key] + public Guid TaskID { get; set; } + public Guid TaskOwnerID { get; set; } + public Guid SprintID { get; set; } + public Guid FeatureID { get; set; } + public Guid ProjectID { get; set; } + public DateTime CreatedDate { get; set; } + public Guid CreatedBy { get; set; } + public DateTime LastModifiedDate { get; set; } + public Guid LastModifiedBy { get; set; } + public string CurrentStatus { get; set; } + } +} \ No newline at end of file diff --git a/src/TaskTracker.Common/Models/UserModel.cs b/src/TaskTracker.Common/Models/UserModel.cs new file mode 100644 index 0000000..d6bb247 --- /dev/null +++ b/src/TaskTracker.Common/Models/UserModel.cs @@ -0,0 +1,23 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace TaskTracker.Common.Models +{ + public class UserModel + { + [Key] + public Guid UserID { get; set; } + + public string Username { get; set; } + + public string Password { get; set; } + + public UserType Usertype { get; set; } + } + + public enum UserType + { + Admin, + TeamMember + } +} \ No newline at end of file diff --git a/src/TaskTracker.Common/Repository/IRepository.cs b/src/TaskTracker.Common/Repository/IRepository.cs new file mode 100644 index 0000000..d0be06e --- /dev/null +++ b/src/TaskTracker.Common/Repository/IRepository.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace TaskTracker.Common.Repository +{ + public interface IRepository where T : class + { + IEnumerable GetAll(); + T Delete(string id); + T GetById(string id); + T InsertOrUpdate(T entity); + } +} \ No newline at end of file diff --git a/src/TaskTracker.Common/Repository/Repository.cs b/src/TaskTracker.Common/Repository/Repository.cs new file mode 100644 index 0000000..bc9c376 --- /dev/null +++ b/src/TaskTracker.Common/Repository/Repository.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using TaskTracker.Common.DataStrategy; + +namespace TaskTracker.Common.Repository +{ + public abstract class Repository : IRepository where T : class + { + protected ICacheStrategy cacheStrategy; + + protected IDbStrategy dbStrategy; + + public Repository(ICacheStrategy cacheStrategy, IDbStrategy dbStrategy) + { + this.cacheStrategy = cacheStrategy; + this.dbStrategy = dbStrategy; + } + + public T GetById(string id) + { + var item = this.cacheStrategy.Get(id); + if (item != null) + { + return item; + } + + item = this.dbStrategy.GetById(id); + this.cacheStrategy.InsertOrUpdate(item); + + return item; + } + + public abstract IEnumerable GetAll(); + + public abstract T Delete(string id); + + public abstract T InsertOrUpdate(T entity); + } +} \ No newline at end of file diff --git a/src/TaskTracker.Common/TaskTracker.Common.csproj b/src/TaskTracker.Common/TaskTracker.Common.csproj index 1a986ae..7943c47 100644 --- a/src/TaskTracker.Common/TaskTracker.Common.csproj +++ b/src/TaskTracker.Common/TaskTracker.Common.csproj @@ -13,5 +13,6 @@ + diff --git a/src/TaskTracker.Services.Tasks/DataStrategy/CacheStrategy.cs b/src/TaskTracker.Services.Tasks/DataStrategy/CacheStrategy.cs new file mode 100644 index 0000000..c6b7a6d --- /dev/null +++ b/src/TaskTracker.Services.Tasks/DataStrategy/CacheStrategy.cs @@ -0,0 +1,21 @@ +using System; +using TaskTracker.Common.DataStrategy; + +namespace TaskTracker.Services.Tasks.DataStrategy +{ + public class CacheStrategy : ICacheStrategy where T : class + { + public bool InsertOrUpdate(T entity) + { + throw new NotImplementedException(); + } + public T Get(string id) + { + throw new NotImplementedException(); + } + public bool Invalidate(string id) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/TaskTracker.Services.Tasks/DataStrategy/InMemoryDbStrategy.cs b/src/TaskTracker.Services.Tasks/DataStrategy/InMemoryDbStrategy.cs new file mode 100644 index 0000000..630a870 --- /dev/null +++ b/src/TaskTracker.Services.Tasks/DataStrategy/InMemoryDbStrategy.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using TaskTracker.Common.DataStrategy; +using TaskTracker.Services.Tasks.EF; +using Microsoft.AspNetCore.Builder; + +namespace TaskTracker.Services.Tasks.DataStrategy +{ + public class InMemoryDbStrategy : IInMemoryDbStrategy where T : class + { + public IEnumerable GetAll() + { + throw new NotImplementedException(); + } + public T Delete(string id) + { + throw new NotImplementedException(); + } + public T GetById(string id) + { + throw new NotImplementedException(); + } + public T InsertOrUpdate(T entity) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/TaskTracker.Services.Tasks/DataStrategy/NoSqlDbStrategy.cs b/src/TaskTracker.Services.Tasks/DataStrategy/NoSqlDbStrategy.cs new file mode 100644 index 0000000..2d6002b --- /dev/null +++ b/src/TaskTracker.Services.Tasks/DataStrategy/NoSqlDbStrategy.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using TaskTracker.Common.DataStrategy; + +namespace TaskTracker.Services.Tasks.DataStrategy +{ + public class NoSqlDbStrategy : INoSqlDbStrategy where T : class + { + public IEnumerable GetAll() + { + throw new NotImplementedException(); + } + public T Delete(string id) + { + throw new NotImplementedException(); + } + public T GetById(string id) + { + throw new NotImplementedException(); + } + public T InsertOrUpdate(T entity) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/TaskTracker.Services.Tasks/DataStrategy/SqlDbStrategy.cs b/src/TaskTracker.Services.Tasks/DataStrategy/SqlDbStrategy.cs new file mode 100644 index 0000000..1559330 --- /dev/null +++ b/src/TaskTracker.Services.Tasks/DataStrategy/SqlDbStrategy.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using TaskTracker.Common.DataStrategy; + +namespace TaskTracker.Services.Tasks.DataStrategy +{ + public class SqlDbStrategy : ISqlDbStrategy where T : class + { + public IEnumerable GetAll() + { + throw new NotImplementedException(); + } + public T Delete(string id) + { + throw new NotImplementedException(); + } + public T GetById(string id) + { + throw new NotImplementedException(); + } + public T InsertOrUpdate(T entity) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/TaskTracker.Services.Tasks/EF/DataContext.cs b/src/TaskTracker.Services.Tasks/EF/DataContext.cs new file mode 100644 index 0000000..ddf849a --- /dev/null +++ b/src/TaskTracker.Services.Tasks/EF/DataContext.cs @@ -0,0 +1,30 @@ +using System; +using Microsoft.EntityFrameworkCore; +using TaskTracker.Common.Models; + +namespace TaskTracker.Services.Tasks.EF +{ + public class DataContext : DbContext + { + // public DataContext(DbContextOptions options) : base(options) + // { + + // } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseInMemoryDatabase("inmemorydb"); + //optionsBuilder.UseSqlite("Data Source=sql.db"); + } + + public DbSet tasks { get; set; } + + public DbSet features { get; set; } + + public DbSet projects { get; set; } + + public DbSet sprints { get; set; } + + public DbSet users { get; set; } + } +} \ No newline at end of file diff --git a/src/TaskTracker.Services.Tasks/Program.cs b/src/TaskTracker.Services.Tasks/Program.cs index a784b68..4d8c620 100644 --- a/src/TaskTracker.Services.Tasks/Program.cs +++ b/src/TaskTracker.Services.Tasks/Program.cs @@ -7,6 +7,9 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using TaskTracker.Services.Tasks.EF; +using TaskTracker.Common.Models; +using TaskTracker.Services.Tasks.DataStrategy; namespace TaskTracker.Services.Tasks { @@ -14,7 +17,26 @@ public class Program { public static void Main(string[] args) { - BuildWebHost(args).Run(); + //BuildWebHost(args).Run(); + + using(var dbContext = new DataContext()) + { + var testModel = new TaskModel + { + TaskName = "Test Task", + TaskDescription = "Test Description", + CreatedDate = DateTime.Now + }; + + dbContext.tasks.Add(testModel); + + dbContext.SaveChanges(); + + foreach(var task in dbContext.tasks) + { + Console.WriteLine(task.TaskName + "\n" + task.TaskDescription + "\n" + task.CreatedDate.Date); + } + } } public static IWebHost BuildWebHost(string[] args) => diff --git a/src/TaskTracker.Services.Tasks/Startup.cs b/src/TaskTracker.Services.Tasks/Startup.cs index 6185297..ef33468 100644 --- a/src/TaskTracker.Services.Tasks/Startup.cs +++ b/src/TaskTracker.Services.Tasks/Startup.cs @@ -8,18 +8,24 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Microsoft.EntityFrameworkCore; +using TaskTracker.Common.Models; +using TaskTracker.Services.Tasks.EF; namespace TaskTracker.Services.Tasks { public class Startup { - public Startup(IConfiguration configuration) + public Startup(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { Configuration = configuration; + HostingEnvironment = hostingEnvironment; } public IConfiguration Configuration { get; } + public IHostingEnvironment HostingEnvironment { get; } + // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { @@ -34,7 +40,24 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) app.UseDeveloperExceptionPage(); } + var context = app.ApplicationServices.GetService(); + AddTestData(context); + app.UseMvc(); } + + private static void AddTestData(DataContext context) + { + var testModel = new TaskModel + { + TaskName = "Test Task", + TaskDescription = "Test Description", + CreatedDate = DateTime.Now + }; + + context.tasks.Add(testModel); + + context.SaveChanges(); + } } } diff --git a/src/TaskTracker.Services.Tasks/TaskTracker.Services.Tasks.csproj b/src/TaskTracker.Services.Tasks/TaskTracker.Services.Tasks.csproj index 7d2b436..8ca8db7 100644 --- a/src/TaskTracker.Services.Tasks/TaskTracker.Services.Tasks.csproj +++ b/src/TaskTracker.Services.Tasks/TaskTracker.Services.Tasks.csproj @@ -1,23 +1,24 @@ - - - - netcoreapp2.0 - - - - - - - - - - - - - - - - - - - + + + + netcoreapp2.0 + + + + + + + + + + + + + + + + + + + +