Example #1
0
        public OperateResult GetById(long id)
        {
            using (DbContextRoot db = new DbContextRoot())
            {
                try
                {
                    var element = (from m in db.rightList
                                   where id == m.id
                                   select m
                                   ).FirstOrDefault();

                    if (element == null)
                    {
                        return(new OperateResult
                        {
                            content = "访问错误",
                        });
                    }

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        data = element,
                    });
                }
                catch (Exception ex)
                {
                    return(new OperateResult
                    {
                        content = ex.Message,
                    });
                }
            }
        }
Example #2
0
        public OperateResult GetAll(QueryParam param = null)
        {
            using (DbContextRoot db = new DbContextRoot())
            {
                try
                {
                    var elements = from e in db.rightList.Include("module")
                                   orderby e.moduleId
                                   select new
                    {
                        e.id,
                        moduleName = e.module.name,
                        e.name,
                        e.url,
                        e.icon,
                    };

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        data = elements.ToList(),
                    });
                }
                catch (Exception ex)
                {
                    return(new OperateResult
                    {
                        content = ex.Message,
                    });
                }
            }
        }
        public OperateResult GetRegisterByCode(string code)
        {
            using (DbContextRoot db = new DbContextRoot())
            {
                try
                {
                    var element = (from m in db.companyRegisterList
                                   where code == m.code
                                   select m
                                   ).FirstOrDefault();

                    if (element == null)
                    {
                        return(new OperateResult
                        {
                            content = "不存在该公司",
                        });
                    }

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        data = element,
                    });
                }
                catch (Exception ex)
                {
                    return(new OperateResult
                    {
                        content = ex.Message,
                    });
                }
            }
        }
Example #4
0
        public OperateResult Add(FunctionRight model)
        {
            using (DbContextRoot db = new DbContextRoot())
            {
                try
                {
                    var match = from m in db.rightList
                                where m.name.Equals(model.name) || m.url.Equals(model.url)
                                select m;
                    if (match.Count() > 0)
                    {
                        return(new OperateResult
                        {
                            content = "已经存在",
                        });
                    }

                    db.rightList.Add(model);
                    db.SaveChanges();

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                    });
                }
                catch (Exception ex)
                {
                    return(new OperateResult
                    {
                        content = ex.Message,
                    });
                }
            }
        }
        public static OperateResult  GetById(long id)
        {
            try
            {
                using (DbContextRoot db = new DbContextRoot())
                {
                    var element = (from m in db.companyRegisterList
                                   where id == m.id
                                   select m
                                   ).FirstOrDefault();

                    if (element == null)
                    {
                        return(new OperateResult
                        {
                            content = "访问错误",
                        });
                    }

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        data = element,
                    });
                }
            }
            catch (Exception ex)
            {
                return(new OperateResult
                {
                    content = Model.Utility.Utility.GetExceptionMsg(ex),
                });
            }
        }
        public OperateResult GetRegisterByPager(QueryParam param = null)
        {
            using (DbContextRoot db = new DbContextRoot())
            {
                try
                {
                    var elements = from e in db.companyRegisterList
                                   select e;

                    int   total = elements.Count();
                    int   pages = 0;
                    Pager pager = param.pager;
                    if (pager == null || pager.rows == 0)
                    {
                        pages = total > 0 ? 1 : 0;
                    }
                    else
                    {
                        pages = total / (pager.rows == 0 ? 10 : pager.rows);
                        pages = total % pager.rows == 0 ? pages : pages + 1;
                        if (pager.page <= 1)
                        {
                            elements = elements.Take(pager.rows);
                        }
                        else
                        {
                            elements = elements.Skip((pager.page - 1) * pager.rows).Take(pager.rows);
                        }
                    }

                    var data = new
                    {
                        pages,
                        total,
                        rows = elements.ToList()
                    };

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        data = data,
                    });
                }
                catch (Exception ex)
                {
                    return(new OperateResult
                    {
                        content = ex.Message,
                    });
                }
            }
        }
