| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using System.Text; |
| | 5 | | using System.Threading.Tasks; |
| | 6 | | using MUNity.Database.Context; |
| | 7 | | using MUNity.Schema.Conference.Website; |
| | 8 | |
|
| | 9 | | namespace MUNity.Services |
| | 10 | | { |
| | 11 | | public class ConferenceWebsiteService |
| | 12 | | { |
| | 13 | | private MunityContext _context; |
| | 14 | |
|
| | 15 | | public List<MenuItem> GetMenuItems(string conferenceId) |
| 0 | 16 | | { |
| 0 | 17 | | return _context.ConferenceWebMenuEntries |
| 0 | 18 | | .Where(n => n.Conference.ConferenceId == conferenceId && n.Parent == null) |
| 0 | 19 | | .Select(n => new MenuItem() |
| 0 | 20 | | { |
| 0 | 21 | | Id = n.ConferenceWebMenuEntryId, |
| 0 | 22 | | PageId = n.TargetedPage.ConferenceWebPageId, |
| 0 | 23 | | Title = n.Title, |
| 0 | 24 | | Items = n.ChildEntries.Select(a => new MenuItem() |
| 0 | 25 | | { |
| 0 | 26 | | Id = a.ConferenceWebMenuEntryId, |
| 0 | 27 | | PageId = a.TargetedPage.ConferenceWebPageId, |
| 0 | 28 | | Title = a.Title |
| 0 | 29 | | }).ToList() |
| 0 | 30 | | }).ToList(); |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | public CreatedPageResult AddPage(string conferenceId, int? parentItemId) |
| 0 | 34 | | { |
| 0 | 35 | | MUNity.Database.Models.Website.ConferenceWebMenuEntry parent = null; |
| 0 | 36 | | if (parentItemId != null) |
| 0 | 37 | | parent = _context.ConferenceWebMenuEntries.Find(parentItemId); |
| | 38 | |
|
| 0 | 39 | | var page = new MUNity.Database.Models.Website.ConferenceWebPage() |
| 0 | 40 | | { |
| 0 | 41 | | Conference = _context.Conferences.Find(conferenceId), |
| 0 | 42 | | CreationDate = DateTime.Now, |
| 0 | 43 | | IsIndexPage = false, |
| 0 | 44 | | LastUpdateDate = DateTime.Now, |
| 0 | 45 | | Title = "New Page" |
| 0 | 46 | | }; |
| | 47 | |
|
| 0 | 48 | | var menuItem = new MUNity.Database.Models.Website.ConferenceWebMenuEntry() |
| 0 | 49 | | { |
| 0 | 50 | | Conference = _context.Conferences.Find(conferenceId), |
| 0 | 51 | | Parent = parent, |
| 0 | 52 | | TargetedPage = page, |
| 0 | 53 | | Title = "New Page" |
| 0 | 54 | | }; |
| | 55 | |
|
| 0 | 56 | | _context.ConferenceWebMenuEntries.Add(menuItem); |
| 0 | 57 | | _context.ConferenceWebPages.Add(page); |
| 0 | 58 | | var recaff = _context.SaveChanges(); |
| | 59 | |
|
| 0 | 60 | | var result = new CreatedPageResult(); |
| 0 | 61 | | if (recaff > 0) |
| 0 | 62 | | { |
| 0 | 63 | | result.Success = true; |
| 0 | 64 | | result.PageId = page.ConferenceWebPageId; |
| 0 | 65 | | result.MenuItemId = menuItem.ConferenceWebMenuEntryId; |
| 0 | 66 | | } |
| | 67 | |
|
| 0 | 68 | | return result; |
| 0 | 69 | | } |
| | 70 | |
|
| | 71 | | public bool RenameMenuEntry(int menuEntryId, string newName) |
| 0 | 72 | | { |
| 0 | 73 | | var entry = _context.ConferenceWebMenuEntries.Find(menuEntryId); |
| 0 | 74 | | if (entry == null) |
| 0 | 75 | | return false; |
| | 76 | |
|
| 0 | 77 | | entry.Title = newName; |
| 0 | 78 | | _context.SaveChanges(); |
| 0 | 79 | | return true; |
| 0 | 80 | | } |
| | 81 | |
|
| 0 | 82 | | public ConferenceWebsiteService(MunityContext context) |
| 0 | 83 | | { |
| 0 | 84 | | _context = context; |
| 0 | 85 | | } |
| | 86 | | } |
| | 87 | | } |