| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using MUNity.Database.Context; |
| | 4 | | using MUNity.Database.Models.Conference; |
| | 5 | | using MUNity.Database.Models.Organization; |
| | 6 | | using MUNity.Database.Models.User; |
| | 7 | |
|
| | 8 | | namespace MUNity.Database.FluentAPI; |
| | 9 | |
|
| | 10 | | public class ProjectOptionsBuilder |
| | 11 | | { |
| 20 | 12 | | public Project Project { get; } |
| | 13 | |
|
| | 14 | | private readonly MunityContext _context; |
| | 15 | |
|
| 4 | 16 | | private bool _useEasyId = true; |
| | 17 | |
|
| | 18 | | public ProjectOptionsBuilder WithName(string name) |
| 4 | 19 | | { |
| 4 | 20 | | this.Project.ProjectName = name; |
| 4 | 21 | | return this; |
| 4 | 22 | | } |
| | 23 | |
|
| | 24 | | public ProjectOptionsBuilder WithShort(string shortName) |
| 4 | 25 | | { |
| 4 | 26 | | this.Project.ProjectShort = shortName; |
| 4 | 27 | | return this; |
| 4 | 28 | | } |
| | 29 | |
|
| | 30 | | public ProjectOptionsBuilder WithCreationUser(MunityUser user) |
| 1 | 31 | | { |
| 1 | 32 | | this.Project.CreationUser = user; |
| 1 | 33 | | return this; |
| 1 | 34 | | } |
| | 35 | |
|
| | 36 | | public ProjectOptionsBuilder WithOrganization(string organizationId) |
| 1 | 37 | | { |
| 1 | 38 | | var organization = _context.Organizations.FirstOrDefault(n => n.OrganizationId == organizationId); |
| 1 | 39 | | if (organization == null) |
| 0 | 40 | | throw new NullReferenceException("The Organization with the given Id cannot be found!"); |
| | 41 | |
|
| 1 | 42 | | Project.ProjectOrganization = organization; |
| 1 | 43 | | return this; |
| 1 | 44 | | } |
| | 45 | |
|
| | 46 | | public ProjectOptionsBuilder WithConference(Action<ConferenceOptionsBuilder> options) |
| 2 | 47 | | { |
| 2 | 48 | | var builder = new ConferenceOptionsBuilder(_context, Project); |
| 2 | 49 | | options(builder); |
| 2 | 50 | | var conference = builder.Conference; |
| 2 | 51 | | _context.Conferences.Add(conference); |
| 2 | 52 | | return this; |
| 2 | 53 | | } |
| | 54 | |
|
| 4 | 55 | | public ProjectOptionsBuilder(MunityContext context, Organization organization = null) |
| 4 | 56 | | { |
| 4 | 57 | | this.Project = new Project(); |
| 4 | 58 | | this._context = context; |
| 4 | 59 | | this.Project.ProjectOrganization = organization; |
| 4 | 60 | | } |
| | 61 | | } |