Changed parts of how data project stucture
This commit is contained in:
@@ -4,18 +4,14 @@
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Domain\Interfaces\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
|
||||
<PackageReference Include="mongocsharpdriver" Version="2.8.0" />
|
||||
<PackageReference Include="RabbitMQ.Client" Version="5.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Interfaces\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@@ -7,13 +6,9 @@ namespace BrightGlimmer.Data.Domain
|
||||
{
|
||||
public class Phone
|
||||
{
|
||||
[BsonElement("Id")]
|
||||
public Guid Id { get; set; }
|
||||
[BsonElement("Type")]
|
||||
public PhoneType Type { get; set; }
|
||||
[BsonElement("AreaCode")]
|
||||
public int AreaCode { get; set; }
|
||||
[BsonElement("Number")]
|
||||
public int Number { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@@ -7,17 +6,11 @@ namespace BrightGlimmer.Data.Domain
|
||||
{
|
||||
public class Student
|
||||
{
|
||||
[BsonElement("Id")]
|
||||
public Guid Id { get; set; }
|
||||
[BsonElement("FirstName")]
|
||||
public string FirstName { get; set; }
|
||||
[BsonElement("MiddleName")]
|
||||
public string MiddleName { get; set; }
|
||||
[BsonElement("LastName")]
|
||||
public string LastName { get; set; }
|
||||
[BsonElement("Email")]
|
||||
public string Email { get; set; }
|
||||
[BsonElement("Phones")]
|
||||
public List<Phone> Phones { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace BrightGlimmer.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(SqliteDatabaseContext))]
|
||||
[DbContext(typeof(SqliteContext))]
|
||||
[Migration("20190420001348_CreateDatabase")]
|
||||
partial class CreateDatabase
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace BrightGlimmer.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(SqliteDatabaseContext))]
|
||||
[DbContext(typeof(SqliteContext))]
|
||||
partial class SqliteDatabaseContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
using BrightGlimmer.Data.Domain;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Data.Repositories
|
||||
{
|
||||
public class MongoStudentRepository
|
||||
{
|
||||
private const string dbName = "bright_glimmer";
|
||||
private const string collectionName = "Students";
|
||||
private IMongoDatabase db;
|
||||
|
||||
public MongoStudentRepository()
|
||||
{
|
||||
var client = new MongoClient("mongodb://localhost:27017"); /* REMOVE LATER */
|
||||
db = client.GetDatabase(dbName);
|
||||
}
|
||||
|
||||
public List<Student> GetStudents()
|
||||
{
|
||||
return db.GetCollection<Student>(collectionName).Find(x => true).ToList();
|
||||
}
|
||||
|
||||
public Student GetStudent(Guid id)
|
||||
{
|
||||
return db.GetCollection<Student>(collectionName).Find(student => student.Id == id).SingleOrDefault();
|
||||
}
|
||||
|
||||
public Student GetStudentByEmail(string email)
|
||||
{
|
||||
return db.GetCollection<Student>(collectionName).Find(student => student.Email == email).Single();
|
||||
}
|
||||
|
||||
public void Create(Student student)
|
||||
{
|
||||
db.GetCollection<Student>(collectionName).InsertOne(student);
|
||||
}
|
||||
|
||||
public void Update(Student student)
|
||||
{
|
||||
var filter = Builders<Student>.Filter.Where(x => x.Id == student.Id);
|
||||
db.GetCollection<Student>(collectionName).ReplaceOne(filter, student);
|
||||
}
|
||||
|
||||
public void Remove(Guid id)
|
||||
{
|
||||
var filter = Builders<Student>.Filter.Where(x => x.Id == id);
|
||||
var operation = db.GetCollection<Student>(collectionName).DeleteOne(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,12 @@ using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Data.Repositories
|
||||
{
|
||||
public class SqliteStudentRepository
|
||||
public class StudentRepository
|
||||
{
|
||||
private readonly SqliteDatabaseContext context;
|
||||
private readonly SqliteContext context;
|
||||
|
||||
|
||||
public SqliteStudentRepository(SqliteDatabaseContext context)
|
||||
public StudentRepository(SqliteContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
@@ -6,9 +6,9 @@ using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Data
|
||||
{
|
||||
public class SqliteDatabaseContext : DbContext
|
||||
public class SqliteContext : DbContext
|
||||
{
|
||||
public SqliteDatabaseContext(DbContextOptions<SqliteDatabaseContext> options)
|
||||
public SqliteContext(DbContextOptions<SqliteContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user