-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove all use of girafdbcontext in week template controller + setup …
…weektemplate repository
- Loading branch information
1 parent
72b4bcc
commit 8bd68fb
Showing
3 changed files
with
90 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 15 additions & 2 deletions
17
GirafRepositories/WeekPlanner/Interfaces/IWeekTemplateRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
using GirafEntities.User; | ||
using GirafEntities.WeekPlanner; | ||
using GirafEntities.WeekPlanner.DTOs; | ||
using GirafRepositories.Interfaces; | ||
|
||
namespace GirafRepositories.Interfaces | ||
namespace GirafRepositories.WeekPlanner.Interfaces | ||
{ | ||
public interface IWeekTemplateRepository : IRepository<WeekTemplate> | ||
{ | ||
|
||
WeekTemplateNameDTO[] GetWeekTemplatesForUser(GirafUser user); | ||
Task<WeekTemplate> GetWeekTemplateFromIdAndUser(long id, GirafUser user); | ||
void AddWeekTemplate(WeekTemplate newTemplate); | ||
void UpdateWeekTemplate(WeekTemplate template); | ||
void RemoveTemplate(WeekTemplate template); | ||
WeekTemplate GetWeekTemplateFromId(long id); | ||
|
||
|
||
|
||
|
||
Task<int> SaveChangesAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,70 @@ | ||
using GirafEntities.User; | ||
using GirafEntities.WeekPlanner; | ||
using GirafRepositories.Interfaces; | ||
using GirafEntities.WeekPlanner.DTOs; | ||
using GirafRepositories.Persistence; | ||
using GirafRepositories.WeekPlanner.Interfaces; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace GirafRepositories.WeekPlanner | ||
{ | ||
public class WeekTemplateRepository : Repository<WeekTemplate>, IWeekTemplateRepository | ||
{ | ||
public WeekTemplateRepository(GirafDbContext context) : base(context) | ||
{ | ||
|
||
} | ||
|
||
public WeekTemplateNameDTO[] GetWeekTemplatesForUser(GirafUser user) | ||
{ | ||
return Context.WeekTemplates | ||
.Where(t => t.DepartmentKey == user.DepartmentKey) | ||
.Select(w => new WeekTemplateNameDTO(w.Name, w.Id)).ToArray(); | ||
} | ||
|
||
public async Task<WeekTemplate> GetWeekTemplateFromIdAndUser(long id, GirafUser user) | ||
{ | ||
return await Context.WeekTemplates | ||
.Include(w => w.Thumbnail) | ||
.Include(u => u.Weekdays) | ||
.ThenInclude(wd => wd.Activities) | ||
.ThenInclude(pa => pa.Pictograms) | ||
.ThenInclude(p => p.Pictogram) | ||
.Where(t => t.DepartmentKey == user.DepartmentKey) | ||
.FirstOrDefaultAsync(w => w.Id == id); | ||
} | ||
|
||
public void AddWeekTemplate(WeekTemplate newTemplate) | ||
{ | ||
Context.WeekTemplates.Add(newTemplate); | ||
} | ||
|
||
public void UpdateWeekTemplate(WeekTemplate template) | ||
{ | ||
Context.WeekTemplates.Update(template); | ||
} | ||
|
||
public void RemoveTemplate(WeekTemplate template) | ||
{ | ||
Context.WeekTemplates.Remove(template); | ||
} | ||
|
||
public WeekTemplate GetWeekTemplateFromId(long id) | ||
{ | ||
return Context.WeekTemplates | ||
.Include(w => w.Thumbnail) | ||
.Include(u => u.Weekdays) | ||
.ThenInclude(wd => wd.Activities) | ||
.ThenInclude(e => e.Pictograms) | ||
.FirstOrDefault(t => id == t.Id); | ||
} | ||
|
||
/// <summary> | ||
/// Saves changes. | ||
/// </summary> | ||
/// <returns></returns> | ||
public Task<int> SaveChangesAsync() | ||
{ | ||
return Context.SaveChangesAsync(); | ||
} | ||
} | ||
} |