Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions VolunterSite.WebUI/Cozy.Service/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace Cozy.Service
{
public class Class1
{
}
}
7 changes: 7 additions & 0 deletions VolunterSite.WebUI/Cozy.Service/Cozy.Service.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.EntityFrameworkCore;
using VolunteerSite.Domain.Models;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;

namespace VolunteerSite.Data.Context
{
public class VolunteerSiteDbContext : IdentityDbContext<AppUser>
{
//public DbSet<Volunteer> Volunteers { get; set; }


public DbSet<VolunteerGroup> VolunteerGroups { get; set; }
public DbSet<Organization> Organizations { get; set; }
public DbSet<JobListing> JobListings { get; set; }
public DbSet<GroupMember> GroupMembers { get; set; }
public DbSet<Volunteer> Volunteers { get; set; }

// Setting up the provider (SQL Server) and location of the Database
protected override void OnConfiguring(DbContextOptionsBuilder optionBuilder)
{
// bad way of providing the connection string
optionBuilder.UseSqlServer(@"Server=(localdb)\MSSQLLocalDB;Database=volunteersite;Trusted_Connection=True");
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<AppUser>()
.HasOne(u => u.Volunteer)
.WithOne(v => v.User)
.HasForeignKey<Volunteer>(v => v.UserId);

modelBuilder.Entity<VolunteerGroup>()
.HasOne(g => g.GroupAdmin)
.WithMany(u => u.VolunteerGroups)
.HasForeignKey(g => g.GroupAdminId)
.HasConstraintName("ForeignKey_VolunteerGroup_AppUser");

modelBuilder.Entity<AppUser>()
.HasOne(u => u.Organization)
.WithOne(o => o.OrganizationAdmin)
.HasForeignKey<Organization>(o => o.OrganizationAdminId)
.HasConstraintName("ForeignKey_Organization_AppUser");

modelBuilder.Entity<SavedJobListing>()
.HasOne(j => j.Volunteer)
.WithMany(u => u.SavedJobListings)
.HasForeignKey(j => j.VolunteerId)
.HasConstraintName("ForeignKey_SavedJobListing_Volunteer");


modelBuilder.Entity<IdentityRole>().HasData(
new IdentityRole { Name = "Volunteer", NormalizedName = "VOLUNTEER" },
new IdentityRole { Name = "OrganizationAdmin", NormalizedName = "ORGANIZATIONADMIN" },
new IdentityRole { Name = "GroupAdmin", NormalizedName = "GROUPADMIN" }
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VolunteerSite.Data.Context;
using VolunteerSite.Data.Interfaces;
using VolunteerSite.Domain.Models;

namespace VolunteerSite.Data.Implementation.EFCore
{
public class EFCoreGroupMemberRepository : IGroupMemberRepository
{
public GroupMember Create(GroupMember newGroupMember)
{
using (var context = new VolunteerSiteDbContext())
{
context.GroupMembers.Add(newGroupMember);
context.SaveChanges();

return newGroupMember;
}
}

public bool DeleteById(int groupMemberId)
{
using (var context = new VolunteerSiteDbContext())
{
var groupMemberToBeDeleted = GetById(groupMemberId);
context.Remove(groupMemberToBeDeleted);
context.SaveChanges();

if (GetById(groupMemberId) == null)
{
return true;
}

return false;
}
}

public ICollection<GroupMember> GetByGroupId(string volunteerGroupId)
{
using (var context = new VolunteerSiteDbContext())
{
return context.GroupMembers.Where(m => m.VolunteerGroupId == volunteerGroupId).ToList();
}
}

public GroupMember GetById(int groupMemberId)
{
using (var context = new VolunteerSiteDbContext())
{
return context.GroupMembers.Single(m => m.Id == groupMemberId);
}
}

public GroupMember Update(GroupMember updatedGroupMember)
{
using (var context = new VolunteerSiteDbContext())
{
var existingGroupMember = GetById(updatedGroupMember.Id);
context.Entry(existingGroupMember).CurrentValues.SetValues(updatedGroupMember);
context.SaveChanges();

return existingGroupMember;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VolunteerSite.Data.Context;
using VolunteerSite.Data.Interfaces;
using VolunteerSite.Domain.Models;

namespace VolunteerSite.Data.Implementation.EFCore
{
public class EFCoreJobListingRepository : IJobListingRepository
{
public JobListing Create(JobListing newJobListing)
{
using (var context = new VolunteerSiteDbContext())
{
context.JobListings.Add(newJobListing);
context.SaveChanges();

return newJobListing;
}
}

public bool DeleteById(int jobListingId)
{
using (var context = new VolunteerSiteDbContext())
{
var jobListingToBeDeleted = GetById(jobListingId);
context.Remove(jobListingToBeDeleted);
context.SaveChanges();

if (GetById(jobListingId) == null)
{
return true;
}

return false;
}
}


public JobListing GetById(int jobListingId)
{
using (var context = new VolunteerSiteDbContext())
{
return context.JobListings.Single(j => j.Id == jobListingId);
}
}

public ICollection<JobListing> GetAll()
{
using (var context = new VolunteerSiteDbContext())
{
return context.JobListings.AsEnumerable().ToList();
}
}

public ICollection<JobListing> GetByOrganizationId(int organizationId)
{
using (var context = new VolunteerSiteDbContext())
{
return context.JobListings.Where(j => j.OrganizationId == organizationId).ToList();
}
}

public ICollection<JobListing> GetByTypeOfJob(string typeOfJob)
{
using (var context = new VolunteerSiteDbContext())
{
return context.JobListings.Where(m => m.TypeOfJob == typeOfJob).ToList();
}
}

public JobListing Update(JobListing updatedJobListing)
{
using (var context = new VolunteerSiteDbContext())
{
var existingJobListing = GetById(updatedJobListing.Id);
context.Entry(existingJobListing).CurrentValues.SetValues(updatedJobListing);
context.SaveChanges();

return existingJobListing;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VolunteerSite.Data.Context;
using VolunteerSite.Data.Interfaces;
using VolunteerSite.Domain.Models;

namespace VolunteerSite.Data.Implementation.EFCore
{
public class EFCoreOrganizationRepository : IOrganizationRepository
{
public Organization Create(Organization newOrganization)
{
using (var context = new VolunteerSiteDbContext())
{
context.Organizations.Add(newOrganization);
context.SaveChanges();

return newOrganization;
}
}

public bool DeleteById(int organizationId)
{
using (var context = new VolunteerSiteDbContext())
{
var organizationToBeDeleted = GetById(organizationId);
context.Remove(organizationToBeDeleted);
context.SaveChanges();

if (GetById(organizationId) == null)
{
return true;
}

return false;
}
}

public Organization GetById(int organizationId)
{
using (var context = new VolunteerSiteDbContext())
{
return context.Organizations.Single(o => o.Id == organizationId);
}
}

public Organization GetByAdminId(string adminId)
{
using (var context = new VolunteerSiteDbContext())
{
return context.Organizations.Single(o => o.OrganizationAdminId == adminId);
}
}

public Organization Update(Organization updatedOrganization)
{
using (var context = new VolunteerSiteDbContext())
{
var existingOrganization = GetById(updatedOrganization.Id);
context.Entry(existingOrganization).CurrentValues.SetValues(updatedOrganization);
context.SaveChanges();

return existingOrganization;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VolunteerSite.Data.Context;
using VolunteerSite.Data.Interfaces;
using VolunteerSite.Domain.Models;

namespace VolunteerSite.Data.Implementation.EFCore
{
public class EFCoreVolunteerGroupRepository : IVolunteerGroupRepository
{
public VolunteerGroup Create(VolunteerGroup newVolunteerGroup)
{
using (var context = new VolunteerSiteDbContext())
{
context.VolunteerGroups.Add(newVolunteerGroup);
context.SaveChanges();

return newVolunteerGroup;
}
}

public bool DeleteById(int volunteerGroupId)
{
using (var context = new VolunteerSiteDbContext())
{
var volunteerGroupToBeDeleted = GetById(volunteerGroupId);
context.Remove(volunteerGroupToBeDeleted);
context.SaveChanges();

if (GetById(volunteerGroupId) == null)
{
return true;
}

return false;
}
}

public VolunteerGroup GetById(int volunteerGroupId)
{
using (var context = new VolunteerSiteDbContext())
{
return context.VolunteerGroups.Single(v => v.Id == volunteerGroupId);
}
}

public VolunteerGroup Update(VolunteerGroup updatedVolunteerGroup)
{
using (var context = new VolunteerSiteDbContext())
{
var existingVolunteerGroup = GetById(updatedVolunteerGroup.Id);
context.Entry(existingVolunteerGroup).CurrentValues.SetValues(updatedVolunteerGroup);
context.SaveChanges();

return existingVolunteerGroup;
}
}
}
}
Loading