Exemple #1
0
        public ActionResultVM Connection(string type, int ac, string id)
        {
            var vm = new ActionResultVM();

            try
            {
                var uinfo = new Application.UserAuthService(HttpContext).Get();

                if (uinfo.UserId == 0)
                {
                    vm.Set(ARTag.unauthorized);
                }
                else if (string.IsNullOrWhiteSpace(id))
                {
                    vm.Set(ARTag.invalid);
                }
                else if (!new List <string> {
                    "add", "cancel"
                }.Contains(type))
                {
                    vm.Set(ARTag.invalid);
                }
                else if (!new List <int> {
                    1, 2
                }.Contains(ac))
                {
                    vm.Set(ARTag.invalid);
                }
                else
                {
                    using var db = new Data.ContextBase();
                    var currMo = db.GuffRecord.Find(id);

                    if (currMo == null)
                    {
                        vm.Set(ARTag.invalid);
                    }
                    else
                    {
                        var ctype = Application.EnumService.ConnectionType.GuffRecord.ToString();
                        switch (type)
                        {
                        case "add":
                        {
                            if (db.UserConnection.Any(x => x.Uid == uinfo.UserId && x.UconnTargetType == ctype && x.UconnTargetId == id && x.UconnAction == ac))
                            {
                                vm.Set(ARTag.exist);
                            }
                            else
                            {
                                //关联记录
                                var ucmo = new Domain.UserConnection()
                                {
                                    UconnId         = Core.UniqueTo.LongId().ToString(),
                                    Uid             = uinfo.UserId,
                                    UconnTargetType = Application.EnumService.ConnectionType.GuffRecord.ToString(),
                                    UconnTargetId   = id,
                                    UconnAction     = ac,
                                    UconnCreateTime = DateTime.Now
                                };

                                db.Add(ucmo);

                                switch (ac)
                                {
                                case 1:
                                    currMo.GrLaud += 1;
                                    break;

                                case 2:
                                    currMo.GrMark += 1;
                                    break;
                                }
                                db.Update(currMo);

                                int num = db.SaveChanges();

                                vm.Set(num > 0);
                            }
                        }
                        break;

                        case "cancel":
                        {
                            var curruc = db.UserConnection.FirstOrDefault(x => x.Uid == uinfo.UserId && x.UconnTargetType == ctype && x.UconnTargetId == id && x.UconnAction == ac);
                            if (curruc == null)
                            {
                                vm.Set(ARTag.invalid);
                            }
                            else
                            {
                                db.Remove(curruc);

                                switch (ac)
                                {
                                case 1:
                                    currMo.GrLaud -= 1;
                                    break;

                                case 2:
                                    currMo.GrMark -= 1;
                                    break;
                                }
                                db.Update(currMo);

                                int num = db.SaveChanges();

                                vm.Set(num > 0);
                            }
                        }
                        break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                Filters.FilterConfigs.WriteLog(HttpContext, ex);
            }

            return(vm);
        }
Exemple #2
0
        public ActionResultVM Detail(string id)
        {
            var vm = new ActionResultVM();

            try
            {
                if (string.IsNullOrWhiteSpace(id))
                {
                    vm.Set(ARTag.invalid);
                }
                else
                {
                    var ctype = Application.EnumService.ConnectionType.GuffRecord.ToString();

                    var uinfo = new Application.UserAuthService(HttpContext).Get();

                    using var db = new Data.ContextBase();
                    var query = from a in db.GuffRecord
                                join b in db.UserInfo on a.Uid equals b.UserId
                                join c in db.UserConnection.Where(x => x.UconnTargetType == ctype && x.UconnAction == 1 && x.Uid == uinfo.UserId) on a.GrId equals c.UconnTargetId into cg
                                from c1 in cg.DefaultIfEmpty()
                                where a.GrId == id
                                select new
                    {
                        a,
                        c1.UconnTargetId,
                        b.Nickname
                    };
                    var qm = query.FirstOrDefault();
                    if (qm == null)
                    {
                        vm.Set(ARTag.invalid);
                    }
                    else
                    {
                        if (qm.a.GrOpen == 1 || uinfo.UserId == qm.a.Uid)
                        {
                            // 阅读 +1
                            qm.a.GrReadNum += 1;
                            db.Update(qm.a);
                            db.SaveChanges();

                            qm.a.Spare1 = string.IsNullOrEmpty(qm.UconnTargetId) ? "" : "laud";
                            qm.a.Spare2 = (uinfo.UserId == qm.a.Uid) ? "owner" : "";
                            qm.a.Spare3 = qm.Nickname;

                            vm.Data = qm.a;

                            vm.Set(ARTag.success);
                        }
                        else
                        {
                            vm.Set(ARTag.unauthorized);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                Filters.FilterConfigs.WriteLog(HttpContext, ex);
            }

            return(vm);
        }
Exemple #3
0
        public ActionResultVM Update(Domain.GuffRecord mo)
        {
            var vm = new ActionResultVM();

            try
            {
                var uinfo = new Application.UserAuthService(HttpContext).Get();

                if (string.IsNullOrWhiteSpace(mo.GrContent) && string.IsNullOrWhiteSpace(mo.GrImage) && string.IsNullOrWhiteSpace(mo.GrAudio) && string.IsNullOrWhiteSpace(mo.GrVideo))
                {
                    vm.Code = 1;
                    vm.Msg  = "内容不能为空(内容、图片、音频、视频 至少有一项有内容)";
                }
                else if (string.IsNullOrWhiteSpace(mo.GrTag))
                {
                    vm.Code = 2;
                    vm.Msg  = "标签不能为空";
                }
                else if (uinfo.UserId == 0)
                {
                    vm.Set(ARTag.unauthorized);
                }
                else
                {
                    using var db = new Data.ContextBase();
                    var currMo = db.GuffRecord.Find(mo.GrId);

                    if (currMo == null)
                    {
                        vm.Set(ARTag.invalid);
                    }
                    else
                    {
                        currMo.GrTypeName  = Fast.ParsingTo.JsSafeJoin(mo.GrTypeName);
                        currMo.GrTypeValue = Fast.ParsingTo.JsSafeJoin(mo.GrTypeValue);
                        currMo.GrObject    = Fast.ParsingTo.JsSafeJoin(mo.GrObject);

                        currMo.GrContent   = mo.GrContent;
                        currMo.GrContentMd = mo.GrContentMd;

                        currMo.GrImage  = Fast.ParsingTo.JsSafeJoin(mo.GrImage);
                        currMo.GrAudio  = Fast.ParsingTo.JsSafeJoin(mo.GrAudio);
                        currMo.GrVideo  = Fast.ParsingTo.JsSafeJoin(mo.GrVideo);
                        currMo.GrFile   = Fast.ParsingTo.JsSafeJoin(mo.GrFile);
                        currMo.GrRemark = mo.GrRemark;

                        currMo.GrTag        = mo.GrTag;
                        currMo.GrUpdateTime = DateTime.Now;
                        currMo.GrOpen       = mo.GrOpen ?? 1;

                        db.Update(currMo);

                        int num = db.SaveChanges();

                        vm.Data = mo.GrId;
                        vm.Set(num > 0);
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                Filters.FilterConfigs.WriteLog(HttpContext, ex);
            }

            return(vm);
        }