Example #7
0
        public static OperateResult  GetAll(QueryParam param = null)
        {
            try
            {
                using (DbContextRoot db = new DbContextRoot())
                {
                    var elements = from e in db.rightList.Include("module")
                                   orderby e.moduleId
                                   select new
                    {
                        e.id,
                        moduleName = e.module.name,
                        e.name,
                        e.url,
                        e.icon,
                        e.show,
                        e.authorize
                    };

                    #region 查询过滤
                    if (param != null && param.filters != null)
                    {
                        // 过滤显示
                        #region 过滤显示
                        if (param.filters.Keys.Contains("show"))
                        {
                            var  p = param.filters["show"];
                            bool v = Convert.ToBoolean(p.value);
                            elements = elements.Where(t => t.show == v);
                        }
                        #endregion
                    }

                    #endregion


                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        data = elements.ToList(),
                    });
                }
            }
            catch (Exception ex)
            {
                return(new OperateResult
                {
                    content = Model.Utility.Utility.GetExceptionMsg(ex),
                });
            }
        }
        public OperateResult RemoveRegister(long id)
        {
            using (DbContextRoot db = new DbContextRoot())
            {
                try
                {
                    var element = db.companyRegisterList.Find(id);

                    if (element == null)
                    {
                        return(new OperateResult
                        {
                            content = "不存在该部门",
                        });
                    }

                    db.companyRegisterList.Remove(element);

                    db.Entry(element).State = EntityState.Deleted;

                    var company = (from c in db.companyList
                                   where c.name == element.name
                                   select c).FirstOrDefault();
                    db.companyList.Remove(company);
                    db.Entry(company).State = EntityState.Deleted;


                    db.SaveChanges();

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        content = "删除成功"
                    });
                }
                catch (Exception ex)
                {
                    return(new OperateResult
                    {
                        content = ex.Message,
                    });
                }
            }
        }
        public OperateResult AddRegister(CompanyRegister model)
        {
            using (DbContextRoot db = new DbContextRoot())
            {
                try
                {
                    var match = from m in db.companyRegisterList
                                where m.name.Equals(model.name) || m.code.Equals(model.code)
                                select m;
                    if (match.Count() > 0)
                    {
                        return(new OperateResult
                        {
                            content = "该公司已经存在",
                        });
                    }

                    db.companyRegisterList.Add(model);
                    Company c = new Company
                    {
                        name = model.name,
                        code = model.code
                    };
                    db.companyList.Add(c);

                    db.SaveChanges();

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                    });
                }
                catch (Exception ex)
                {
                    return(new OperateResult
                    {
                        content = ex.Message,
                    });
                }
            }
        }
Example #10
0
        public OperateResult Update(FunctionRight model)
        {
            using (DbContextRoot db = new DbContextRoot())
            {
                try
                {
                    var elements = (from e in db.rightList
                                    where e.id != model.id && e.name == model.name
                                    select e
                                    ).ToList();
                    if (elements.Count() >= 1)
                    {
                        return(new OperateResult
                        {
                            content = "已经存在同名的部门",
                        });
                    }


                    db.Entry(model).State = EntityState.Modified;

                    db.SaveChanges();

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        content = "更新成功"
                    });
                }
                catch (Exception ex)
                {
                    return(new OperateResult
                    {
                        content = ex.Message,
                    });
                }
            }
        }
        public static OperateResult  Update(CompanyRegister model)
        {
            try
            {
                using (DbContextRoot db = new DbContextRoot())
                {
                    var elements = (from e in db.companyRegisterList
                                    where e.id != model.id && e.name == model.name
                                    select e
                                    ).ToList();
                    if (elements.Count() >= 1)
                    {
                        return(new OperateResult
                        {
                            content = "已经存在同名的部门",
                        });
                    }


                    db.Entry(model).State = EntityState.Modified;

                    db.SaveChanges();

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        content = "更新成功"
                    });
                }
            }
            catch (Exception ex)
            {
                return(new OperateResult
                {
                    content = Model.Utility.Utility.GetExceptionMsg(ex),
                });
            }
        }
