Пример #1
0
        public APIReturn Post_insert([FromForm] ulong?Last_posts_id, [FromForm] ulong?Owner_users_id, [FromForm] int?Count_posts, [FromForm] uint?Count_views, [FromForm] string Title, [FromForm] ulong?Top, [FromForm] uint[] mn_Tags, [FromForm] ulong[] mn_Users)
        {
            TopicsInfo item = new TopicsInfo();

            item.Last_posts_id  = Last_posts_id;
            item.Owner_users_id = Owner_users_id;
            item.Count_posts    = Count_posts;
            item.Count_views    = Count_views;
            item.Create_time    = DateTime.Now;
            item.Title          = Title;
            item.Top            = Top;
            item.Update_time    = DateTime.Now;
            item = Topics.Insert(item);
            //关联 Tags
            foreach (uint mn_Tags_in in mn_Tags)
            {
                item.FlagTags(mn_Tags_in);
            }
            //关联 Users
            foreach (ulong mn_Users_in in mn_Users)
            {
                item.FlagUsers(mn_Users_in);
            }
            return(new APIReturn(0, "成功", "item", item.ToBson()));
        }
Пример #2
0
        public APIReturn Put_update(ulong?Id, [FromForm] ulong?Last_posts_id, [FromForm] ulong?Owner_users_id, [FromForm] int?Count_posts, [FromForm] uint?Count_views, [FromForm] string Title, [FromForm] ulong?Top, [FromForm] uint[] mn_Tags, [FromForm] ulong[] mn_Users)
        {
            TopicsInfo item = new TopicsInfo();

            item.Id             = Id;
            item.Last_posts_id  = Last_posts_id;
            item.Owner_users_id = Owner_users_id;
            item.Count_posts    = Count_posts;
            item.Count_views    = Count_views;
            item.Create_time    = DateTime.Now;
            item.Title          = Title;
            item.Top            = Top;
            item.Update_time    = DateTime.Now;
            int affrows = Topics.Update(item);

            //关联 Tags
            if (mn_Tags.Length == 0)
            {
                item.UnflagTagsALL();
            }
            else
            {
                List <uint> mn_Tags_list = mn_Tags.ToList();
                foreach (TagsInfo Obj_tags in item.Obj_tagss)
                {
                    int idx = mn_Tags_list.FindIndex(a => a == Obj_tags.Id);
                    if (idx == -1)
                    {
                        item.UnflagTags(Obj_tags.Id);
                    }
                    else
                    {
                        mn_Tags_list.RemoveAt(idx);
                    }
                }
                mn_Tags_list.ForEach(a => item.FlagTags(a));
            }
            //关联 Users
            if (mn_Users.Length == 0)
            {
                item.UnflagUsersALL();
            }
            else
            {
                List <ulong> mn_Users_list = mn_Users.ToList();
                foreach (UsersInfo Obj_users in item.Obj_userss)
                {
                    int idx = mn_Users_list.FindIndex(a => a == Obj_users.Id);
                    if (idx == -1)
                    {
                        item.UnflagUsers(Obj_users.Id);
                    }
                    else
                    {
                        mn_Users_list.RemoveAt(idx);
                    }
                }
                mn_Users_list.ForEach(a => item.FlagUsers(a));
            }
            if (affrows > 0)
            {
                return(new APIReturn(0, "成功"));
            }
            return(new APIReturn(99, "失败"));
        }