Пример #1
0
        public override void InsertWorkWikiItem(IWorkWikiItem item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            WikiDataContext db = new WikiDataContext(
                ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<LinqWorkWikiItem> wikis = db.GetTable<LinqWorkWikiItem>();

            wikis.InsertOnSubmit(new LinqWorkWikiItem()
            {
                Action = (int)item.Action,
                ApplicationName = this.ApplicationName,
                Author = item.Author,
                Authorizer = item.Authorizer,
                Category = item.Category,
                Content = item.Content,
                DateCreated = item.DateCreated,
                DepartmentArea = item.DepartmentArea,
                Description = item.Description,
                Editable = item.Editable,
                Editor = item.Editor,
                ExpirationDate = item.ExpirationDate,
                ID = item.ID,
                IpAddress = item.IPAddress,
                IsVisible = item.IsVisible,
                Keywords = item.Keywords,
                LastUpdated = item.LastUpdated,
                LastUpdatedBy = item.LastUpdatedBy,
                Messages = item.Messages,
                ReachLevel = (int)item.ReachLevel,
                Slug = item.Slug,
                Status = (int)item.Status,
                Title = item.Title,
                TrackingNumber = item.TrackingNumber
            });

            try
            {
                db.SubmitChanges(ConflictMode.ContinueOnConflict);
            }
            catch (ChangeConflictException ex)
            {
                Trace.TraceWarning(ex.Message);

                // All database values overwrite current values.
                foreach (ObjectChangeConflict occ in db.ChangeConflicts)
                    occ.Resolve(RefreshMode.OverwriteCurrentValues);
            }
            catch (DbException ex)
            {
                Trace.TraceError(ex.Message);
                return;
            }
        }
Пример #2
0
        public override List<Guid> GetWorkWikiItem(Guid? trackingNumber, Guid? id, string title, string description,
            string content, string author, string slug, bool? isVisible, string category, string keywords, ReachLevel? level, 
            DateTime? initialDateCreated, DateTime? finalDateCreated, DateTime? initialLastUpdated, DateTime? finalLastUpdated, 
            DateTime? initialExpirationDate, DateTime? finalExpirationDate, string lastUpdatedBy, 
            int pageSize, int pageIndex, out int totalCount)
        {
            List<Guid> records = new List<Guid>();

            WikiDataContext db = new WikiDataContext(
                ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<LinqWorkWikiItem> workitems = db.GetTable<LinqWorkWikiItem>();

            var query = from w in workitems
                        where w.ApplicationName == this.ApplicationName
                        where w.Author.Contains(!string.IsNullOrEmpty(author) ? author : string.Empty)
                        where w.Category.Contains(!string.IsNullOrEmpty(category) ? category : string.Empty)
                        where w.Content.Contains(!string.IsNullOrEmpty(content) ? content : string.Empty)
                        where w.DateCreated >= (initialDateCreated.HasValue && initialDateCreated != DateTime.MinValue ? initialDateCreated : w.DateCreated)
                        where w.DateCreated <= (finalDateCreated.HasValue && finalDateCreated != DateTime.MinValue ? finalDateCreated : w.DateCreated)
                        where (description != null && w.Description != null ? w.Description : string.Empty) == (description != null ? description : string.Empty)
                        where initialExpirationDate != null && w.ExpirationDate >= (initialExpirationDate.HasValue && initialExpirationDate != DateTime.MinValue ? initialExpirationDate.Value : w.ExpirationDate)
                        where finalExpirationDate != null && w.ExpirationDate <= (finalExpirationDate.HasValue && finalExpirationDate != DateTime.MinValue ? finalExpirationDate.Value : w.ExpirationDate)
                        where w.ID == (id.HasValue && id != Guid.Empty ? id : w.ID)
                        where w.IsVisible == (isVisible.HasValue ? isVisible : w.IsVisible)
                        where (keywords != null && w.Keywords != null ? w.Keywords : string.Empty) == (keywords != null ? keywords : string.Empty)
                        where w.LastUpdated >= (initialLastUpdated.HasValue && initialLastUpdated != DateTime.MinValue ? initialLastUpdated : w.LastUpdated)
                        where w.LastUpdated <= (finalLastUpdated.HasValue && finalLastUpdated != DateTime.MinValue ? finalLastUpdated : w.LastUpdated)
                        where (lastUpdatedBy != null && w.LastUpdatedBy != null ? w.LastUpdatedBy : string.Empty) == (lastUpdatedBy != null ? lastUpdatedBy : string.Empty)
                        where (ReachLevel)w.ReachLevel == (level.HasValue ? level : (ReachLevel)w.ReachLevel)
                        where w.Slug.Contains(!string.IsNullOrEmpty(slug) ? slug : string.Empty)
                        where w.Title.Contains(!string.IsNullOrEmpty(title) ? title : string.Empty)
                        where w.TrackingNumber == (trackingNumber.HasValue ? trackingNumber : w.TrackingNumber)
                        select w.TrackingNumber;

            totalCount = query.Count();

            foreach (Guid workitemId in query.Skip(pageSize * pageIndex).Take(pageSize))
                records.Add(workitemId);

            return records;
        }
Пример #3
0
        public override void InsertCategory(string category)
        {
            WikiDataContext db = new WikiDataContext(
                ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<WikiCategory> categories = db.GetTable<WikiCategory>();

            categories.InsertOnSubmit(new WikiCategory() { ApplicationName = this.ApplicationName, CategoryName = category });

            try
            {
                db.SubmitChanges(ConflictMode.ContinueOnConflict);
            }
            catch (ChangeConflictException ex)
            {
                Trace.TraceWarning(ex.Message);

                // All database values overwrite current values.
                foreach (ObjectChangeConflict occ in db.ChangeConflicts)
                    occ.Resolve(RefreshMode.OverwriteCurrentValues);
            }
            catch (DbException ex)
            {
                Trace.TraceError(ex.Message);
                return;
            }
        }
Пример #4
0
        public override List<IWorkWikiItem> GetPendingAuthorizations(string user, int pageSize, int pageIndex, out int totalCount)
        {
            List<IWorkWikiItem> pending = new List<IWorkWikiItem>();

            WikiDataContext db = new WikiDataContext(
                ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<LinqWorkWikiItem> workitems = db.GetTable<LinqWorkWikiItem>();

            var query = from w in workitems
                        where w.ApplicationName == this.ApplicationName
                        where w.Status == (int)WikiStatus.AuthorizationRequested
                        select w;

            totalCount = query.Count();

            foreach (LinqWorkWikiItem item in query.Skip(pageSize * pageIndex).Take(pageSize))
            {
                pending.Add(new WorkWikiItem(new Wiki(item.ID)
            {
                Author = item.Author,
                Category = item.Category,
                Content = item.Content,
                DateCreated = item.DateCreated,
                DepartmentArea = item.DepartmentArea,
                Description = item.Description,
                Editable = item.Editable,
                Editor = item.Editor,
                IsVisible = item.IsVisible,
                Keywords = item.Keywords,
                LastUpdated = item.LastUpdated,
                LastUpdatedBy = item.LastUpdatedBy,
                ReachLevel = (ReachLevel)item.ReachLevel,
                Slug = item.Slug,
                Title = item.Title,
            })
            {
                Action = (SaveAction)item.Action,
                Authorizer = item.Authorizer,
                ExpirationDate = item.ExpirationDate,
                IPAddress = item.IpAddress,
                Messages = item.Messages,
                Status = (WikiStatus)item.Status,
                TrackingNumber = item.TrackingNumber
            });
            }

            return pending;
        }
Пример #5
0
        public override IWiki GetRelatedWiki(string keyword)
        {
            WikiDataContext db = new WikiDataContext(
                ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            var query = db.GetRelatedWiki(this.ApplicationName, keyword);

            GetRelatedWikiResult result = query.SingleOrDefault();

            if (result == null)
                return null;

            return SelectWiki(result.id);
        }
Пример #6
0
        public override Dictionary<string, string> GetAuthorizersByCategory(int pageSize, int pageIndex, out int totalCount)
        {
            Dictionary<string, string> authorizers = new Dictionary<string, string>();

            WikiDataContext db = new WikiDataContext(
                ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<WikiAuthorizer> categories = db.GetTable<WikiAuthorizer>();

            var query = from c in categories
                        where c.ApplicationName == this.ApplicationName
                        select c;

            totalCount = query.Count();

            foreach (WikiAuthorizer authorizer in query.Skip(pageIndex * pageSize).Take(pageSize))
                authorizers.Add(authorizer.Category, authorizer.UserName);

            return authorizers;
        }
Пример #7
0
        public override List<string> GetCategories()
        {
            List<string> categories = new List<string>();

            WikiDataContext db = new WikiDataContext(
                ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<WikiCategory> wikiCategories = db.GetTable<WikiCategory>();

            var query = from c in wikiCategories
                        where c.ApplicationName == this.ApplicationName
                        select c;

            foreach (WikiCategory item in query)
            {
                categories.Add(item.ApplicationName);
            }

            return categories;
        }
Пример #8
0
        public override void DeleteWorkWikiItem(IWorkWikiItem item)
        {
            WikiDataContext db = new WikiDataContext(
                ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<LinqWorkWikiItem> wikis = db.GetTable<LinqWorkWikiItem>();

            // BusinessBase inherited clases will have a downside effect with a ChangeConflictException
            // as it has changed LastUpdated row version in the call stack.
            IWiki wi = SelectWorkWikiItem(item.TrackingNumber);

            // BusinessBase inherited clases will have a downside effect with a ChangeConflictException
            // as it has changed LastUpdated row version in the call stack.
            LinqWorkWikiItem w = new LinqWorkWikiItem()
            {
                Action = (int)item.Action,
                ApplicationName = this.ApplicationName,
                Author = item.Author,
                Authorizer = item.Authorizer,
                Category = item.Category,
                Content = item.Content,
                DateCreated = item.DateCreated,
                DepartmentArea = item.DepartmentArea,
                Description = item.Description,
                Editable = item.Editable,
                Editor = item.Editor,
                ExpirationDate = item.ExpirationDate,
                ID = item.ID,
                IpAddress = item.IPAddress,
                IsVisible = item.IsVisible,
                Keywords = item.Keywords,
                LastUpdated = wi.LastUpdated,
                LastUpdatedBy = item.LastUpdatedBy,
                Messages = item.Messages,
                ReachLevel = (int)item.ReachLevel,
                Slug = item.Slug,
                Status = (int)item.Status,
                Title = item.Title,
                TrackingNumber = item.TrackingNumber
            };

            // Assume that "wiki" has been sent by client.
            // Attach with "true" to the change tracker to consider the entity modified
            // and it can be checked for optimistic concurrency because
            // it has a column that is marked with "RowVersion" attribute
            wikis.Attach(w);

            wikis.DeleteOnSubmit(w);

            try
            {
                db.SubmitChanges(ConflictMode.ContinueOnConflict);
            }
            catch (ChangeConflictException ex)
            {
                Trace.TraceError(ex.Message);

                // All database values overwrite current values.
                foreach (ObjectChangeConflict occ in db.ChangeConflicts)
                    occ.Resolve(RefreshMode.OverwriteCurrentValues);
            }
            catch (DbException ex)
            {
                Trace.TraceError(ex.Message);
            }
        }
Пример #9
0
        public override IWorkWikiItem SelectWorkWikiItem(Guid id)
        {
            WorkWikiItem wiki = null;

            WikiDataContext db = new WikiDataContext(
                ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<LinqWorkWikiItem> wikis = db.GetTable<LinqWorkWikiItem>();

            LinqWorkWikiItem row = wikis.SingleOrDefault<LinqWorkWikiItem>(
                w => w.ApplicationName == this.ApplicationName && w.TrackingNumber == id);

            if (row == null)
                return null;

            wiki = new WorkWikiItem(new Wiki(row.ID)
            {
                Author = row.Author,
                Category = row.Category,
                Content = row.Content,
                DateCreated = row.DateCreated,
                DepartmentArea = row.DepartmentArea,
                Description = row.Description,
                Editable = row.Editable,
                Editor = row.Editor,
                IsVisible = row.IsVisible,
                Keywords = row.Keywords,
                LastUpdated = row.LastUpdated,
                LastUpdatedBy = row.LastUpdatedBy,
                ReachLevel = (ReachLevel)row.ReachLevel,
                Slug = row.Slug,
                Title = row.Title,
            })
            {
                Action = (SaveAction)row.Action,
                Authorizer = row.Authorizer,
                ExpirationDate = row.ExpirationDate,
                IPAddress = row.IpAddress,
                Messages = row.Messages,
                Status = (WikiStatus)row.Status,
                TrackingNumber = row.TrackingNumber
            };

            return wiki;
        }
Пример #10
0
        public override IWiki SelectWiki(Guid id)
        {
            Wiki wiki = null;

            WikiDataContext db = new WikiDataContext(
                ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<LinqWiki> wikis = db.GetTable<LinqWiki>();

            LinqWiki row = wikis.SingleOrDefault<LinqWiki>(
                w => w.ApplicationName == this.ApplicationName && w.ID == id);

            if (row == null)
                return null;

            wiki = new Wiki(row.ID)
            {
                Author = row.Author,
                Category = row.Category,
                Content = row.Content,
                DateCreated = row.DateCreated,
                DepartmentArea = row.DepartmentArea,
                Description = row.Description,
                Editable = row.Editable,
                Editor = row.Editor,
                IsVisible = row.IsVisible,
                Keywords = row.Keywords,
                LastUpdated = row.LastUpdated,
                LastUpdatedBy = row.LastUpdatedBy,
                ReachLevel = (ReachLevel)row.ReachLevel,
                Slug = row.Slug,
                Title = row.Title
            };

            return wiki;
        }
Пример #11
0
        public override List<Guid> SearchWiki(string alphabeticalIndex, int pageSize, int pageIndex, out int totalCount)
        {
            List<Guid> records = new List<Guid>();

            WikiDataContext db = new WikiDataContext(
                ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<LinqWiki> wikis = db.GetTable<LinqWiki>();

            var query = (
                        from w in wikis
                        where w.ApplicationName == this.ApplicationName
                        where w.Keywords.StartsWith(alphabeticalIndex)
                        select w.ID
                        ).Union(
                        from w in wikis
                        where w.ApplicationName == this.ApplicationName
                        where w.Title.StartsWith(alphabeticalIndex)
                        select w.ID
                        );

            totalCount = query.Count();

            foreach (Guid id in query)
            {
                records.Add(id);
            }

            return records;
        }
Пример #12
0
        public override List<Guid> SearchWiki(string title, string description, string content, string author,
            string slug, bool? isVisible, string category, string keywords, ReachLevel? level, 
            DateTime? initialDateCreated, DateTime? finalDateCreated, DateTime? initialLastUpdated, DateTime? finalLastUpdated, 
            string lastUpdatedBy, int pageSize, int pageIndex, out int totalCount)
        {
            List<Guid> records = new List<Guid>();

            WikiDataContext db = new WikiDataContext(
                ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<LinqWiki> wikis = db.GetTable<LinqWiki>();

            var q0 = (from w in wikis
                      where w.ApplicationName == this.ApplicationName
                      select new SearchWikiResult()
                      {
                          ID = Guid.Empty,
                          Author = w.Author,
                          IsVisible = w.IsVisible,
                          DateCreated = w.DateCreated,
                          ReachLevel = (ReachLevel)w.ReachLevel,
                          LastUpdated = w.LastUpdated,
                          LastUpdatedBy = w.LastUpdatedBy,
                          Rate = 10
                      }).Distinct();

            var q1 = from w in wikis
                     where w.ApplicationName == this.ApplicationName
                     where w.Slug.Contains(slug)
                     select new SearchWikiResult()
                     {
                         ID = w.ID,
                         Author = w.Author,
                         IsVisible = w.IsVisible,
                         DateCreated = w.DateCreated,
                         ReachLevel = (ReachLevel)w.ReachLevel,
                         LastUpdated = w.LastUpdated,
                         LastUpdatedBy = w.LastUpdatedBy,
                         Rate = 100
                     };

            var q2 = from w in wikis
                     where w.ApplicationName == this.ApplicationName
                     where w.Title.Contains(title)
                     select new SearchWikiResult()
                     {
                         ID = w.ID,
                         Author = w.Author,
                         IsVisible = w.IsVisible,
                         DateCreated = w.DateCreated,
                         ReachLevel = (ReachLevel)w.ReachLevel,
                         LastUpdated = w.LastUpdated,
                         LastUpdatedBy = w.LastUpdatedBy,
                         Rate = 90
                     };

            var q3 = from w in wikis
                     where w.ApplicationName == this.ApplicationName
                     where w.Keywords.Contains(keywords)
                     select new SearchWikiResult()
                     {
                         ID = w.ID,
                         Author = w.Author,
                         IsVisible = w.IsVisible,
                         DateCreated = w.DateCreated,
                         ReachLevel = (ReachLevel)w.ReachLevel,
                         LastUpdated = w.LastUpdated,
                         LastUpdatedBy = w.LastUpdatedBy,
                         Rate = 80
                     };

            var q4 = from w in wikis
                     where w.ApplicationName == this.ApplicationName
                     where w.Category.Contains(category)
                     select new SearchWikiResult()
                     {
                         ID = w.ID,
                         Author = w.Author,
                         IsVisible = w.IsVisible,
                         DateCreated = w.DateCreated,
                         ReachLevel = (ReachLevel)w.ReachLevel,
                         LastUpdated = w.LastUpdated,
                         LastUpdatedBy = w.LastUpdatedBy,
                         Rate = 70
                     };

            var q5 = from w in wikis
                     where w.ApplicationName == this.ApplicationName
                     where w.Description.Contains(description)
                     select new SearchWikiResult()
                     {
                         ID = w.ID,
                         Author = w.Author,
                         IsVisible = w.IsVisible,
                         DateCreated = w.DateCreated,
                         ReachLevel = (ReachLevel)w.ReachLevel,
                         LastUpdated = w.LastUpdated,
                         LastUpdatedBy = w.LastUpdatedBy,
                         Rate = 60
                     };

            var q6 = from w in wikis
                     where w.ApplicationName == this.ApplicationName
                     where w.Content.Contains(content)
                     select new SearchWikiResult()
                     {
                         ID = w.ID,
                         Author = w.Author,
                         IsVisible = w.IsVisible,
                         DateCreated = w.DateCreated,
                         ReachLevel = (ReachLevel)w.ReachLevel,
                         LastUpdated = w.LastUpdated,
                         LastUpdatedBy = w.LastUpdatedBy,
                         Rate = 50
                     };

            var q7 = q0;

            if (!string.IsNullOrEmpty(slug))
                q7 = q0.Union(q1);

            if (!string.IsNullOrEmpty(title))
                q7 = q7.Union(q2);

            if (!string.IsNullOrEmpty(keywords))
                q7 = q7.Union(q3);

            if (!string.IsNullOrEmpty(category))
                q7 = q7.Union(q4);

            if (!string.IsNullOrEmpty(description))
                q7 = q7.Union(q5);

            if (!string.IsNullOrEmpty(content))
                q7 = q7.Union(q6);

            var query = (from w in q7
                        where w.ID != Guid.Empty
                        where w.IsVisible == (isVisible.HasValue ? isVisible : w.IsVisible)
                        where w.DateCreated >= (initialDateCreated.HasValue && initialDateCreated != DateTime.MinValue ? initialDateCreated : w.DateCreated)
                        where w.DateCreated <= (finalDateCreated.HasValue && finalDateCreated != DateTime.MinValue ? finalDateCreated : w.DateCreated)
                        where (ReachLevel)w.ReachLevel >= (level.HasValue ? level : (ReachLevel)w.ReachLevel)
                        where w.LastUpdated >= (initialLastUpdated.HasValue && initialLastUpdated != DateTime.MinValue ? initialLastUpdated : w.LastUpdated)
                        where w.LastUpdated <= (finalLastUpdated.HasValue && finalLastUpdated != DateTime.MinValue ? finalLastUpdated : w.LastUpdated)
                        where (lastUpdatedBy != null && w.LastUpdatedBy != null ? w.LastUpdatedBy : string.Empty) == (lastUpdatedBy != null ? lastUpdatedBy : string.Empty)
                        orderby w.Rate descending
                        select w.ID
                        ).Distinct();

            totalCount = query.Count();

            foreach (Guid id in query.Skip(pageSize * pageIndex).Take(pageSize))
                records.Add(id);

            return records;
        }