Maps Lightspeed entity classes to the Roadkill domain objects.
(AutoMapper was tried for this, but had problems with the Mindscape.LightSpeed.Entity class)
Ejemplo n.º 1
0
        public Organisation GetOrgByUser(string username)
        {
            UserEntity userentity = Users.FirstOrDefault(p => p.Username == username);
            OrgEntity  orgentity  = Orgs.FirstOrDefault(p => p.Id == userentity.orgID);

            return(FromEntity.ToOrg(orgentity));
        }
Ejemplo n.º 2
0
        public PageContent AddNewPage(Page page, string text, string editedBy, DateTime editedOn, DateTime projectStart, DateTime projectEnd, bool projectEstimatedTime, string projectStatus, string projectLanguage, int orgID)
        {
            PageEntity pageEntity = new PageEntity();

            ToEntity.FromPage(page, pageEntity);
            pageEntity.Id = 0;
            UnitOfWork.Add(pageEntity);
            UnitOfWork.SaveChanges();

            PageContentEntity pageContentEntity = new PageContentEntity()
            {
                Id                   = Guid.NewGuid(),
                Page                 = pageEntity,
                Text                 = text,
                EditedBy             = editedBy,
                EditedOn             = editedOn,
                VersionNumber        = 1,
                ProjectStart         = projectStart,
                ProjectEnd           = projectEnd,
                ProjectEstimatedTime = projectEstimatedTime,
                ProjectStatus        = projectStatus,
                ProjectLanguage      = projectLanguage,
                orgID                = orgID,
            };

            UnitOfWork.Add(pageContentEntity);
            UnitOfWork.SaveChanges();

            PageContent pageContent = FromEntity.ToPageContent(pageContentEntity);

            pageContent.Page = FromEntity.ToPage(pageEntity);
            return(pageContent);
        }
Ejemplo n.º 3
0
        public Organisation GetOrgByUser(Guid userId)
        {
            UserEntity userentity = Users.FirstOrDefault(p => p.Id == userId);
            OrgEntity  orgentity  = Orgs.FirstOrDefault(p => p.Id == userentity.orgID);

            return(FromEntity.ToOrg(orgentity));
        }
