Ejemplo n.º 1
0
 public void Delete(int id)
 {
     using (var banco = new ContextBase(_OptionsBuilder.Options))
     {
         var Objeto = banco.Set <T>().Find(id);
         banco.Remove(Objeto);
         banco.SaveChanges();
     };
 }
Ejemplo n.º 2
0
        public ActionResultVM Delete(string id)
        {
            var vm = new ActionResultVM();

            try
            {
                if (string.IsNullOrWhiteSpace(id))
                {
                    vm.Set(ARTag.invalid);
                }
                else
                {
                    var uinfo = new Func.UserAuthAid(HttpContext).Get();
                    if (uinfo.UserId != 0)
                    {
                        using var db = new ContextBase();
                        var mo = db.GuffRecord.Find(id);

                        if (mo == null)
                        {
                            vm.Set(ARTag.invalid);
                        }
                        else
                        {
                            if (mo.Uid != uinfo.UserId)
                            {
                                vm.Set(ARTag.unauthorized);
                            }
                            else if (mo.GrStatus == -1)
                            {
                                vm.Set(ARTag.refuse);
                            }
                            else
                            {
                                db.Remove(mo);
                                int num = db.SaveChanges();

                                vm.Set(num > 0);
                            }
                        }
                    }
                    else
                    {
                        vm.Set(ARTag.unauthorized);
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                Core.ConsoleTo.Log(ex);
            }

            return(vm);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 首页
        /// </summary>
        /// <param name="code">分享码</param>
        /// <param name="filename"></param>
        /// <param name="xml"></param>
        /// <param name="mof"></param>
        /// <returns></returns>
        public IActionResult Index(string code, string filename, string xml, Domain.Draw mof)
        {
            var id  = RouteData.Values["id"]?.ToString();
            var sid = RouteData.Values["sid"]?.ToString();

            var kid = string.Empty;

            if (id?.Length == 20)
            {
                kid = id;
            }
            else if (sid?.Length == 20)
            {
                kid = sid;
            }
            if (!string.IsNullOrEmpty(kid))
            {
                var sck = "SharedCode_" + kid;
                //有分享码
                if (!string.IsNullOrWhiteSpace(code))
                {
                    Response.Cookies.Append(sck, code);
                }
                else
                {
                    code = Request.Cookies[sck]?.ToString();
                }
            }

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

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

            //新增、编辑
            if (id == "open")
            {
                //编辑
                if (!string.IsNullOrWhiteSpace(sid))
                {
                    var vm = new SharedResultVM();
                    var mo = db.Draw.Find(sid);

                    //分享码
                    var isShare = !string.IsNullOrWhiteSpace(mo?.Spare1) && mo?.Spare1 == code;
                    if (mo?.DrOpen == 1 || mo?.Uid == uinfo.UserId || isShare)
                    {
                        vm.Set(SharedEnum.RTag.success);
                        vm.Data = mo;
                    }
                    else
                    {
                        vm.Set(SharedEnum.RTag.unauthorized);
                    }
                    return(Content(vm.ToJson()));
                }
                return(Ok());
            }
            //新增、编辑表单
            else if (id == "form")
            {
                object model = null;
                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    if (!string.IsNullOrWhiteSpace(sid))
                    {
                        var mo = db.Draw.Find(sid);
                        if (mo.Uid == uinfo.UserId)
                        {
                            model = mo;
                        }
                    }
                }

                return(View("_PartialDrawForm", model));
            }
            //保存标题等信息
            else if (id == "saveform")
            {
                var vm = Apps.LoginService.CompleteInfoValid(HttpContext);
                if (vm.Code == 200)
                {
                    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;
                        mof.DrStatus     = 1;

                        db.Draw.Add(mof);
                        num = db.SaveChanges();
                    }
                    else
                    {
                        var newmo = db.Draw.Find(mof.DrId);
                        if (newmo.Uid != uinfo.UserId)
                        {
                            vm.Set(SharedEnum.RTag.unauthorized);
                        }
                        else
                        {
                            newmo.DrRemark = mof.DrRemark;
                            newmo.DrName   = mof.DrName;
                            newmo.DrOpen   = mof.DrOpen;
                            newmo.Spare1   = mof.Spare1;

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

                if (vm.Code == 200)
                {
                    return(Redirect("/draw/user/" + uinfo?.UserId));
                }
                else
                {
                    return(Content(vm.Msg));
                }
            }
            //保存内容
            else if (id == "save")
            {
                var vm = Apps.LoginService.CompleteInfoValid(HttpContext);
                if (vm.Code == 200)
                {
                    //新增
                    if (string.IsNullOrWhiteSpace(sid))
                    {
                        var mo = new 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(SharedEnum.RTag.unauthorized);
                        }
                    }
                }

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

                if (User.Identity.IsAuthenticated)
                {
                    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(SharedEnum.RTag.unauthorized);
                    }
                }
                else
                {
                    vm.Set(SharedEnum.RTag.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 subdir = GlobalTo.GetValue("StaticResource:DrawPath");
                var vm     = new Web.Controllers.api.APIController().Upload(Request.Form.Files[0], subdir);

                if (vm.Code == 200)
                {
                    var jd = vm.Data.ToJson().ToJObject();
                    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));
        }
Ejemplo n.º 4
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.Data.Models.Draw mof)
        {
            var id  = RouteData.Values["id"]?.ToString();
            var sid = RouteData.Values["sid"]?.ToString();

            var uinfo = new UserAuthAid(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 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 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 ContextBase();
                    int num = 0;
                    if (string.IsNullOrWhiteSpace(mof.DrId))
                    {
                        mof.DrId         = mof.DrType[0] + 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 ContextBase();
                    //新增
                    if (string.IsNullOrWhiteSpace(sid))
                    {
                        var mo = new Blog.Data.Models.Draw
                        {
                            DrName    = filename,
                            DrContent = xml,

                            DrId         = mof.DrType[0] + 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 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 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));
        }
Ejemplo n.º 5
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
                {
                    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);
        }