Example #12
0
        public OperateResult Remove(long id)
        {
            using (DbContextRoot db = new DbContextRoot())
            {
                try
                {
                    var element  = db.rightList.Find(id);
                    var elements = db.rightList.ToList();

                    if (element == null)
                    {
                        return(new OperateResult
                        {
                            content = "不存在条数据",
                        });
                    }

                    db.rightList.Remove(element);

                    db.Entry(element).State = EntityState.Deleted;
                    db.SaveChanges();

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        content = "删除成功"
                    });
                }
                catch (Exception ex)
                {
                    return(new OperateResult
                    {
                        content = ex.Message,
                    });
                }
            }
        }
        public OperateResult GetRegisterAll(QueryParam param = null)
        {
            using (DbContextRoot db = new DbContextRoot())
            {
                try
                {
                    var elements = from e in db.companyRegisterList
                                   select e;

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        data = elements.ToList(),
                    });
                }
                catch (Exception ex)
                {
                    return(new OperateResult
                    {
                        content = ex.Message,
                    });
                }
            }
        }
        public static OperateResult  GetAll(QueryParam param = null)
        {
            try
            {
                using (DbContextRoot db = new DbContextRoot())
                {
                    var elements = from e in db.companyRegisterList
                                   select e;

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        data = elements.ToList(),
                    });
                }
            }
            catch (Exception ex)
            {
                return(new OperateResult
                {
                    content = Model.Utility.Utility.GetExceptionMsg(ex),
                });
            }
        }
Example #15
0
        public OperateResult GetByPager(QueryParam param = null)
        {
            using (DbContextRoot db = new DbContextRoot())
            {
                try
                {
                    var elements = from e in db.rightList.Include("module")
                                   orderby e.moduleId
                                   select new
                    {
                        e.id,
                        moduleName = e.module.name,
                        e.name,
                        e.url,
                        e.icon,
                        e.authorize
                    };

                    int   total = elements.Count();
                    int   pages = 0;
                    Pager pager = param.pager;
                    if (pager == null || pager.rows == 0)
                    {
                        pages = total > 0 ? 1 : 0;
                    }
                    else
                    {
                        pages = total / (pager.rows == 0 ? 10 : pager.rows);
                        pages = total % pager.rows == 0 ? pages : pages + 1;
                        if (pager.page <= 1)
                        {
                            elements = elements.Take(pager.rows);
                        }
                        else
                        {
                            elements = elements.Skip((pager.page - 1) * pager.rows).Take(pager.rows);
                        }
                    }

                    var data = new
                    {
                        pages,
                        total,
                        rows = elements.ToList()
                    };

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        data = data,
                    });
                }
                catch (Exception ex)
                {
                    return(new OperateResult
                    {
                        content = ex.Message,
                    });
                }
            }
        }
Example #16
0
        public static OperateResult  GetByPager(QueryParam param = null)
        {
            try
            {
                using (DbContextRoot db = new DbContextRoot())
                {
                    var elements = from e in db.rightList.Include("module")
                                   orderby e.module.showIndex
                                   select new
                    {
                        e.id,
                        moduleName = e.module.name,
                        e.name,
                        e.url,
                        e.icon,
                        e.show,
                        e.authorize
                    };

                    #region 查询过滤
                    if (param != null && param.filters != null)
                    {
                        // 过滤显示
                        #region 过滤显示
                        if (param.filters.Keys.Contains("show"))
                        {
                            var  p = param.filters["show"];
                            bool v = Convert.ToBoolean(p.value);
                            elements = elements.Where(t => t.show == v);
                        }
                        #endregion
                    }

                    #endregion


                    int   total = elements.Count();
                    int   pages = 0;
                    Pager pager = param.pager;
                    if (pager == null || pager.rows == 0)
                    {
                        pages = total > 0 ? 1 : 0;
                    }
                    else
                    {
                        pages = total / (pager.rows == 0 ? 20 : pager.rows);
                        pages = total % pager.rows == 0 ? pages : pages + 1;
                        if (pager.page <= 1)
                        {
                            elements = elements.Take(pager.rows);
                        }
                        else
                        {
                            elements = elements.Skip((pager.page - 1) * pager.rows).Take(pager.rows);
                        }
                    }

                    var data = new
                    {
                        pages,
                        total,
                        rows = elements.ToList()
                    };

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        data = data,
                    });
                }
            }
            catch (Exception ex)
            {
                return(new OperateResult
                {
                    content = Model.Utility.Utility.GetExceptionMsg(ex),
                });
            }
        }