public User[] GetAllUsersInsideWorkshop(Workshop workshop)
        {
            if(!workshop.ManagerReference.IsLoaded) workshop.ManagerReference.Load();
            var users = new List<User> {workshop.Manager};
            users.AddRange(workshop.Users);

            return users.ToArray();
        }
 public WorkshopDisplay(Workshop workshop)
 {
     Id = workshop.WorkshopID;
     Name = workshop.Name;
     if (!workshop.ManagerReference.IsLoaded) workshop.ManagerReference.Load();
     Manager = new UserDisplay(workshop.Manager);
     if(!workshop.Users.IsLoaded) workshop.Users.Load();
     MemberCount = workshop.Users.Count;
 }
 public WorkshopEntityViewModel MapToViewModel(Workshop model)
 {
     var workshopViewModel = new WorkshopEntityViewModel();
     if(model!=null)
     {
         workshopViewModel.Id = model.WorkshopID;
         workshopViewModel.Name = model.Name;
         if (model.Manager != null)
         {
             workshopViewModel.ManagerId = model.Manager.UserID;
             workshopViewModel.ManagerName = model.Manager.Fullname;
         }
         if (model.Team != null)
         {
             workshopViewModel.TeamName = model.Team.Name;
             workshopViewModel.TeamId = model.Team.TeamID;
         }
     }
     return workshopViewModel;
 }
 public void MapToModel(WorkshopEntityViewModel entityViewModel, Workshop model, bool includeManager)
 {
     model.Name = entityViewModel.Name;
     if(includeManager) model.Manager = _userRepository.GetByID((int)entityViewModel.ManagerId);
     model.Team = _teamRepository.GetByID((int)entityViewModel.TeamId);
 }
 public void MapToModel(WorkshopEntityViewModel entityViewModel, Workshop model)
 {
     MapToModel(entityViewModel, model, true);
 }
 public void Save(Workshop item)
 {
     throw new NotImplementedException();
 }
        public Document[] GetPublicDocumentsByWorkshop(User currentUser, Workshop workshop)
        {
            var workshopUsers = _administrationService.GetAllUsersInsideWorkshop(workshop);
            var currentUserTeam = _userService.GetUserTeam(currentUser);
            var currentUserWorkshop = _userService.GetUserWorkshop(currentUser);
            if(!workshop.TeamReference.IsLoaded) workshop.TeamReference.Load();
            var documents = new List<Document>();
            foreach (var user in workshopUsers)
            {
                Func<Document, bool> documentSelectionCondition;
                if(currentUserWorkshop.WorkshopID==workshop.WorkshopID)
                {
                    documentSelectionCondition = (d => d.DistributionMode == DocumentDitributionMode.Protected.ID ||
                                                       d.DistributionMode == DocumentDitributionMode.Public.ID ||
                                                       d.DistributionMode == DocumentDitributionMode.Team.ID);
                }
                else if (currentUserTeam.TeamID == workshop.Team.TeamID)
                {
                    documentSelectionCondition = (d => d.DistributionMode == DocumentDitributionMode.Public.ID ||
                                                         d.DistributionMode == DocumentDitributionMode.Team.ID);
                }
                else
                {
                    documentSelectionCondition = (d => d.DistributionMode == DocumentDitributionMode.Public.ID);
                }

                if(!user.DocumentsAuthored.IsLoaded) user.DocumentsAuthored.Load();
                documents.AddRange(user.DocumentsAuthored.Where(documentSelectionCondition).ToArray());
            }

            return documents.ToArray();
        }
 public void Delete(Workshop item)
 {
     Context.DeleteObject(item);
 }
 public void Add(Workshop item)
 {
     Context.AddToWorkshops(item);
 }