| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using MUNity.Database.Context; |
| | 4 | | using MUNity.Database.Models.Conference; |
| | 5 | | using MUNity.Database.Models.User; |
| | 6 | |
|
| | 7 | | namespace MUNity.Database.FluentAPI; |
| | 8 | |
|
| | 9 | | public class ConferenceOptionsBuilder |
| | 10 | | { |
| | 11 | | private Conference _conference; |
| | 12 | |
|
| | 13 | | private readonly MunityContext _context; |
| | 14 | |
|
| | 15 | | public Conference Conference |
| | 16 | | { |
| | 17 | | get |
| 5 | 18 | | { |
| 5 | 19 | | this._conference.CreationDate = DateTime.Now; |
| 5 | 20 | | return _conference; |
| 5 | 21 | | } |
| | 22 | | } |
| | 23 | |
|
| | 24 | | public ConferenceOptionsBuilder WithName(string name) |
| 3 | 25 | | { |
| 3 | 26 | | this._conference.Name = name; |
| 3 | 27 | | return this; |
| 3 | 28 | | } |
| | 29 | |
|
| | 30 | | public ConferenceOptionsBuilder WithFullName(string fullName) |
| 3 | 31 | | { |
| 3 | 32 | | this._conference.FullName = fullName; |
| 3 | 33 | | return this; |
| 3 | 34 | | } |
| | 35 | |
|
| | 36 | | public ConferenceOptionsBuilder WithShort(string shortName) |
| 3 | 37 | | { |
| 3 | 38 | | this._conference.ConferenceShort = shortName; |
| 3 | 39 | | return this; |
| 3 | 40 | | } |
| | 41 | |
|
| | 42 | | public ConferenceOptionsBuilder WithStartDate(DateTime startDate) |
| 1 | 43 | | { |
| 1 | 44 | | this._conference.StartDate = startDate; |
| 1 | 45 | | return this; |
| 1 | 46 | | } |
| | 47 | |
|
| | 48 | | public ConferenceOptionsBuilder WithEndDate(DateTime endDate) |
| 1 | 49 | | { |
| 1 | 50 | | this._conference.EndDate = endDate; |
| 1 | 51 | | return this; |
| 1 | 52 | | } |
| | 53 | |
|
| | 54 | | public ConferenceOptionsBuilder WithBasePrice(decimal price) |
| 1 | 55 | | { |
| 1 | 56 | | this._conference.GeneralParticipationCost = price; |
| 1 | 57 | | return this; |
| 1 | 58 | | } |
| | 59 | |
|
| | 60 | | public ConferenceOptionsBuilder ByUser(MunityUser user) |
| 1 | 61 | | { |
| 1 | 62 | | this._conference.CreationUser = user; |
| 1 | 63 | | return this; |
| 1 | 64 | | } |
| | 65 | |
|
| | 66 | | public ConferenceOptionsBuilder WithProject(string projectId) |
| 1 | 67 | | { |
| 1 | 68 | | var project = _context.Projects.FirstOrDefault(n => n.ProjectId == projectId); |
| 1 | 69 | | if (project == null) |
| 0 | 70 | | throw new NullReferenceException($"The given Project {projectId} was not found. Make sure it exists."); |
| | 71 | |
|
| 1 | 72 | | Conference.ConferenceProject = project; |
| 1 | 73 | | return this; |
| 1 | 74 | | } |
| | 75 | |
|
| | 76 | | public ConferenceOptionsBuilder WithCommittee(Action<CommitteeOptionsBuilder> builder) |
| 1 | 77 | | { |
| 1 | 78 | | var options = new CommitteeOptionsBuilder(); |
| 1 | 79 | | builder(options); |
| 1 | 80 | | this._conference.Committees.Add(options.Committee); |
| 1 | 81 | | return this; |
| 1 | 82 | | } |
| | 83 | |
|
| 3 | 84 | | public ConferenceOptionsBuilder(MunityContext context, Project project = null) |
| 3 | 85 | | { |
| 3 | 86 | | this._conference = new Conference(); |
| 3 | 87 | | this._context = context; |
| 3 | 88 | | this._conference.ConferenceProject = project; |
| 3 | 89 | | } |
| | 90 | | } |