public ViewModels.Session GetCurrentSession(string dictaatName, string userId = null) { var count = this._context.DictaatSession .Include(ds => ds.DictaatDetails) .Where(s => s.DictaatDetailsId == dictaatName).Count(); if (count == 0) { var s = new DictaatSession() { DictaatDetailsId = dictaatName, StartedOn = DateTime.Now, }; _context.DictaatSession.Add(s); _context.SaveChanges(); } var session = _context.DictaatSession .Include("Participants.User") .FirstOrDefault(s => s.DictaatDetailsId == dictaatName && s.EndedOn == null); var response = new ViewModels.Session(session); if (userId != null && response.ParticipantIds.Contains(userId)) { response.ContainsMe = true; } return(response); }
/// <summary> /// Create a new dictaat based on a given template. /// </summary> /// <param name="name">Name of the dictaat. Must be unique.</param> /// <param name="template">optional template name, default = defaultTemplate</param> public void CreateDictaat(string name, ApplicationUser user, string template) { //Create the database entry var dictaatDetails = new DictaatDetails() { Name = name, DictaatOwnerId = user.Id, IsEnabled = false, //by default we don't show the dictaten }; var dictaatSession = new DictaatSession() { DictaatDetailsId = name, StartedOn = DateTime.Now, }; _context.DictaatSession.Add(dictaatSession); _context.DictaatDetails.Add(dictaatDetails); _context.SaveChanges(); //Create the folder Domain.Dictaat dictaat = _dictaatFactory.CreateDictaat(name, template); }
public Session(DictaatSession session) { this.ParticipantIds = session.Participants.Select(p => p.UserId); }