Exemple #1
0
        public ActionResultVM SaveRun(Blog.Domain.Run mo)
        {
            var vm = new ActionResultVM();

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

            using (var db = new Blog.Data.ContextBase())
            {
                //add
                if (string.IsNullOrWhiteSpace(mo.RunCode))
                {
                    mo.RunId         = Guid.NewGuid().ToString();
                    mo.RunCreateTime = DateTime.Now;
                    mo.RunStatus     = 1;
                    mo.RunOpen       = 1;
                    mo.Uid           = uinfo.UserId;

                    mo.RunCode = Core.UniqueTo.LongId().ToString();
                    db.Run.Add(mo);
                    int num = db.SaveChanges();

                    vm.Data = mo.RunCode;
                    vm.Set(num > 0);
                }
                else
                {
                    var oldmo = db.Run.FirstOrDefault(x => x.RunCode == mo.RunCode);

                    if (oldmo != null)
                    {
                        if (oldmo.Uid == uinfo.UserId)
                        {
                            oldmo.RunContent1 = mo.RunContent1;
                            oldmo.RunContent2 = mo.RunContent2;
                            oldmo.RunContent3 = mo.RunContent3;
                            oldmo.RunRemark   = mo.RunRemark;
                            oldmo.RunTheme    = mo.RunTheme;

                            db.Run.Update(oldmo);
                            int num = db.SaveChanges();

                            vm.Data = mo.RunCode;
                            vm.Set(num > 0);
                        }
                        else
                        {
                            vm.Set(ARTag.refuse);
                        }
                    }
                    else
                    {
                        vm.Set(ARTag.invalid);
                    }
                }
            }

            return(vm);
        }
