public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var refer_id = UMC.Data.Utility.Guid(this.AsyncDialog("Refer", g =>
            {
                return(new Web.UITextDialog()
                {
                    Title = "评论的主题"
                });
            }));

            var user = UMC.Security.Identity.Current;

            var Id = UMC.Data.Utility.Guid(this.AsyncDialog("Id", g =>
            {
                return(this.DialogValue(Guid.NewGuid().ToString()));
            })).Value;

            var commentEntity = Utility.CMS.ObjectEntity <UMC.Data.Entities.Comment>()
                                .Where.And().In(new Comment {
                Id = refer_id
            }, Id).Entities;
            var commant = commentEntity.Single();

            var ui      = this.AsyncDialog("UI", g => this.DialogValue("none"));
            var section = this.AsyncDialog("section", g => this.DialogValue("1"));
            var row     = this.AsyncDialog("row", g => this.DialogValue("1"));

            var Content = Web.UIDialog.AsyncDialog("Content", g =>
            {
                var from = new Web.UIFormDialog();
                if (commant != null)
                {
                    from.Title = "回复评论";
                }
                else
                {
                    from.Title = "评论";
                }
                if (request.IsApp)
                {
                    var sn = new WebMeta(request.Arguments);
                    sn.Put("Id", Id).Put("Refer", refer_id);
                    var ms = new WebMeta().Put("submit", new UIClick(sn)
                    {
                        Text = commant != null ? "请回复" : "请评论"
                    }.Send(request.Model, request.Command));

                    this.Context.Send(commant == null ? "Comment" : "Reply", ms, true);
                }
                from.AddTextarea("内容", "Content", String.Empty).Put("MinSize", "6");

                if (commant == null)
                {
                    from.AddFiles("图片上传", "Picture").Put("required", "none")
                    .Command("Design", "Picture", new UMC.Web.WebMeta().Put("id", Id));
                }

                from.Submit(commant != null ? "确认回复" : "确认评论", request, "UI.Event");
                return(from);
            });
            var image = this.AsyncDialog("image", "none");

            if (image != "none")
            {
                var webr = UMC.Data.WebResource.Instance();
                var imgs = image.Split(',');
                var ls   = new List <Picture>();
                for (var i = 0; i < imgs.Length; i++)
                {
                    webr.Transfer(new Uri(imgs[i]), Id, i + 1);
                    ls.Add(new Picture {
                        group_id = Id, Seq = i + 1, UploadDate = DateTime.Now, user_id = user.Id
                    });
                }
                if (ls.Count > 0)
                {
                    var entity = UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Picture>();

                    entity.Where.And().Equal(new UMC.Data.Entities.Picture {
                        group_id = Id
                    }).Entities.Delete();
                    entity.Insert(ls.ToArray());
                }
            }
            if (commant != null)
            {
                if (commant.Id == Id)
                {
                    return;
                }
                var forId = commant.for_id ?? Guid.Empty;
                if (forId == Guid.Empty)
                {
                    forId = commant.Id.Value;
                }
                var entity = Utility.CMS.ObjectEntity <Subject>()
                             .Where.And().Equal(new Subject {
                    Id = commant.ref_id
                }).Entities;
                var sinle = entity.Single(new Subject {
                    Reply = 0, project_id = Guid.Empty
                });
                if (sinle != null)
                {
                    if (sinle.Reply.HasValue)
                    {
                        entity.Update("{0}+{1}", new Subject {
                            Reply = 1
                        });
                    }
                    else
                    {
                        entity.Update(new Subject {
                            Reply = 1
                        });
                    }
                }

                commentEntity.Insert(new Comment
                {
                    Id          = Id,
                    CommentDate = DateTime.Now,
                    for_id      = forId,
                    ref_id      = commant.ref_id,
                    Content     = Content,
                    Effective   = 0,
                    Farworks    = 0,
                    Invalid     = 0,
                    project_id  = sinle != null ? sinle.project_id : null,
                    Reply       = 0,
                    Score       = 0,
                    Unhealthy   = 0,
                    Visible     = 0,
                    Poster      = user.Alias,
                    user_id     = user.Id
                });
                var cm = Utility.CMS.ObjectEntity <UMC.Data.Entities.Comment>()
                         .Where.And().Equal(new Data.Entities.Comment {
                    Id = commant.Id
                })
                         .Entities.Single();
                var editer = new Web.UISection.Editer(section, row);
                editer.Put((Utility.Comment(cm, request.Model)), false);
                editer.Builder(this.Context, ui, true);
            }
            else
            {
                var entity = Utility.CMS.ObjectEntity <UMC.Data.Entities.Subject>()
                             .Where.And().Equal(new Subject {
                    Id = refer_id
                }).Entities;
                var sinle = entity.Single(new Subject {
                    Reply = 0, project_id = Guid.Empty
                });
                commentEntity.Insert(new Comment
                {
                    Id          = Id,
                    CommentDate = DateTime.Now,
                    for_id      = Guid.Empty,
                    ref_id      = refer_id,
                    project_id  = sinle != null ? sinle.project_id : null,
                    Content     = Content,
                    Effective   = 0,
                    Farworks    = 0,
                    Invalid     = 0,
                    Reply       = 0,
                    Score       = 0,
                    Unhealthy   = 0,
                    Visible     = 0,
                    Poster      = user.Alias,
                    user_id     = user.Id
                });
                if (sinle != null)
                {
                    if (sinle.Reply.HasValue)
                    {
                        entity.Update("{0}+{1}", new Subject {
                            Reply = 1
                        });
                    }
                    else
                    {
                        entity.Update(new Subject {
                            Reply = 1
                        });
                    }


                    var editer = new Web.UISection.Editer(1, 1);
                    var cm     = Utility.CMS.ObjectEntity <UMC.Data.Entities.Comment>()
                                 .Where.And().Equal(new Data.Entities.Comment {
                        Id = Id, for_id = Guid.Empty
                    })
                                 .Entities.Single();

                    if (commentEntity.Where.Reset().And().Equal(new Comment {
                        ref_id = refer_id, for_id = Guid.Empty
                    }).And().Greater(new Comment
                    {
                        Visible = -1
                    }).Entities.Count() == 1)
                    {
                        editer.Put(Utility.Comment(cm, request.Model), false);
                    }
                    else
                    {
                        editer.Insert(Utility.Comment(cm, request.Model));
                    }

                    editer.Builder(this.Context, ui, true);
                }
            }
        }
