Пример #1
0
        public IActionResult Register(UserInfo mo, string RegisterCode)
        {
            var vm = new ActionResultVM();

            if (string.IsNullOrWhiteSpace(RegisterCode) || HttpContext.Session.GetString("RegisterCode") != RegisterCode)
            {
                vm.msg = "验证码错误或已过期";
            }
            else if (!(mo.UserName?.Length >= 5 && mo.UserPwd?.Length >= 5))
            {
                vm.msg = "账号、密码长度至少 5 位数";
            }
            else
            {
                mo.UserPwd        = CalcTo.MD5(mo.UserPwd);
                mo.UserCreateTime = DateTime.Now;

                //邮箱注册
                if (ParsingTo.IsMail(mo.UserName))
                {
                    mo.UserMail = mo.UserName;
                }
                vm = RegisterUser(mo);
            }

            ViewData["UserName"] = mo.UserName;

            return(View(vm));
        }
Пример #2
0
        public SharedResultVM ReplyAdd([FromForm] Domain.UserReply mo, [FromForm] string id)
        {
            var vm = new SharedResultVM();

            try
            {
                if (string.IsNullOrWhiteSpace(id))
                {
                    vm.Set(SharedEnum.RTag.invalid);
                }
                else if (string.IsNullOrWhiteSpace(mo.UrContent))
                {
                    vm.Set(SharedEnum.RTag.invalid);
                    vm.Msg = "回复内容不能为空";
                }
                else
                {
                    vm = Apps.LoginService.CompleteInfoValid(HttpContext);
                    if (vm.Code == 200)
                    {
                        var uinfo = Apps.LoginService.Get(HttpContext);

                        var guffmo = db.GuffRecord.Find(id);
                        if (guffmo == null)
                        {
                            vm.Set(SharedEnum.RTag.invalid);
                        }
                        else
                        {
                            mo.Uid          = uinfo.UserId;
                            mo.UrTargetType = Application.EnumService.ConnectionType.GuffRecord.ToString();
                            mo.UrTargetId   = id;
                            mo.UrCreateTime = DateTime.Now;
                            mo.UrStatus     = 1;
                            mo.UrTargetPid  = 0;

                            mo.UrAnonymousLink = ParsingTo.JsSafeJoin(mo.UrAnonymousLink);

                            db.UserReply.Add(mo);

                            guffmo.GrReplyNum += 1;
                            db.GuffRecord.Update(guffmo);

                            int num = db.SaveChanges();
                            vm.Set(num > 0);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                Apps.FilterConfigs.WriteLog(HttpContext, ex);
            }

            return(vm);
        }
Пример #3
0
        public ActionResultVM SaveUserInfo(UserInfo mo)
        {
            var vm = new ActionResultVM();

            if (string.IsNullOrWhiteSpace(mo.Nickname))
            {
                vm.Set(ARTag.refuse);
                vm.msg = "昵称不能为空";

                return(vm);
            }

            int uid = new UserAuthAid(HttpContext).Get().UserId;

            using (var db = new ContextBase())
            {
                var usermo = db.UserInfo.Find(uid);

                //变更账号
                if (!string.IsNullOrWhiteSpace(mo.UserName) && usermo.UserNameChange != 1 && usermo.UserName != mo.UserName)
                {
                    //账号重复
                    if (db.UserInfo.Any(x => x.UserName == mo.UserName))
                    {
                        vm.Set(ARTag.exist);
                        vm.msg = "账号已经存在";

                        return(vm);
                    }
                    else
                    {
                        usermo.UserName       = mo.UserName;
                        usermo.UserNameChange = 1;
                    }
                }

                //变更邮箱
                if (mo.UserMail != usermo.UserMail)
                {
                    usermo.UserMailValid = 0;

                    //邮箱正则验证
                    if (!string.IsNullOrWhiteSpace(mo.UserMail))
                    {
                        if (!ParsingTo.IsMail(mo.UserMail))
                        {
                            vm.Set(ARTag.invalid);
                            vm.msg = "邮箱格式有误";

                            return(vm);
                        }
                        else
                        {
                            if (db.UserInfo.Any(x => x.UserMail == mo.UserMail))
                            {
                                vm.Set(ARTag.exist);
                                vm.msg = "邮箱已经存在";

                                return(vm);
                            }
                        }
                    }
                }

                usermo.UserMail  = mo.UserMail;
                usermo.Nickname  = mo.Nickname;
                usermo.UserPhone = mo.UserPhone;
                usermo.UserUrl   = mo.UserUrl;

                db.UserInfo.Update(usermo);
                var num = db.SaveChanges();

                //更新授权信息
                using (var ac = new AccountController())
                {
                    ac.SetAuth(HttpContext, usermo, true);
                }

                vm.Set(num > 0);
            };

            return(vm);
        }
Пример #4
0
        public SharedResultVM LsitReplySave(UserReply mo, UserMessage um)
        {
            var vm = new SharedResultVM();

            vm = Apps.LoginService.CompleteInfoValid(HttpContext);
            if (vm.Code == 200)
            {
                if (!mo.Uid.HasValue || string.IsNullOrWhiteSpace(mo.UrContent) || string.IsNullOrWhiteSpace(mo.UrTargetId))
                {
                    vm.Set(SharedEnum.RTag.lack);
                }
                else
                {
                    var uinfo = Apps.LoginService.Get(HttpContext);
                    mo.Uid = uinfo.UserId;

                    var now = DateTime.Now;

                    //回复消息
                    um.UmId         = UniqueTo.LongId().ToString();
                    um.UmTriggerUid = mo.Uid;
                    um.UmType       = Application.EnumService.MessageType.UserWriting.ToString();
                    um.UmTargetId   = mo.UrTargetId;
                    um.UmAction     = 2;
                    um.UmStatus     = 1;
                    um.UmContent    = mo.UrContent;
                    um.UmCreateTime = now;

                    //回复内容
                    mo.UrCreateTime = now;
                    mo.UrStatus     = 1;
                    mo.UrTargetPid  = 0;
                    mo.UrTargetType = Application.EnumService.ReplyType.UserWriting.ToString();

                    mo.UrAnonymousLink = ParsingTo.JsSafeJoin(mo.UrAnonymousLink);

                    db.UserReply.Add(mo);

                    //回填文章最新回复记录
                    var mow = db.UserWriting.FirstOrDefault(x => x.UwId.ToString() == mo.UrTargetId);
                    if (mow != null)
                    {
                        mow.UwReplyNum += 1;
                        mow.UwLastUid   = mo.Uid;
                        mow.UwLastDate  = now;

                        um.UmTargetIndex = mow.UwReplyNum;

                        db.UserWriting.Update(mow);
                    }

                    if (um.Uid != um.UmTriggerUid)
                    {
                        db.UserMessage.Add(um);
                    }

                    int num = db.SaveChanges();

                    vm.Set(num > 0);
                }
            }

            return(vm);
        }
Пример #5
0
        /// <summary>
        /// 公共登录验证
        /// </summary>
        /// <param name="vt">登录类型</param>
        /// <param name="mo">用户信息</param>
        /// <param name="isremember">记住账号</param>
        /// <returns></returns>
        private ActionResultVM ValidateLogin(ValidateloginType vt, UserInfo mo, bool isremember = true)
        {
            var vm = new ActionResultVM();

            string sql = string.Empty;

            using var db = new ContextBase();
            var      uiR   = db.UserInfo;
            UserInfo outMo = new UserInfo();

            switch (vt)
            {
            case ValidateloginType.local:
                if (string.IsNullOrWhiteSpace(mo.UserName) || string.IsNullOrWhiteSpace(mo.UserPwd))
                {
                    vm.msg = "用户名或密码不能为空";
                    return(vm);
                }
                else
                {
                    mo.UserPwd = CalcTo.MD5(mo.UserPwd);

                    //邮箱登录
                    if (ParsingTo.IsMail(mo.UserName))
                    {
                        outMo = uiR.FirstOrDefault(x => x.UserMail == mo.UserName && x.UserPwd == mo.UserPwd);
                    }
                    else
                    {
                        outMo = uiR.FirstOrDefault(x => x.UserName == mo.UserName && x.UserPwd == mo.UserPwd);
                    }
                }
                break;

            case ValidateloginType.qq:
                outMo = uiR.FirstOrDefault(x => x.OpenId1.Equals(mo.OpenId1));
                break;

            case ValidateloginType.weibo:
                outMo = uiR.FirstOrDefault(x => x.OpenId2.Equals(mo.OpenId2));
                break;

            case ValidateloginType.github:
                outMo = uiR.FirstOrDefault(x => x.OpenId3.Equals(mo.OpenId3));
                break;

            case ValidateloginType.taobao:
                outMo = uiR.FirstOrDefault(x => x.OpenId4.Equals(mo.OpenId4));
                break;

            case ValidateloginType.microsoft:
                outMo = uiR.FirstOrDefault(x => x.OpenId5.Equals(mo.OpenId5));
                break;

            case ValidateloginType.dingtalk:
                outMo = uiR.FirstOrDefault(x => x.OpenId6.Equals(mo.OpenId6));
                break;
            }

            if (outMo == null || outMo.UserId == 0)
            {
                vm.msg = "用户名或密码错误";
                return(vm);
            }

            if (outMo.LoginLimit == 1)
            {
                vm.msg = "用户已被禁止登录";
                return(vm);
            }

            //刷新登录标记
            outMo.UserLoginTime = DateTime.Now;
            outMo.UserSign      = outMo.UserLoginTime.Value.ToTimestamp().ToString();
            uiR.Update(outMo);
            var num = db.SaveChanges();

            if (num < 1)
            {
                vm.msg = "请求登录被拒绝";
                return(vm);
            }

            try
            {
                //登录标记 缓存5分钟,绝对过期
                var usk = "UserSign_" + outMo.UserId;
                CacheTo.Set(usk, outMo.UserSign, 5 * 60, false);

                //写入授权
                SetAuth(HttpContext, outMo, isremember);

                //生成Token
                vm.data = UserAuthAid.TokenMake(outMo);

                vm.Set(ARTag.success);
            }
            catch (Exception ex)
            {
                vm.Set(ex);
            }

            return(vm);
        }
Пример #6
0
        private static SharedResultVM UploadCheck(IFormFile file, byte[] content, string ext, string subdir)
        {
            var vm = new SharedResultVM();

            if (file != null)
            {
                ext = Path.GetExtension(file.FileName);
            }

            if (string.IsNullOrWhiteSpace(ext) || !ext.Contains('.') || ext.EndsWith("exe"))
            {
                vm.Set(SharedEnum.RTag.refuse);
                vm.Msg = "Invalid extension";
            }
            else
            {
                var    now      = DateTime.Now;
                string filename = now.ToString("HHmmss") + RandomTo.NumCode() + ext;

                if (!string.IsNullOrWhiteSpace(subdir) && !ParsingTo.IsLinkPath(subdir))
                {
                    vm.Set(SharedEnum.RTag.invalid);
                    vm.Msg = "subdir 仅为字母、数字";
                }
                else
                {
                    //虚拟路径
                    var vpath = PathTo.Combine(subdir, now.ToString("yyyy'/'MM'/'dd"));
                    //物理根路径
                    var prp = GlobalTo.GetValue("StaticResource:PhysicalRootPath").Replace("~", GlobalTo.ContentRootPath);
                    //物理路径
                    var ppath = PathTo.Combine(prp, vpath);
                    //创建物理目录
                    if (!Directory.Exists(ppath))
                    {
                        Directory.CreateDirectory(ppath);
                    }

                    using var fs = new FileStream(PathTo.Combine(ppath, filename), FileMode.CreateNew);
                    if (file != null)
                    {
                        file.CopyTo(fs);
                    }
                    else
                    {
                        fs.Write(content, 0, content.Length);
                    }
                    fs.Flush();
                    fs.Close();

                    //输出
                    vm.Data = new
                    {
                        server = GlobalTo.GetValue("StaticResource:Server"),
                        path   = PathTo.Combine(vpath, filename)
                    };
                    vm.Set(SharedEnum.RTag.success);
                }
            }

            return(vm);
        }
Пример #7
0
        /// <summary>
        /// 回复
        /// </summary>
        /// <param name="mo">回复信息</param>
        /// <param name="um">消息通知</param>
        /// <returns></returns>
        public ActionResultVM LsitReplySave(UserReply mo, UserMessage um)
        {
            var vm = new ActionResultVM();

            var uinfo = new UserAuthAid(HttpContext).Get();

            if ((uinfo.UserId != 0 && string.IsNullOrWhiteSpace(uinfo.Nickname)) || (uinfo.UserId == 0 && string.IsNullOrWhiteSpace(mo.UrAnonymousName)))
            {
                vm.Set(ARTag.refuse);
                vm.msg = "昵称不能为空";

                return(vm);
            }

            mo.Uid = uinfo.UserId;

            var now = DateTime.Now;

            //回复消息
            um.UmId         = UniqueTo.LongId().ToString();
            um.UmTriggerUid = mo.Uid;
            um.UmType       = EnumAid.MessageType.UserWriting.ToString();
            um.UmTargetId   = mo.UrTargetId;
            um.UmAction     = 2;
            um.UmStatus     = 1;
            um.UmContent    = mo.UrContent;
            um.UmCreateTime = now;

            using (var db = new ContextBase())
            {
                //回复内容
                mo.UrCreateTime = now;
                mo.UrStatus     = 1;
                mo.UrTargetPid  = 0;
                mo.UrTargetType = EnumAid.ReplyType.UserWriting.ToString();

                mo.UrAnonymousLink = ParsingTo.JsSafeJoin(mo.UrAnonymousLink);

                db.UserReply.Add(mo);

                //回填文章最新回复记录
                var mow = db.UserWriting.FirstOrDefault(x => x.UwId.ToString() == mo.UrTargetId);
                if (mow != null)
                {
                    mow.UwReplyNum += 1;
                    mow.UwLastUid   = mo.Uid;
                    mow.UwLastDate  = now;

                    um.UmTargetIndex = mow.UwReplyNum;

                    db.UserWriting.Update(mow);
                }

                if (um.Uid != um.UmTriggerUid)
                {
                    db.UserMessage.Add(um);
                }

                int num = db.SaveChanges();

                vm.Set(num > 0);
            }

            return(vm);
        }
Пример #8
0
        /// <summary>
        /// 公共登录验证
        /// </summary>
        /// <param name="vt">登录类型</param>
        /// <param name="mo">用户信息</param>
        /// <param name="isremember">记住账号</param>
        /// <returns></returns>
        private SharedResultVM ValidateLogin(LoginBase.LoginType?vt, Domain.UserInfo mo, bool isremember = true)
        {
            var vm = new SharedResultVM();

            string sql = string.Empty;

            var uiR = db.UserInfo;

            Domain.UserInfo outMo = new();

            switch (vt)
            {
            case LoginBase.LoginType.QQ:
                outMo = uiR.FirstOrDefault(x => x.OpenId1.Equals(mo.OpenId1));
                break;

            case LoginBase.LoginType.WeiBo:
                outMo = uiR.FirstOrDefault(x => x.OpenId2.Equals(mo.OpenId2));
                break;

            case LoginBase.LoginType.GitHub:
                outMo = uiR.FirstOrDefault(x => x.OpenId3.Equals(mo.OpenId3));
                break;

            case LoginBase.LoginType.TaoBao:
                outMo = uiR.FirstOrDefault(x => x.OpenId4.Equals(mo.OpenId4));
                break;

            case LoginBase.LoginType.MicroSoft:
                outMo = uiR.FirstOrDefault(x => x.OpenId5.Equals(mo.OpenId5));
                break;

            case LoginBase.LoginType.DingTalk:
                outMo = uiR.FirstOrDefault(x => x.OpenId6.Equals(mo.OpenId6));
                break;

            default:
                if (string.IsNullOrWhiteSpace(mo.UserName) || string.IsNullOrWhiteSpace(mo.UserPwd))
                {
                    vm.Msg = "用户名或密码不能为空";
                    return(vm);
                }
                else
                {
                    mo.UserPwd = CalcTo.MD5(mo.UserPwd);

                    //邮箱登录
                    if (ParsingTo.IsMail(mo.UserName))
                    {
                        outMo = uiR.FirstOrDefault(x => x.UserMail == mo.UserName && x.UserPwd == mo.UserPwd);
                    }
                    else
                    {
                        outMo = uiR.FirstOrDefault(x => x.UserName == mo.UserName && x.UserPwd == mo.UserPwd);
                    }
                }
                break;
            }

            if (outMo == null || outMo.UserId == 0)
            {
                vm.Msg = "用户名或密码错误";
                return(vm);
            }

            if (outMo.LoginLimit == 1)
            {
                vm.Msg = "用户已被禁止登录";
                return(vm);
            }

            try
            {
                //刷新登录标记
                outMo.UserLoginTime = DateTime.Now;
                outMo.UserSign      = outMo.UserLoginTime.Value.ToTimestamp().ToString();
                uiR.Update(outMo);
                db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            try
            {
                //登录标记 缓存5分钟,绝对过期
                if (GlobalTo.GetValue <bool>("Common:SingleSignOn"))
                {
                    var usk = "UserSign_" + outMo.UserId;
                    CacheTo.Set(usk, outMo.UserSign, 5 * 60, false);
                }

                //写入授权
                SetAuth(HttpContext, outMo, isremember);

                //生成Token
                vm.Data = Apps.LoginService.TokenMake(outMo);

                vm.Set(SharedEnum.RTag.success);
            }
            catch (Exception ex)
            {
                vm.Set(ex);
            }

            return(vm);
        }
Пример #9
0
        public ActionResultVM ReplyAdd(UserReply mo, string id)
        {
            var vm = new ActionResultVM();

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

                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    mo.Uid = uinfo.UserId;
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(mo.UrAnonymousName) || !ParsingTo.IsMail(mo.UrAnonymousMail))
                    {
                        vm.Set(ARTag.invalid);
                        vm.msg = "昵称、邮箱不能为空";

                        return(vm);
                    }

                    mo.Uid = 0;
                }

                if (string.IsNullOrWhiteSpace(id))
                {
                    vm.Set(ARTag.invalid);
                }
                else if (string.IsNullOrWhiteSpace(mo.UrContent))
                {
                    vm.Set(ARTag.invalid);
                    vm.msg = "回复内容不能为空";
                }
                else
                {
                    using var db = new ContextBase();
                    var guffmo = db.GuffRecord.Find(id);
                    if (guffmo == null)
                    {
                        vm.Set(ARTag.invalid);
                    }
                    else
                    {
                        mo.Uid          = uinfo.UserId;
                        mo.UrTargetType = EnumAid.ConnectionType.GuffRecord.ToString();
                        mo.UrTargetId   = id;
                        mo.UrCreateTime = DateTime.Now;
                        mo.UrStatus     = 1;
                        mo.UrTargetPid  = 0;

                        mo.UrAnonymousLink = ParsingTo.JsSafeJoin(mo.UrAnonymousLink);

                        db.UserReply.Add(mo);

                        guffmo.GrReplyNum += 1;
                        db.GuffRecord.Update(guffmo);

                        int num = db.SaveChanges();
                        vm.Set(num > 0);
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Пример #10
0
        public ActionResultVM Update(GuffRecord mo)
        {
            var vm = new ActionResultVM();

            try
            {
                var uinfo = new UserAuthAid(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 ContextBase();
                    var currMo = db.GuffRecord.Find(mo.GrId);

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

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

                        currMo.GrImage  = ParsingTo.JsSafeJoin(mo.GrImage);
                        currMo.GrAudio  = ParsingTo.JsSafeJoin(mo.GrAudio);
                        currMo.GrVideo  = ParsingTo.JsSafeJoin(mo.GrVideo);
                        currMo.GrFile   = 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);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Пример #11
0
        public ActionResultVM Add(GuffRecord mo)
        {
            var vm = new ActionResultVM();

            try
            {
                var uinfo = new UserAuthAid(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 ContextBase();

                    if (db.UserInfo.Find(uinfo.UserId).UserMailValid != 1)
                    {
                        vm.code = 1;
                        vm.msg  = "请先验证邮箱";
                    }
                    else
                    {
                        var now = DateTime.Now;

                        mo.Uid          = uinfo.UserId;
                        mo.GrId         = UniqueTo.LongId().ToString();
                        mo.GrCreateTime = now;
                        mo.GrUpdateTime = now;
                        mo.GrStatus     = 1;
                        mo.GrReadNum    = 0;
                        mo.GrLaud       = 0;
                        mo.GrMark       = 0;
                        mo.GrReplyNum   = 0;
                        mo.GrOpen ??= 1;

                        mo.GrTypeName  = ParsingTo.JsSafeJoin(mo.GrTypeName);
                        mo.GrTypeValue = ParsingTo.JsSafeJoin(mo.GrTypeValue);
                        mo.GrObject    = ParsingTo.JsSafeJoin(mo.GrObject);
                        mo.GrImage     = ParsingTo.JsSafeJoin(mo.GrImage);
                        mo.GrAudio     = ParsingTo.JsSafeJoin(mo.GrAudio);
                        mo.GrVideo     = ParsingTo.JsSafeJoin(mo.GrVideo);
                        mo.GrFile      = ParsingTo.JsSafeJoin(mo.GrFile);
                        mo.GrTag       = ParsingTo.JsSafeJoin(mo.GrTag);

                        db.GuffRecord.Add(mo);

                        int num = db.SaveChanges();

                        vm.data = mo.GrId;
                        vm.Set(num > 0);
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                ConsoleTo.Log(ex);
            }

            return(vm);
        }
Пример #12
0
        public SharedResultVM Update([FromForm] Domain.GuffRecord mo)
        {
            var vm = new SharedResultVM();

            try
            {
                var uinfo = Apps.LoginService.Get(HttpContext);

                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(SharedEnum.RTag.unauthorized);
                }
                else
                {
                    var currMo = db.GuffRecord.Find(mo.GrId);

                    if (currMo == null)
                    {
                        vm.Set(SharedEnum.RTag.invalid);
                    }
                    else if (currMo.Uid != uinfo.UserId)
                    {
                        vm.Set(SharedEnum.RTag.unauthorized);
                    }
                    else
                    {
                        currMo.GrTypeName  = ParsingTo.JsSafeJoin(mo.GrTypeName);
                        currMo.GrTypeValue = ParsingTo.JsSafeJoin(mo.GrTypeValue);
                        currMo.GrObject    = ParsingTo.JsSafeJoin(mo.GrObject);

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

                        currMo.GrImage  = ParsingTo.JsSafeJoin(mo.GrImage);
                        currMo.GrAudio  = ParsingTo.JsSafeJoin(mo.GrAudio);
                        currMo.GrVideo  = ParsingTo.JsSafeJoin(mo.GrVideo);
                        currMo.GrFile   = 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);
                Apps.FilterConfigs.WriteLog(HttpContext, ex);
            }

            return(vm);
        }
Пример #13
0
        public SharedResultVM Add([FromForm] Domain.GuffRecord mo)
        {
            var vm = new SharedResultVM();

            try
            {
                var uinfo = Apps.LoginService.Get(HttpContext);

                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(SharedEnum.RTag.unauthorized);
                }
                else
                {
                    vm = Apps.LoginService.CompleteInfoValid(HttpContext);
                    if (vm.Code == 200)
                    {
                        var now = DateTime.Now;

                        mo.Uid          = uinfo.UserId;
                        mo.GrId         = UniqueTo.LongId().ToString();
                        mo.GrCreateTime = now;
                        mo.GrUpdateTime = now;
                        mo.GrStatus     = 1;
                        mo.GrReadNum    = 0;
                        mo.GrLaud       = 0;
                        mo.GrMark       = 0;
                        mo.GrReplyNum   = 0;
                        mo.GrOpen ??= 1;

                        mo.GrTypeName  = ParsingTo.JsSafeJoin(mo.GrTypeName);
                        mo.GrTypeValue = ParsingTo.JsSafeJoin(mo.GrTypeValue);
                        mo.GrObject    = ParsingTo.JsSafeJoin(mo.GrObject);
                        mo.GrImage     = ParsingTo.JsSafeJoin(mo.GrImage);
                        mo.GrAudio     = ParsingTo.JsSafeJoin(mo.GrAudio);
                        mo.GrVideo     = ParsingTo.JsSafeJoin(mo.GrVideo);
                        mo.GrFile      = ParsingTo.JsSafeJoin(mo.GrFile);
                        mo.GrTag       = ParsingTo.JsSafeJoin(mo.GrTag);

                        db.GuffRecord.Add(mo);

                        int num = db.SaveChanges();

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

            return(vm);
        }