using System; using System.Linq; using BO.AppServer.Data.Entity; using Microsoft.EntityFrameworkCore; using Quadarax.Foundation.Core.Data.Domain; using Quadarax.Foundation.Core.Data.Extensions; using Quadarax.Foundation.Core.Data.Interface; using Quadarax.Foundation.Core.Data.Interface.Domain; using Quadarax.Foundation.Core.Data.Repository; public class WorkspaceRepo : EntityRepository { public WorkspaceRepo(IUnitOfWork unitOfWork) : base(unitOfWork) { } public Workspace NewWorkspace(string name, BillingPlan billingPlan, bool isDefault, User owner, User creator) { var workspace = New(); workspace.Created = DateTime.Now; workspace.CreatedByUser = creator; workspace.Structures.Add(new Structure(){Created = DateTime.Now,CreatedByUserId = creator.Id}); AppendUser(workspace, owner, isDefault); return workspace; } public void AppendUser(Workspace workspace, User user, bool isDefault) { var userWorkspaceSet = Context.GetDbSet>(); var userWorkspace = new UserWorkspace(); userWorkspace.Workspace = workspace; userWorkspace.User = user; userWorkspace.IsDefault = isDefault; userWorkspaceSet.Add(userWorkspace); } public IQueryable GetAllEmpty(IPaging paging) { return Query(paging).Where(x => x.Structures.Any(struc => !struc.Metadocuments.Any())); } public IQueryable GetAllNonEmpty(IPaging paging) { return Query(paging).Where(x => x.Structures.Any(struc => struc.Metadocuments.Count>0)); } public IQueryable GetAllByOwner(User owner, IPaging paging) { var userWorkspaceSet = Context.GetDbSet>(); return userWorkspaceSet.Page(paging.IsDisabled ? (int?)null : paging.Page, paging.PageSize) .Where(x => x.User == owner).Select(x => x.Workspace); } }