• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Models.whoaverseEntities类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Voat.Models.whoaverseEntities的典型用法代码示例。如果您正苦于以下问题:C# whoaverseEntities类的具体用法?C# whoaverseEntities怎么用?C# whoaverseEntities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



whoaverseEntities类属于Voat.Models命名空间,在下文中一共展示了whoaverseEntities类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SendPrivateMessage

        // a method to send a private message to a user, invoked by other methods
        public static bool SendPrivateMessage(string sender, string recipient, string subject, string body)
        {
            using (var db = new whoaverseEntities())
            {
                try
                {
                    var privateMessage = new Privatemessage
                    {
                        Sender = sender,
                        Recipient = recipient,
                        Timestamp = DateTime.Now,
                        Subject = subject,
                        Body = body,
                        Status = true,
                        Markedasunread = true
                    };

                    db.Privatemessages.Add(privateMessage);
                    db.SaveChanges();

                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }
开发者ID:SamHH,项目名称:voat,代码行数:29,代码来源:MesssagingUtility.cs


示例2: PullsDefaultFrontpage

            public void PullsDefaultFrontpage(whoaverseEntities db, Defaultsubverse defaultsubverse, List<Message> messages)
            {
                // Arrange
                // TODO: See if we can coax Autofixture into handling this for us
                if (defaultsubverse.name.Length > 20)
                    defaultsubverse.name = defaultsubverse.name.Substring(0, 19);
                db.Defaultsubverses.Add(defaultsubverse);
                db.Subverses.Add(new Subverse {name = defaultsubverse.name, title = new Guid().ToString()});
                db.SaveChanges();

                foreach (var message in messages)
                {
                    // TODO: See if we can coax Autofixture into handling this for us
                    if (message.Thumbnail.Length > 40)
                        message.Thumbnail = message.Thumbnail.Substring(0, 39);
                    message.Subverse = defaultsubverse.name;
                }
                db.Messages.AddRange(messages);
                db.SaveChanges();

                var homeController = new HomeController(db);
                homeController.ControllerContext = GetControllerContext(false);

                // Act
                var actionResult = (ViewResult) homeController.Index(null);
                var model = (PaginatedList<Message>) actionResult.Model;

                // Assert
                Assert.True(model.Count == messages.Count);
            }
开发者ID:bob3695,项目名称:voat,代码行数:30,代码来源:HomeControllerTest.cs


示例3: CheckIfSavedComment

 // returns true if saved, false otherwise
 public static bool? CheckIfSavedComment(string userToCheck, int commentId)
 {
     using (var db = new whoaverseEntities())
     {
         return db.Commentsavingtrackers.Where(b => b.CommentId == commentId && b.UserName == userToCheck).AsNoTracking().Any();
     }
 }
开发者ID:blakar,项目名称:voat,代码行数:8,代码来源:SavingComments.cs


示例4: BadgeInfo

        public ApiBadge BadgeInfo(string badgeId)
        {
            ApiBadge badgeInfo = CacheHandler.Register<ApiBadge>(String.Format("LegacyApi.ApiBadge.{0}", badgeId),
             new Func<ApiBadge>(() =>
             {
                 using (whoaverseEntities db = new whoaverseEntities(CONSTANTS.CONNECTION_READONLY))
                 {
                     var badge = _db.Badges.Find(badgeId);

                     if (badge == null)
                     {
                         throw new HttpResponseException(HttpStatusCode.NotFound);
                     }

                     var resultModel = new ApiBadge
                     {
                         BadgeId = badge.BadgeId,
                         BadgeGraphics = badge.BadgeGraphics,
                         Name = badge.BadgeName,
                         Title = badge.BadgeTitle
                     };

                     return resultModel;
                 }
             }), TimeSpan.FromHours(5));
            return badgeInfo;
        }
开发者ID:mwizard,项目名称:voat,代码行数:27,代码来源:WebApiController.cs


示例5: SaveComment

        // a user wishes to save a comment, save it
        public static void SaveComment(int commentId, string userWhichSaved)
        {
            var result = CheckIfSavedComment(userWhichSaved, commentId);

            using (var db = new whoaverseEntities())
            {
                if (result == true)
                {
                    // Already saved, unsave
                    UnSaveComment(userWhichSaved, commentId);
                }
                else
                {
                    // register save
                    var tmpSavingTracker = new Commentsavingtracker
                    {
                        CommentId = commentId,
                        UserName = userWhichSaved,
                        Timestamp = DateTime.Now
                    };
                    db.Commentsavingtrackers.Add(tmpSavingTracker);
                    db.SaveChanges();
                }
            }
        }
开发者ID:mwizard,项目名称:voat,代码行数:26,代码来源:SavingComments.cs


示例6: CheckIfSaved

 // returns true if saved, false otherwise
 public static bool? CheckIfSaved(string userToCheck, int messageId)
 {
     using (var db = new whoaverseEntities())
     {
         return db.Savingtrackers.Where(u => u.UserName == userToCheck && u.MessageId == messageId).AsNoTracking().Any();
     }
 }
开发者ID:blakar,项目名称:voat,代码行数:8,代码来源:Saving.cs


示例7: CheckIfSavedComment

        // returns true if saved, false otherwise
        public static bool? CheckIfSavedComment(string userToCheck, int commentId)
        {
            using (whoaverseEntities db = new whoaverseEntities())
            {

                var cmd = db.Database.Connection.CreateCommand();
                cmd.CommandText = "SELECT COUNT(*) FROM Commentsavingtracker WITH (NOLOCK) WHERE UserName = @UserName AND CommentId = @CommentId";

                var param = cmd.CreateParameter();
                param.ParameterName = "UserName";
                param.DbType = System.Data.DbType.String;
                param.Value = userToCheck;
                cmd.Parameters.Add(param);

                param = cmd.CreateParameter();
                param.ParameterName = "CommentId";
                param.DbType = System.Data.DbType.String;
                param.Value = commentId;
                cmd.Parameters.Add(param);

                if (cmd.Connection.State != System.Data.ConnectionState.Open)
                {
                    cmd.Connection.Open();
                }

                int count = (int)cmd.ExecuteScalar();

                return count > 0;
            }

            //using (var db = new whoaverseEntities())
            //{
            //    return db.Commentsavingtrackers.Where(b => b.CommentId == commentId && b.UserName == userToCheck).AsNoTracking().Any();
            //}
        }
开发者ID:mwizard,项目名称:voat,代码行数:36,代码来源:SavingComments.cs


示例8: SaveSubmission

        // a user wishes to save a submission, save it
        public static void SaveSubmission(int submissionId, string userWhichSaved)
        {
            var result = CheckIfSaved(userWhichSaved, submissionId);

            using (var db = new whoaverseEntities())
            {
                if (result == true)
                {
                    // Already saved, unsave
                    UnSaveSubmission(userWhichSaved, submissionId);
                }
                else
                {
                    // register save
                    var tmpSavingTracker = new Savingtracker
                    {
                        MessageId = submissionId,
                        UserName = userWhichSaved,
                        Timestamp = DateTime.Now
                    };
                    db.Savingtrackers.Add(tmpSavingTracker);
                    db.SaveChanges();
                }
            }
        }
开发者ID:blakar,项目名称:voat,代码行数:26,代码来源:Saving.cs


示例9: CustomCssDisabledForUser

 // check if a given user does not want to see custom CSS styles
 public static bool CustomCssDisabledForUser(string userName)
 {
     using (var db = new whoaverseEntities())
     {
         var result = db.Userpreferences.Find(userName);
         return result != null && result.Disable_custom_css;
     }
 }
开发者ID:seanfreiburg,项目名称:voat,代码行数:9,代码来源:User.cs


示例10: AdultContentEnabled

 // check if a given user wants to see NSFW (adult) content
 public static bool AdultContentEnabled(string userName)
 {
     using (var db = new whoaverseEntities())
     {
         var result = db.Userpreferences.Find(userName);
         return result != null && result.Enable_adult_content;
     }
 }
开发者ID:seanfreiburg,项目名称:voat,代码行数:9,代码来源:User.cs


示例11: CommentRepliesCount

 // get total number of comment replies for a given user
 public static int CommentRepliesCount(string userName)
 {
     using (var db = new whoaverseEntities())
     {
         var commentReplies = db.Commentreplynotifications.Where(s => s.Recipient.Equals(userName, StringComparison.OrdinalIgnoreCase));
         if (!commentReplies.Any()) return 0;
         return commentReplies.Any() ? commentReplies.Count() : 0;
     }
 }
开发者ID:seanfreiburg,项目名称:voat,代码行数:10,代码来源:User.cs


示例12: UnSaveComment

        // a user has saved this comment earlier and wishes to unsave it, delete the record
        private static void UnSaveComment(string userWhichSaved, int commentId)
        {
            using (var db = new whoaverseEntities())
            {
                var votingTracker = db.Commentsavingtrackers.FirstOrDefault(b => b.CommentId == commentId && b.UserName == userWhichSaved);

                if (votingTracker == null) return;
                // delete vote history
                db.Commentsavingtrackers.Remove(votingTracker);
                db.SaveChanges();
            }
        }
开发者ID:blakar,项目名称:voat,代码行数:13,代码来源:SavingComments.cs


示例13: UnSaveSubmission

        // a user has saved this submission earlier and wishes to unsave it, delete the record
        private static void UnSaveSubmission(string userWhichSaved, int messageId)
        {
            using (var db = new whoaverseEntities())
            {
                var saveTracker = db.Savingtrackers.FirstOrDefault(b => b.MessageId == messageId && b.UserName == userWhichSaved);

                if (saveTracker == null) return;
                //delete vote history
                db.Savingtrackers.Remove(saveTracker);
                db.SaveChanges();
            }
        }
开发者ID:blakar,项目名称:voat,代码行数:13,代码来源:Saving.cs


示例14: CheckIfVoted

        // returns -1:downvoted, 1:upvoted, 0:not voted
        public static int CheckIfVoted(string userToCheck, int messageId)
        {
            using (var db = new whoaverseEntities())
            {
                var checkResult = db.Votingtrackers.Where(u => u.UserName == userToCheck && u.MessageId == messageId)
                        .AsNoTracking()
                        .FirstOrDefault();

                int intCheckResult = checkResult != null ? checkResult.VoteStatus.Value : 0;
                return intCheckResult;
            }
        }
开发者ID:blakar,项目名称:voat,代码行数:13,代码来源:Voting.cs


示例15: CheckIfVotedComment

        // returns -1:downvoted, 1:upvoted, or 0:not voted
        public static int CheckIfVotedComment(string userToCheck, int commentId)
        {
            int intCheckResult = 0;

            using (var db = new whoaverseEntities())
            {
                var checkResult = db.Commentvotingtrackers.FirstOrDefault(b => b.CommentId == commentId && b.UserName == userToCheck);

                intCheckResult = checkResult != null ? checkResult.VoteStatus.Value : 0;

                return intCheckResult;
            }
        }
开发者ID:blakar,项目名称:voat,代码行数:14,代码来源:VotingComments.cs


示例16: BannedHostnames

 public IEnumerable<string> BannedHostnames()
 {
     IEnumerable<string> bannedSubs = CacheHandler.Register<IEnumerable<string>>("LegacyApi.BannedHostnames",
       new Func<IList<string>>(() =>
       {
           using (whoaverseEntities db = new whoaverseEntities(CONSTANTS.CONNECTION_READONLY))
           {
               var bannedHostnames = db.Banneddomains.OrderBy(s => s.Added_on).ToList();
               return bannedHostnames.Select(item => "Hostname: " + item.Hostname + ", reason: " + item.Reason + ", added on: " + item.Added_on + ", added by: " + item.Added_by).ToList();
           }
       }), TimeSpan.FromHours(12));
     return bannedSubs;
 }
开发者ID:mwizard,项目名称:voat,代码行数:13,代码来源:WebApiController.cs


示例17: CommentKarma

        // get comment contribution points for a user
        public static int CommentKarma(string userName)
        {
            string cacheKey = CacheKey(userName, KarmaCacheType.Comment);

            object cacheData = Cache[cacheKey];
            if (cacheData != null)
            {
                return (int)cacheData;
            }

            int count = 0;
            using (whoaverseEntities db = new whoaverseEntities())
            {

                var cmd = db.Database.Connection.CreateCommand();
                cmd.CommandText = "SELECT ISNULL(SUM(Likes - Dislikes), 0) FROM Comments WITH (NOLOCK) WHERE Name = @Name";

                var param = cmd.CreateParameter();
                param.ParameterName = "Name";
                param.DbType = System.Data.DbType.String;
                param.Value = userName;
                cmd.Parameters.Add(param);

                if (cmd.Connection.State != System.Data.ConnectionState.Open)
                {
                    cmd.Connection.Open();
                }
                long l = (long)cmd.ExecuteScalar();
                count = (int)l;
                Cache.Insert(cacheKey, count, null, DateTime.Now.AddSeconds(cacheTimeInSeconds), System.Web.Caching.Cache.NoSlidingExpiration);

            }

            return count;

            //using (var db = new whoaverseEntities())
            //{
            //    try
            //    {
            //        return db.Comments.Where(c => c.Name.Trim().Equals(userName, StringComparison.OrdinalIgnoreCase))
            //            .Select(c => c.Likes - c.Dislikes)
            //            .Sum();
            //    }
            //    catch (Exception)
            //    {
            //        return 0;
            //    }
            //}
        }
开发者ID:blakar,项目名称:voat,代码行数:50,代码来源:Karma.cs


示例18: IsHostnameBanned

        public static bool IsHostnameBanned(string hostnameToCheck)
        {
            using (var db = new whoaverseEntities())
            {
                var bannedHostname = db.Banneddomains.FirstOrDefault(r => r.Hostname.Equals(hostnameToCheck, StringComparison.OrdinalIgnoreCase));

                // manual ban for blogspot
                if (hostnameToCheck.Contains("blogspot"))
                {
                    return true;
                }

                // look for exact match
                return bannedHostname != null;
            }
        }
开发者ID:blakar,项目名称:voat,代码行数:16,代码来源:BanningUtility.cs


示例19: MarkPrivateMessagesAsRead

        // a method to mark single or all private messages as read for a given user
        public static async Task<bool> MarkPrivateMessagesAsRead(bool? markAll, string userName, int? itemId)
        {
            using (var db = new whoaverseEntities())
            {
                try
                {
                    // mark all items as read
                    if (markAll != null && (bool) markAll)
                    {
                        IQueryable<Privatemessage> unreadPrivateMessages = db.Privatemessages
                                                                            .Where(s => s.Recipient.Equals(userName, StringComparison.OrdinalIgnoreCase) && s.Status)
                                                                            .OrderByDescending(s => s.Timestamp)
                                                                            .ThenBy(s => s.Sender);

                        if (!unreadPrivateMessages.Any()) return false;

                        foreach (var singleMessage in unreadPrivateMessages.ToList())
                        {
                            singleMessage.Status = false;
                        }
                        await db.SaveChangesAsync();
                        return true;
                    }

                    // mark single item as read
                    if (itemId != null)
                    {
                        var privateMessageToMarkAsread = db.Privatemessages.FirstOrDefault(s => s.Recipient.Equals(userName, StringComparison.OrdinalIgnoreCase) && s.Status && s.Id == itemId);
                        if (privateMessageToMarkAsread == null) return false;

                        var item = db.Privatemessages.Find(itemId);
                        item.Status = false;
                        await db.SaveChangesAsync();
                        return true;
                    }
                    return false;
                }
                catch (Exception)
                {
                    return false;
                }
            }

        }
开发者ID:SamHH,项目名称:voat,代码行数:45,代码来源:MesssagingUtility.cs


示例20: Retrieve

        public static Subverse Retrieve(string subverse)
        {
            if (!String.IsNullOrEmpty(subverse)) {
                string cacheKey = CacheHandler.Keys.SubverseInfo(subverse);

                Subverse sub = (Subverse)CacheHandler.Retrieve(cacheKey);
                if (sub == null) {
                    sub = (Subverse)CacheHandler.Register(cacheKey, new Func<object>(() => {

                        using (whoaverseEntities db = new whoaverseEntities()) {
                            return db.Subverses.Where(x => x.name == subverse).FirstOrDefault();
                        }

                    }), TimeSpan.FromMinutes(5), 50);
                }
                return sub;
            }
            return null;
        }
开发者ID:mwizard,项目名称:voat,代码行数:19,代码来源:SubverseCache.cs



注:本文中的Voat.Models.whoaverseEntities类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Draw.SColorF类代码示例发布时间:2022-05-26
下一篇:
C# Models.voatEntities类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap