Ejemplo n.º 1
0
        public SharedResultVM SaveGist(Domain.Gist mo)
        {
            var vm = Apps.LoginService.CompleteInfoValid(HttpContext);

            if (vm.Code == 200)
            {
                var uinfo = Apps.LoginService.Get(HttpContext);

                //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(SharedEnum.RTag.success);
                }
                else
                {
                    var oldmo = db.Gist.FirstOrDefault(x => x.GistCode == mo.GistCode);
                    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(SharedEnum.RTag.success);
                    }
                    else
                    {
                        vm.Set(SharedEnum.RTag.fail);
                    }
                }
            }

            return(vm);
        }
Ejemplo n.º 2
0
        public IActionResult SaveGist(Domain.Gist mo)
        {
            string result = "fail";

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

            using (var db = new 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();
                    result = new
                    {
                        code    = mo.GistCode,
                        message = "success"
                    }.ToJson();
                }
                else
                {
                    var oldmo = db.Gist.Where(x => x.GistCode == mo.GistCode).FirstOrDefault();
                    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();
                            result = new
                            {
                                code    = mo.GistCode,
                                message = "success"
                            }.ToJson();
                        }
                        else
                        {
                            result = new
                            {
                                message = "refuse"
                            }.ToJson();
                        }
                    }
                    else
                    {
                        result = new
                        {
                            message = "undefined"
                        }.ToJson();
                    }
                }
            }

            return(Content(result));
        }
Ejemplo n.º 3
0
        public ActionResultVM SaveGist(Domain.Gist mo)
        {
            var vm = new ActionResultVM();

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

            using (var db = new 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.Where(x => x.GistCode == mo.GistCode).FirstOrDefault();
                    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.refuse);
                        }
                    }
                    else
                    {
                        vm.Set(ARTag.invalid);
                    }
                }
            }

            return(vm);
        }