Ejemplo n.º 4
0
        public PageContent AddNewPage(Page page, string text, string editedBy, DateTime editedOn)
        {
            PageEntity pageEntity = new PageEntity();

            ToEntity.FromPage(page, pageEntity);
            pageEntity.Id = 0;
            UnitOfWork.Add(pageEntity);
            UnitOfWork.SaveChanges();

            PageContentEntity pageContentEntity = new PageContentEntity()
            {
                Id            = Guid.NewGuid(),
                Page          = pageEntity,
                Text          = text,
                EditedBy      = editedBy,
                EditedOn      = editedOn,
                VersionNumber = 1,
            };

            UnitOfWork.Add(pageContentEntity);
            UnitOfWork.SaveChanges();

            PageContent pageContent = FromEntity.ToPageContent(pageContentEntity);

            pageContent.Page = FromEntity.ToPage(pageEntity);
            return(pageContent);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This updates an existing set of text and is used for page rename updates.
        /// To add a new version of a page, use AddNewPageContentVersion
        /// </summary>
        /// <param name="content"></param>
        public void UpdatePageContent(PageContent content)
        {
            PageContentEntity entity = UnitOfWork.FindById <PageContentEntity>(content.Id);

            if (entity != null)
            {
                ToEntity.FromPageContent(content, entity);
                UnitOfWork.SaveChanges();
                content = FromEntity.ToPageContent(entity);
            }
        }
Ejemplo n.º 6
0
        public Relationship RelToUserToPage(int pageID, string username)
        {
            Relationship _RelToUserToPage = new Relationship();

            RelEntity entity = Rels.FirstOrDefault(r => r.username == username && r.pageId == pageID);

            if (entity != null && entity.pageId != 0)
            {
                _RelToUserToPage = FromEntity.ToRel(entity);
            }

            return(_RelToUserToPage);
        }
Ejemplo n.º 7
0
        public User GetUserByEmail(string email, bool?isActivated = null)
        {
            UserEntity entity;

            if (isActivated.HasValue)
            {
                entity = Users.FirstOrDefault(x => x.Email == email && x.IsActivated == isActivated);
            }
            else
            {
                entity = Users.FirstOrDefault(x => x.Email == email);
            }

            return(FromEntity.ToUser(entity));
        }
Ejemplo n.º 8
0
        public User GetUserById(Guid id, bool?isActivated = null)
        {
            UserEntity entity;

            if (isActivated.HasValue)
            {
                entity = Users.FirstOrDefault(x => x.Id == id && x.IsActivated == isActivated);
            }
            else
            {
                entity = Users.FirstOrDefault(x => x.Id == id);
            }

            return(FromEntity.ToUser(entity));
        }
Ejemplo n.º 9
0
        public Relationship AddNewRel(Relationship rel, int reltypeid, string username, int orgID, int pageID, string reltext)
        {
            RelEntity relEntity = new RelEntity();

            ToEntity.FromRelationship(rel, relEntity);
            relEntity.username    = username;
            relEntity.orgId       = orgID;
            relEntity.pageId      = pageID;
            relEntity.relDateTime = DateTime.Now;
            UnitOfWork.Add(relEntity);
            UnitOfWork.SaveChanges();

            Relationship newrel = FromEntity.ToRel(relEntity);

            return(newrel);
        }
Ejemplo n.º 10
0
        public PageContent AddNewPageContentVersion(Page page, string text, string editedBy, DateTime editedOn, int version, DateTime projectStart, DateTime projectEnd, bool projectEstimatedTime, string projectStatus, string projectLanguage, int orgID)
        {
            if (version < 1)
            {
                version = 1;
            }

            PageEntity pageEntity = UnitOfWork.FindById <PageEntity>(page.Id);

            if (pageEntity != null)
            {
                // Update the content
                PageContentEntity pageContentEntity = new PageContentEntity()
                {
                    Id                   = Guid.NewGuid(),
                    Page                 = pageEntity,
                    Text                 = text,
                    EditedBy             = editedBy,
                    EditedOn             = editedOn,
                    VersionNumber        = version,
                    ProjectStart         = projectStart,
                    ProjectEnd           = projectEnd,
                    ProjectEstimatedTime = projectEstimatedTime,
                    ProjectStatus        = projectStatus,
                    ProjectLanguage      = projectLanguage,
                    orgID                = orgID,
                };

                UnitOfWork.Add(pageContentEntity);
                UnitOfWork.SaveChanges();

                // The page modified fields
                pageEntity.ModifiedOn = editedOn;
                pageEntity.ModifiedBy = editedBy;
                UnitOfWork.SaveChanges();

                // Turn the content database entity back into a domain object
                PageContent pageContent = FromEntity.ToPageContent(pageContentEntity);
                pageContent.Page = FromEntity.ToPage(pageEntity);

                return(pageContent);
            }

            Log.Error("Unable to update page content for page id {0} (not found)", page.Id);
            return(null);
        }
Ejemplo n.º 11
0
        public List <Relationship> FindPageRelationships(int pageID)
        {
            List <RelEntity> entities = Rels.Where(p => p.pageId == pageID).ToList();

            foreach (var relEntity in entities)
            {
                if (string.IsNullOrEmpty(relEntity.username))
                {
                    var user = GetUserById(relEntity.UserId);
                    if (user != null)
                    {
                        relEntity.username = user.Username;
                    }
                }
            }

            return(FromEntity.ToRelList(entities));
        }
Ejemplo n.º 12
0
        public Page SaveOrUpdatePage(Page page)
        {
            PageEntity entity = UnitOfWork.FindById <PageEntity>(page.Id);

            if (entity == null)
            {
                entity = new PageEntity();
                ToEntity.FromPage(page, entity);
                UnitOfWork.Add(entity);
                UnitOfWork.SaveChanges();
                page = FromEntity.ToPage(entity);
            }
            else
            {
                ToEntity.FromPage(page, entity);
                UnitOfWork.SaveChanges();
                page = FromEntity.ToPage(entity);
            }

            return(page);
        }
Ejemplo n.º 13
0
        public Relationship SaveOrUpdateRel(Relationship rel)
        {
            RelEntity entity = UnitOfWork.FindById <RelEntity>(rel.Id);

            if (entity == null)
            {
                entity = new RelEntity();
                ToEntity.FromRelationship(rel, entity);
                UnitOfWork.Add(entity);
                UnitOfWork.SaveChanges();
                rel = FromEntity.ToRel(entity);
            }
            else
            {
                ToEntity.FromRelationship(rel, entity);
                UnitOfWork.SaveChanges();
                rel = FromEntity.ToRel(entity);
            }

            return(rel);
        }
Ejemplo n.º 14
0
        public User SaveOrUpdateUser(User user)
        {
            UserEntity entity = UnitOfWork.FindById <UserEntity>(user.Id);

            if (entity == null)
            {
                // Turn the domain object into a database entity
                entity = new UserEntity();
                ToEntity.FromUser(user, entity);
                UnitOfWork.Add(entity);
                UnitOfWork.SaveChanges();

                user = FromEntity.ToUser(entity);
            }
            else
            {
                ToEntity.FromUser(user, entity);
                UnitOfWork.SaveChanges();
            }

            return(user);
        }
Ejemplo n.º 15
0
        public Relationship SaveOrUpdateRel(Relationship rel)
        {
            RelEntity entity = UnitOfWork.FindById <RelEntity>(rel.id);

            if (entity == null)
            {
                entity = new RelEntity();
                ToEntity.FromRelationship(rel, entity);
                UnitOfWork.Add(entity);
                UnitOfWork.SaveChanges();
                rel = FromEntity.ToRel(entity);
            }
            else
            {
                rel.orgID = GetUserByUsername(rel.username).orgID;

                ToEntity.FromRelationship(rel, entity);
                UnitOfWork.SaveChanges();
                rel = FromEntity.ToRel(entity);
            }

            return(rel);
        }
Ejemplo n.º 16
0
        public User GetUserByPasswordResetKey(string key)
        {
            UserEntity entity = Users.FirstOrDefault(x => x.PasswordResetKey == key);

            return(FromEntity.ToUser(entity));
        }
Ejemplo n.º 17
0
        public IEnumerable <Page> FindPagesContainingTag(string tag)
        {
            IEnumerable <PageEntity> entities = Pages.Where(p => p.Tags.ToLower().Contains(tag.ToLower()));            // Lightspeed doesn't support ToLowerInvariant

            return(FromEntity.ToPageList(entities));
        }
Ejemplo n.º 18
0
        public IEnumerable <PageContent> GetPageContentByEditedBy(string username)
        {
            List <PageContentEntity> entities = PageContents.Where(p => p.EditedBy == username).ToList();

            return(FromEntity.ToPageContentList(entities));
        }
Ejemplo n.º 19
0
        public User GetUserByUsername(string username)
        {
            UserEntity entity = Users.FirstOrDefault(x => x.Username == username);

            return(FromEntity.ToUser(entity));
        }
Ejemplo n.º 20
0
        public PageContent GetPageContentById(Guid id)
        {
            PageContentEntity entity = PageContents.FirstOrDefault(p => p.Id == id);

            return(FromEntity.ToPageContent(entity));
        }
Ejemplo n.º 21
0
        public PageContent GetPageContentByPageIdAndVersionNumber(int id, int versionNumber)
        {
            PageContentEntity entity = PageContents.FirstOrDefault(p => p.Page.Id == id && p.VersionNumber == versionNumber);

            return(FromEntity.ToPageContent(entity));
        }
Ejemplo n.º 22
0
        public Page GetPageByTitle(string title)
        {
            PageEntity entity = Pages.FirstOrDefault(p => p.Title.ToLower() == title.ToLower());

            return(FromEntity.ToPage(entity));
        }
Ejemplo n.º 23
0
        public PageContent GetLatestPageContent(int pageId)
        {
            PageContentEntity entity = PageContents.Where(x => x.Page.Id == pageId).OrderByDescending(x => x.EditedOn).FirstOrDefault();

            return(FromEntity.ToPageContent(entity));
        }
Ejemplo n.º 24
0
        public IEnumerable <PageContent> FindPageContentsByPageId(int pageId)
        {
            List <PageContentEntity> entities = PageContents.Where(p => p.Page.Id == pageId).ToList();

            return(FromEntity.ToPageContentList(entities));
        }
Ejemplo n.º 25
0
        public Page GetPageById(int id)
        {
            PageEntity entity = Pages.FirstOrDefault(p => p.Id == id);

            return(FromEntity.ToPage(entity));
        }
Ejemplo n.º 26
0
        public User GetUserByUsernameOrEmail(string username, string email)
        {
            UserEntity entity = Users.FirstOrDefault(x => x.Username == username || x.Email == email);

            return(FromEntity.ToUser(entity));
        }
Ejemplo n.º 27
0
        public IEnumerable <Page> FindPagesModifiedBy(string username)
        {
            List <PageEntity> entities = Pages.Where(p => p.ModifiedBy == username).ToList();

            return(FromEntity.ToPageList(entities));
        }
Ejemplo n.º 28
0
        public IEnumerable <PageContent> AllPageContents()
        {
            List <PageContentEntity> entities = PageContents.ToList();

            return(FromEntity.ToPageContentList(entities));
        }
Ejemplo n.º 29
0
        public IEnumerable <Page> AllPages()
        {
            List <PageEntity> entities = Pages.ToList();

            return(FromEntity.ToPageList(entities));
        }
Ejemplo n.º 30
0
        public IEnumerable <User> FindAllAdmins()
        {
            List <UserEntity> entities = Users.Where(x => x.IsAdmin).ToList();

            return(FromEntity.ToUserList(entities));
        }