Exemple #2
0
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var model = request.Model;
            var proid = UMC.Data.Utility.Guid(this.AsyncDialog("Id", g => this.DialogValue(request.Url.ToString())));

            if (proid.HasValue == false)
            {
                this.Prompt("参数不正确");
            }
            var subEntity = Utility.CMS.ObjectEntity <UMC.Data.Entities.Subject>();

            var sub = subEntity.Where.And().Equal(new Subject {
                Id = proid
            }).Entities.Single();

            if (sub == null)
            {
                this.Prompt("参数不正确");
            }
            var Type = this.AsyncDialog("Type", g =>
            {
                //return this.DialogValue("auto");
                var sheet = new Web.UISheetDialog()
                {
                    Title = "更多"
                };                                                    //屏蔽
                sheet.Options.Add(new Web.UIClick("Id", proid.ToString(), "Type", "Share")
                {
                    Command = request.Command, Model = model, Text = "分享到应用"
                });
                //sheet.Options.Add(new Web.UIClick("Id", proid.ToString(), "Type", "0") { Command = request.Command, Model = model, Text = "屏蔽此作者" });
                //sheet.Options.Add(new Web.UIClick("Id", proid.ToString(), "Type", "1") { Command = request.Command, Model = model, Text = "屏蔽此项目" });
                sheet.Options.Add(new Web.UIClick("Id", proid.ToString(), "Type", "Off")
                {
                    Command = request.Command, Model = model, Text = "举报内容"
                });
                return(sheet);
            });
            var user = Security.Identity.Current;

            switch (Type)
            {
            case "Off":
                var frm = this.AsyncDialog("Settings", g =>
                {
                    var fm   = new UIFormDialog();
                    fm.Title = "举报";
                    fm.AddRadio("违规性质", "Type").Put("内容质量差").Put("旧闻重复").Put("内容不实").Put("标题夸张").Put("低俗色情")
                    .Put("其他问题").Put("侵犯名誉/商誉/隐私/肖像权");
                    fm.AddFile("证明材料", "Url", "");
                    fm.AddTextarea("举报描述", "Description", "");
                    return(fm);
                });
                var url = new Uri(frm["Url"]);

                var s = "UserResources/TipOff" + url.AbsolutePath.Substring(url.AbsolutePath.IndexOf('/', 2));    //
                Data.WebResource.Instance().Transfer(url, s);
                var t = new SubjectTipOff();
                Data.Reflection.SetProperty(t, frm.GetDictionary());
                t.user_id      = user.Id;
                t.Url          = Data.WebResource.Instance().ResolveUrl(s);
                t.sub_id       = sub.Id;
                t.CreationTime = DateTime.Now;
                Utility.CMS.ObjectEntity <SubjectTipOff>().Where.And().Equal(new SubjectTipOff {
                    user_id = user.Id, sub_id = sub.Id
                })
                .Entities.IFF(e => e.Update(t) == 0, e => e.Insert(t));
                if (sub.TipOffs.HasValue)
                {
                    subEntity.Update("{0}+{1}", new Subject {
                        TipOffs = 1
                    });
                }
                else
                {
                    subEntity.Update(new Subject {
                        TipOffs = 1
                    });
                }
                this.Prompt("举报成功,我们将尽快处理");
                break;

            case "Share":
                response.Redirect(request.Model, "Share", proid.ToString());
                break;

            default:
            case "Block":

                var ui      = this.AsyncDialog("UI", g => this.DialogValue("none"));
                var section = this.AsyncDialog("section", g => this.DialogValue("1"));
                var row     = this.AsyncDialog("row", g => this.DialogValue("1"));
                var frm2    = Utility.IntParse(this.AsyncDialog("Settings", g =>
                {
                    if (Utility.IntParse(Type, -1) > -1)
                    {
                        return(this.DialogValue(Type));
                    }
                    var fm   = new UISelectDialog();
                    fm.Title = "屏蔽";
                    fm.Options.Put("屏蔽此作者", "0").Put("屏蔽此项目", "1");
                    return(fm);
                }), 0);
                var block = new ProjectBlock {
                    user_id = user.Id, ref_id = sub.user_id, Type = frm2
                };
                switch (frm2)
                {
                case 0:
                    block.ref_id = sub.user_id;
                    break;

                case 1:
                    block.ref_id = sub.project_id;
                    break;
                }
                if (block.ref_id.HasValue)
                {
                    Utility.CMS.ObjectEntity <ProjectBlock>().Where.And().Equal(block)
                    .Entities.IFF(e => e.Count() == 0, e => e.Insert(block));
                }
                if (ui == "none")
                {
                    this.Prompt("屏蔽成功");
                }
                else
                {
                    var editer = new Web.UISection.Editer(section, row, ui);
                    editer.Delete();
                    editer.ReloadSinle();
                    editer.Builder(this.Context, ui, true);
                }
                break;
            }
        }