Example #1
0
        public object Post(JArray data)
        {
            using (var db = new SysContext())
            {
                for (int i = 0; i < data.Count; i++)
                {
                    JObject       obj       = data[i] as JObject;
                    RowState      rowState  = (RowState)(int)obj["_row_state"];
                    sys_parameter parameter = obj.ToObject <sys_parameter>();
                    switch (rowState)
                    {
                    case RowState.Changed:
                        db.Entry(parameter).State = System.Data.Entity.EntityState.Modified;
                        break;

                    case RowState.New:
                        db.sys_parameter.Add(parameter);
                        break;

                    case RowState.Deleted:
                        db.Entry(parameter).State = System.Data.Entity.EntityState.Deleted;
                        break;
                    }
                }
                db.SaveChanges();
            }
            return(true);
        }
Example #2
0
        public object Post(JArray data)
        {
            using (var db = new SysContext())
            {
                for (int i = 0; i < data.Count; i++)
                {
                    JObject  obj      = data[i] as JObject;
                    RowState rowState = (RowState)(int)obj["_row_state"];
                    sys_code code     = obj.ToObject <sys_code>();
                    switch (rowState)
                    {
                    case RowState.Changed:
                        db.Entry(code).State = System.Data.Entity.EntityState.Modified;
                        break;

                    case RowState.New:
                        db.sys_code.Add(code);
                        break;

                    case RowState.Deleted:
                        db.Entry(code).State = System.Data.Entity.EntityState.Deleted;
                        break;
                    }
                }

                // 记录操作日志
                db.sys_log.Add(new sys_log
                {
                    UserCode = User.Identity.Name,
                    UserName = User.Identity.GetUserInfo().UserName,
                    Position = Request.RequestUri.PathAndQuery,
                    Target   = "字典分类数据",
                    Type     = "修改",
                    Message  = data.ToString(),
                    Date     = DateTime.Now,
                });
                db.SaveChanges();
            }
            return(true);
        }
Example #3
0
        public ActionResult SearchScheme(string pageCode, string method = "list")
        {
            var    user   = System.Web.HttpContext.Current.Session["sys_user"] as sys_user;
            var    sss    = new SysSerialServices();
            object result = null;

            using (var db = new SysContext())
            {
                switch (method)
                {
                case "list":
                    if (user == null)
                    {
                        result = db.sys_searchScheme.Where(s => s.PageCode == pageCode).OrderBy(s => s.Title).Select(s => new {
                            s.Id,
                            s.Title,
                            s.Data,
                            deleable = false
                        }).ToList();
                    }
                    else
                    {
                        result = db.sys_searchScheme.Where(s => s.PageCode == pageCode && (s.CompCode == null || s.CompCode == user.CompCode)).OrderBy(s => s.Title).Select(s => new {
                            s.Id,
                            s.Title,
                            s.Data,
                            deleable = s.CompCode == user.CompCode && s.UserCode == user.UserCode
                        }).ToList();
                    }
                    break;

                case "add":
                    if (user != null)
                    {
                        var ss = new sys_searchScheme
                        {
                            Id       = sss.GetNewSerial(db, "sys_searchScheme"),
                            CompCode = user.CompCode,
                            UserCode = user.UserCode,
                            PageCode = pageCode,
                            Title    = Request["title"],
                            Data     = Request["data"]
                        };
                        db.sys_searchScheme.Add(ss);
                        db.SaveChanges();
                        result = new { ss.Id, ss.Title, ss.Data, deleable = true };
                    }
                    break;

                case "del":
                    if (user != null)
                    {
                        var ss = db.sys_searchScheme.Find(int.Parse(Request["id"]));
                        if (ss != null && ss.CompCode == user.CompCode && ss.UserCode == user.UserCode)
                        {
                            db.Entry(ss).State = EntityState.Deleted;
                            db.SaveChanges();
                            result = true;
                        }
                    }
                    break;
                }
            }
            return(new JsonNetResult(result));
        }