Exemple #2
0
        /// <summary>
        /// Gist一条操作
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            string id = RouteData.Values["id"]?.ToString();

            if (string.IsNullOrWhiteSpace(id))
            {
                return(Redirect("/gist"));
            }

            //write js
            bool isjs = id.ToLower().Contains(".js");

            if (isjs)
            {
                id = id.Replace(".js", "");
            }

            //cmd && Auth
            string cmd = RouteData.Values["sid"]?.ToString().ToLower();

            if (User.Identity.IsAuthenticated)
            {
                var uinfo = new Blog.Application.UserAuthService(HttpContext).Get();
                using var db = new Blog.Data.ContextBase();
                switch (cmd)
                {
                case "edit":
                {
                    var mo = db.Gist.Where(x => x.GistCode == id).FirstOrDefault();
                    //有记录且为当前用户
                    if (mo != null && mo.Uid == uinfo.UserId)
                    {
                        return(View("_PartialMonacoEditor", mo));
                    }
                }
                break;

                case "delete":
                {
                    var mo = db.Gist.Where(x => x.GistCode == id && x.Uid == uinfo.UserId).FirstOrDefault();
                    db.Gist.Remove(mo);
                    int num = db.SaveChanges();
                    if (num > 0)
                    {
                        return(Redirect("/gist/user/" + uinfo.UserId));
                    }
                    else
                    {
                        return(Content("Deletion failed or could not be accessed"));
                    }
                }
                }
            }

            using (var db = new Blog.Data.ContextBase())
            {
                var query = from a in db.Gist
                            join b in db.GistSync on a.GistCode equals b.GistCode into bg
                            from b in bg.DefaultIfEmpty()
                            where a.GistCode == id && a.GistStatus == 1 && a.GistOpen == 1
                            select new Blog.Domain.Gist
                {
                    GistId         = a.GistId,
                    Uid            = a.Uid,
                    GistCode       = a.GistCode,
                    GistContent    = a.GistContent,
                    GistCreateTime = a.GistCreateTime,
                    GistUpdateTime = a.GistUpdateTime,
                    GistFilename   = a.GistFilename,
                    GistLanguage   = a.GistLanguage,
                    GistOpen       = a.GistOpen,
                    GistRemark     = a.GistRemark,
                    GistRow        = a.GistRow,
                    GistStatus     = a.GistStatus,
                    GistTags       = a.GistTags,
                    GistTheme      = a.GistTheme,

                    Spare1 = b.GsGitHubId,
                    Spare2 = b.GsGiteeId
                };
                var mo = query.FirstOrDefault();
                if (isjs)
                {
                    return(Content(mo.GistContent));
                }
                else
                {
                    return(View(mo));
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 首页
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="xml"></param>
        /// <param name="mof"></param>
        /// <returns></returns>
        public IActionResult Index(string filename, string xml, Blog.Domain.Draw mof)
        {
            var id  = RouteData.Values["id"]?.ToString();
            var sid = RouteData.Values["sid"]?.ToString();

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

            if (!string.IsNullOrWhiteSpace(filename))
            {
                filename = filename.ToDecode();
            }
            if (!string.IsNullOrWhiteSpace(xml))
            {
                xml = xml.ToDecode();
            }


            //新增
            if (id == "open")
            {
                //编辑
                if (!string.IsNullOrWhiteSpace(sid))
                {
                    var vm = new ActionResultVM();
                    using var db = new Blog.Data.ContextBase();
                    var mo = db.Draw.Find(sid);
                    if (mo?.DrOpen == 1 || mo?.Uid == uinfo.UserId)
                    {
                        vm.Set(ARTag.success);
                        vm.Data = mo;
                    }
                    else
                    {
                        vm.Set(ARTag.unauthorized);
                    }
                    return(Content(vm.ToJson()));
                }
                return(Ok());
            }
            //新增、编辑表单
            else if (id == "form")
            {
                object model = null;
                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    if (!string.IsNullOrWhiteSpace(sid))
                    {
                        using var db = new Blog.Data.ContextBase();
                        var mo = db.Draw.Find(sid);
                        if (mo.Uid == uinfo.UserId)
                        {
                            model = mo;
                        }
                    }
                }

                return(View("_PartialDrawForm", model));
            }
            //保存标题等信息
            else if (id == "saveform")
            {
                var vm = new ActionResultVM();
                if (User.Identity.IsAuthenticated)
                {
                    using var db = new Blog.Data.ContextBase();
                    int num = 0;
                    if (string.IsNullOrWhiteSpace(mof.DrId))
                    {
                        mof.DrId         = mof.DrType[0] + Core.UniqueTo.LongId().ToString();
                        mof.DrCreateTime = DateTime.Now;
                        mof.Uid          = uinfo.UserId;
                        mof.DrOrder      = 100;

                        db.Draw.Add(mof);
                        num = db.SaveChanges();
                    }
                    else
                    {
                        var newmo = db.Draw.Find(mof.DrId);
                        if (newmo.Uid == uinfo.UserId)
                        {
                            newmo.DrRemark = mof.DrRemark;
                            newmo.DrName   = mof.DrName;
                            newmo.DrOpen   = mof.DrOpen;

                            db.Draw.Update(newmo);
                            num = db.SaveChanges();
                        }
                    }
                    vm.Set(num > 0);
                }
                else
                {
                    vm.Set(ARTag.unauthorized);
                }

                if (vm.Code == 200)
                {
                    return(Redirect("/draw/user/" + uinfo?.UserId));
                }
                else
                {
                    return(Content(vm.ToJson()));
                }
            }
            //保存内容
            else if (id == "save")
            {
                var vm = new ActionResultVM();

                if (User.Identity.IsAuthenticated)
                {
                    using var db = new Blog.Data.ContextBase();
                    //新增
                    if (string.IsNullOrWhiteSpace(sid))
                    {
                        var mo = new Blog.Domain.Draw
                        {
                            DrName    = filename,
                            DrContent = xml,

                            DrId         = mof.DrType[0] + Core.UniqueTo.LongId().ToString(),
                            DrType       = mof.DrType,
                            DrCreateTime = DateTime.Now,
                            DrOpen       = 1,
                            DrOrder      = 100,
                            DrStatus     = 1,
                            Uid          = uinfo.UserId
                        };

                        db.Draw.Add(mo);

                        var num = db.SaveChanges();
                        vm.Set(num > 0);
                        vm.Data = mo.DrId;
                    }
                    else
                    {
                        var mo = db.Draw.Find(sid);
                        if (mo?.Uid == uinfo.UserId)
                        {
                            mo.DrName    = filename;
                            mo.DrContent = xml;

                            db.Draw.Update(mo);

                            var num = db.SaveChanges();
                            vm.Set(num > 0);
                        }
                        else
                        {
                            vm.Set(ARTag.unauthorized);
                        }
                    }
                }
                else
                {
                    vm.Code = 1;
                    vm.Msg  = "未登录";
                }

                return(Content(vm.ToJson()));
            }
            //删除
            else if (id == "del")
            {
                var vm = new ActionResultVM();

                if (User.Identity.IsAuthenticated)
                {
                    using var db = new Blog.Data.ContextBase();
                    var mo = db.Draw.Find(sid);
                    if (mo.Uid == uinfo.UserId)
                    {
                        db.Remove(mo);
                        int num = db.SaveChanges();

                        vm.Set(num > 0);
                    }
                    else
                    {
                        vm.Set(ARTag.unauthorized);
                    }
                }
                else
                {
                    vm.Set(ARTag.unauthorized);
                }

                if (vm.Code == 200)
                {
                    return(Redirect("/draw/discover"));
                }
                else
                {
                    return(Content(vm.ToJson()));
                }
            }
            //插入图片
            else if (id == "upload")
            {
                var errno = -1;
                var msg   = "fail";
                var url   = "";

                var vm = new Blog.Web.Controllers.APIController().API98(Request.Form.Files[0], GlobalTo.GetValue("StaticResource:DrawPath"));

                if (vm.Code == 200)
                {
                    var jd = ((JObject)vm.Data);
                    url   = jd["server"].ToString() + jd["path"].ToString();
                    errno = 0;
                    msg   = "ok";
                }

                return(Content(new
                {
                    errno,
                    msg,
                    data = new
                    {
                        url
                    }
                }.ToJson()));
            }

            ViewData["vid"] = id;

            var vname = string.Format("_Partial{0}View", id.StartsWith('m') ? "Mind" : "Draw");

            return(View(vname));
        }
Exemple #4
0
        /// <summary>
        /// Run一条
        /// </summary>
        /// <param name="pure"></param>
        /// <returns></returns>
        public IActionResult Index(string pure)
        {
            string id = RouteData.Values["id"]?.ToString();

            if (string.IsNullOrWhiteSpace(id))
            {
                return(Redirect("/run"));
            }

            //output json
            if (!string.IsNullOrWhiteSpace(id) && id.ToLower().Contains(".json"))
            {
                id           = id.Replace(".json", "");
                using var db = new Blog.Data.ContextBase();
                var mo = db.Run.FirstOrDefault(x => x.RunCode == id && x.RunOpen == 1 && x.RunStatus == 1);
                if (mo != null)
                {
                    return(Content(new
                    {
                        code = mo.RunCode,
                        remark = mo.RunRemark,
                        datetime = mo.RunCreateTime,
                        html = mo.RunContent1,
                        javascript = mo.RunContent2,
                        css = mo.RunContent3
                    }.ToJson()));
                }
            }

            //cmd (Auth)
            string cmd = RouteData.Values["sid"]?.ToString().ToLower();

            switch (cmd)
            {
            case "edit":
            {
                using var db = new Blog.Data.ContextBase();
                var mo = db.Run.FirstOrDefault(x => x.RunCode == id);
                //有记录且为当前用户
                if (mo != null)
                {
                    return(View("_PartialMonacoEditor", mo));
                }
            }
            break;

            case "delete":
            {
                if (User.Identity.IsAuthenticated)
                {
                    using var db = new Blog.Data.ContextBase();
                    var uinfo = new Blog.Application.UserAuthService(HttpContext).Get();
                    var mo    = db.Run.FirstOrDefault(x => x.RunCode == id && x.Uid == uinfo.UserId);
                    db.Run.Remove(mo);
                    int num = db.SaveChanges();
                    if (num > 0)
                    {
                        return(Redirect("/run/user/" + uinfo.UserId));
                    }
                    else
                    {
                        return(Content("Deletion failed or could not be accessed"));
                    }
                }
                else
                {
                    return(Content("Deletion failed or could not be accessed"));
                }
            }
            }

            using (var db = new Blog.Data.ContextBase())
            {
                var mo = db.Run.FirstOrDefault(x => x.RunCode == id && x.RunStatus == 1 && x.RunOpen == 1);
                ViewData["pure"] = pure;
                return(View(mo));
            }
        }
Exemple #5
0
        public ActionResultVM SaveGist(Blog.Domain.Gist mo)
        {
            var vm = new ActionResultVM();

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

            using (var db = new Blog.Data.ContextBase())
            {
                //add
                if (string.IsNullOrWhiteSpace(mo.GistCode))
                {
                    mo.GistId         = Guid.NewGuid().ToString();
                    mo.GistCreateTime = DateTime.Now;
                    mo.GistUpdateTime = mo.GistCreateTime;
                    mo.GistStatus     = 1;
                    mo.Uid            = uinfo.UserId;

                    mo.GistCode = Core.UniqueTo.LongId().ToString();
                    db.Gist.Add(mo);
                    db.SaveChanges();

                    vm.Data = mo.GistCode;
                    vm.Set(ARTag.success);
                }
                else
                {
                    var oldmo = db.Gist.FirstOrDefault(x => x.GistCode == mo.GistCode);
                    if (oldmo != null)
                    {
                        if (oldmo.Uid == uinfo.UserId)
                        {
                            oldmo.GistRemark         = mo.GistRemark;
                            oldmo.GistFilename       = mo.GistFilename;
                            oldmo.GistLanguage       = mo.GistLanguage;
                            oldmo.GistTheme          = mo.GistTheme;
                            oldmo.GistContent        = mo.GistContent;
                            oldmo.GistContentPreview = mo.GistContentPreview;
                            oldmo.GistRow            = mo.GistRow;
                            oldmo.GistOpen           = mo.GistOpen;
                            oldmo.GistUpdateTime     = DateTime.Now;

                            db.Gist.Update(oldmo);
                            db.SaveChanges();

                            vm.Data = mo.GistCode;
                            vm.Set(ARTag.success);
                        }
                        else
                        {
                            vm.Set(ARTag.unauthorized);
                        }
                    }
                    else
                    {
                        vm.Set(ARTag.invalid);
                    }
                }
            }

            return(vm);
        }