示例#1
0
        //Adds new Report to Reports Table
        public Task <Reports> AddReportPost(int postId, int userId, string comment)
        {
            FilterDefinition <Reports> filter = GetPostIdFilter(postId);

            Report[] reportArray = new Report[] { new Report()
                                                  {
                                                      UserId  = userId,
                                                      Comment = comment
                                                  } };
            Reports reports = new Reports()
            {
                PostId       = postId,
                ReportsArray = reportArray,
                IsResolved   = false
            };

            bool isEntityPresent = db.Reports.CheckAndCreateEntityBool(reports, filter);

            if (isEntityPresent)
            {
                Report[] initialReports = db.Reports.Find(filter).FirstOrDefault().ReportsArray;

                Task <Reports> updateTask = MongoArrayUtils <Reports> .AddToArrayWithCount <Report>(db.Reports, filter, REPORTS_ARRAY, reportArray, initialReports, COUNT);

                return(updateTask);
            }
            return(null);
        }
        //Add bookmarks to Bookmarks Table
        public Task <Bookmarks> AddBookmarks(int userId, params int[] postIds)
        {
            Bookmarks bookmark = new Bookmarks()
            {
                UserId  = userId,
                PostIds = postIds
            };
            FilterDefinition <Bookmarks> filter = GetUserIdFilter(userId);

            bool isEntityPresent = db.Bookmarks.CheckAndCreateEntityBool(bookmark, filter);

            if (isEntityPresent)
            {
                int[] initialValues = db.Bookmarks.Find(filter).FirstOrDefault().PostIds;

                Task <Bookmarks> updateTask = MongoArrayUtils <Bookmarks> .AddToArrayWithCount(db.Bookmarks, filter, POST_IDS, postIds, initialValues, COUNT);
            }
            return(null);
        }