Пример #1
0
        // GET api/menuapi
        public IEnumerable <CMenuCategory> Get()
        {
            var user =
                (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]];

            if (user == null)
            {
                throw new HttpResponseException(new SiginFailureMessage());
            }
            using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0))
            {
                try
                {
                    dal.Open();
                }
                catch (Exception ex)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName),
                        LogContent = string.Format("{0}#{1}", "Menu.List", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }
                var menus = FunctionBll.LoadMenu(dal, user.GroupCode);
                if (menus == null)
                {
                    throw new HttpResponseException(new DataNotFoundMessage());
                }
                return(menus);
            }
        }
Пример #2
0
        // GET api/logapi
        public IEnumerable <CLog> Get(int page)
        {
            var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]];

            if (user == null)
            {
                throw new HttpResponseException(new SiginFailureMessage());
            }
            using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0))
            {
                CLog[] logs;
                try
                {
                    dal.Open();
                    logs = LogBll.List(dal, page);
                    dal.Close();
                }
                catch (Exception ex)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName),
                        LogContent = string.Format("{0}#{1}", "Log.List", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }
                if (logs == null)
                {
                    throw new HttpResponseException(new DataNotFoundMessage());
                }
                return(logs);
            }
        }
Пример #3
0
        // GET api/contactapi/5
        public CCustContact Get(int id)
        {
            var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]];

            if (user == null)
            {
                throw new HttpResponseException(new SiginFailureMessage());
            }
            using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0))
            {
                CCustContact custContact;
                try
                {
                    dal.Open();
                    custContact = CustContactBll.Get(dal, id);
                    dal.Close();
                }
                catch (Exception ex)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName),
                        LogContent = string.Format("{0}#{1}", "CustContact.Get", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }
                if (custContact == null)
                {
                    throw new HttpResponseException(new DataNotFoundMessage());
                }
                return(custContact);
            }
        }
Пример #4
0
        // POST api/customerapi
        public CCustomer Post(CCustomer value)
        {
            var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]];

            if (user == null)
            {
                throw new HttpResponseException(new SiginFailureMessage());
            }
            using (
                var dal =
                    DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0)
                )
            {
                bool ok;
                try
                {
                    dal.Open();
                    ok = CustomerBll.Create(dal, value, string.Format("{0}-{1}", user.UserCode, user.UserName));
                }
                catch (Exception ex)
                {
                    if (ex.Message.StartsWith("违反了 UNIQUE KEY 约束"))
                    {
                        throw new HttpResponseException(new PrimaryRepeatedMessge());
                    }
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName),
                        LogContent = string.Format("{0}#{1}", "Customer.Post", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }
                if (!ok)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogContent = string.Format("新建客户{0}-{1}", value.CustomerCode, value.CustomerName),
                        LogType    = LogType.操作失败,
                        LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName)
                    });
                    throw new HttpResponseException(new DealFailureMessage());
                }
                LogBll.Write(dal, new CLog
                {
                    LogContent = string.Format("新建客户{0}-{1}", value.CustomerCode, value.CustomerName),
                    LogType    = LogType.操作成功,
                    LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName)
                });
                dal.Close();
                return(value);
            }
        }
Пример #5
0
        public CSign Post(CSign value)
        {
            using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0))
            {
                bool ok;
                try
                {
                    dal.Open();
                }
                catch (Exception ex)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", value.UserCode, value.UserName),
                        LogContent = string.Format("{0}#{1}", "Signin", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }
                var tokenCookie = HttpContext.Current.Request.Cookies["Token"];
                if (value.Remain && tokenCookie != null && string.IsNullOrEmpty(value.UserCode) && string.IsNullOrEmpty(value.UPwd))
                {
                    //Token不为空 用户名和密码为空,则使用token登录
                    ok = SignBll.Signin(dal, tokenCookie.Values["User"], tokenCookie.Values["Value"], value);
                }
                else
                {
                    //使用用户名密码登录
                    ok = SignBll.Signin(dal, value);
                }
                if (!ok)
                {
                    throw new HttpResponseException(new DataNotFoundMessage());
                }
                HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]] = value;
                //生成Token
                var token = Guid.NewGuid().ToString();
                SignBll.UpdateToken(dal, token, value.UserCode);
                HttpContext.Current.Response.Cookies["Token"].Values["User"]  = value.UserCode;
                HttpContext.Current.Response.Cookies["Token"].Values["Value"] = token;

                HttpContext.Current.Response.Cookies["Token"].Expires = DateTime.Now.AddDays(30);
                if (value.Remain)
                {
                    return(value);
                }
                HttpContext.Current.Response.Cookies["Token"].Expires = DateTime.Now.AddDays(-1);
                SignBll.DropToken(dal, value.UserCode);
                dal.Close();
                return(value);
            }
        }
Пример #6
0
        // GET api/userselecterapi
        public IEnumerable <CLenovoInputOption> Get(string dataSource, string condition)
        {
            var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]];

            if (user == null)
            {
                throw new HttpResponseException(new SiginFailureMessage());
            }
            using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0))
            {
                CLenovoInputOption[] options;
                try
                {
                    dal.Open();
                    switch (dataSource)
                    {
                    case "User":
                        options = UserBll.GetLenovoInputOption(dal, condition);
                        break;

                    case "Dept":
                        options = DeptBll.GetLenovoInputOption(dal, condition);
                        break;

                    case "UserGroup":
                        options = UserGroupBll.GetLenovoInputOption(dal, condition);
                        break;

                    default:
                        throw new HttpResponseException(new SystemExceptionMessage());
                    }

                    dal.Close();
                }
                catch (Exception ex)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName),
                        LogContent = string.Format("{0}#{1}", "LenovoInputer.List", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }
                if (options == null)
                {
                    throw new HttpResponseException(new DataNotFoundMessage());
                }
                return(options);
            }
        }
Пример #7
0
        // DELETE api/userapi/5
        public void Delete(int id)
        {
            var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]];

            if (user == null)
            {
                throw new HttpResponseException(new SiginFailureMessage());
            }
            using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0))
            {
                bool  ok;
                CUser hisUser;
                try
                {
                    dal.Open();
                    ok = UserBll.Delete(dal, id, out hisUser);
                }
                catch (Exception ex)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName),
                        LogContent = string.Format("{0}#{1}", "User.Delete", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }
                if (!ok)
                {
                    if (hisUser != null)
                    {
                        LogBll.Write(dal, new CLog
                        {
                            LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName),
                            LogContent = string.Format("删除用户{0}-{1}", hisUser.UserCode, hisUser.UserName),
                            LogType    = LogType.操作失败
                        });
                    }
                    throw new HttpResponseException(new DealFailureMessage());
                }
                LogBll.Write(dal, new CLog
                {
                    LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName),
                    LogContent = string.Format("删除用户{0}-{1}", hisUser.UserCode, hisUser.UserName),
                    LogType    = LogType.操作成功
                });
                dal.Close();
            }
        }
Пример #8
0
        // PUT api/usergroupapi/5
        public CUserGroup Put(int id, CUserGroup value)
        {
            var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]];

            if (user == null)
            {
                throw new HttpResponseException(new SiginFailureMessage());
            }
            using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0))
            {
                bool ok;
                try
                {
                    dal.Open();
                    ok = UserGroupBll.Update(dal, value, string.Format("{0}-{1}", user.UserCode, user.UserName));
                }
                catch (Exception ex)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName),
                        LogContent = string.Format("{0}#{1}", "UserGroup.Put", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }
                if (!ok)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName),
                        LogContent = string.Format("修改用户组{0}-{1}", value.GroupCode, value.GroupName),
                        LogType    = LogType.操作失败
                    });
                    throw new HttpResponseException(new DealFailureMessage());
                }
                LogBll.Write(dal, new CLog
                {
                    LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName),
                    LogContent = string.Format("修改用户组{0}-{1}", value.GroupCode, value.GroupName),
                    LogType    = LogType.操作成功
                });
                dal.Close();
                return(value);
            }
        }
Пример #9
0
        // GET api/uniquecheckapi/5
        public CCheckResultModel Get(string dataSource, string value)
        {
            var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]];

            if (user == null)
            {
                throw new HttpResponseException(new SiginFailureMessage());
            }
            using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0))
            {
                try
                {
                    CCheckResultModel rst;
                    dal.Open();
                    switch (dataSource)
                    {
                    case "User.UserCode":
                        rst = UserBll.CheckUserCodeUnique(dal, value);
                        break;

                    case "Customer.CustomerCode":
                        rst = CustomerBll.CheckCustomerCodeUnique(dal, value);
                        break;

                    default:
                        throw new Exception("UniqueCheckInputer错误,没有找到指定DataSource");
                    }

                    dal.Close();
                    return(rst);
                }
                catch (Exception ex)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", user.UserCode, user.UserName),
                        LogContent = string.Format("{0}#{1}", "UniqueCheck.Get", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }
            }
        }
Пример #10
0
        // GET api/menuapi
        public IEnumerable <CMenuCategory> Get()
        {
            using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0))
            {
                var user =
                    (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]];
                try
                {
                    dal.Open();
                    if (user == null)
                    {
                        var httpCookie = HttpContext.Current.Request.Cookies["Token"];
                        if (httpCookie != null)
                        {
                            //存在Token,进行Token登录

                            if (SignBll.Signin(dal, httpCookie.Values["User"], httpCookie.Values["Value"],
                                               user))
                            {
                                HttpContext.Current.Session.Add(ConfigurationManager.AppSettings["AuthSaveKey"],
                                                                user);
                                //更新Token
                                var token = Guid.NewGuid().ToString();
                                HttpContext.Current.Response.Cookies["Token"].Values["User"]  = user.UserCode;
                                HttpContext.Current.Response.Cookies["Token"].Values["Value"] = token;
                                HttpContext.Current.Response.Cookies["Token"].Expires         = DateTime.Now.AddDays(30);
                                SignBll.UpdateToken(dal, token, user.UserCode);
                            }
                            else
                            {
                                throw new HttpResponseException(new SiginFailureMessage());
                            }
                        }
                        else
                        {
                            throw new HttpResponseException(new SiginFailureMessage());
                        }
                    }
                    var menus = FunctionBll.LoadMenu(dal, user.GroupCode);
                    if (menus == null)
                    {
                        throw new HttpResponseException(new DataNotFoundMessage());
                    }
                    return(menus);
                }
                catch (Exception ex)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", user == null?string.Empty:user.UserCode, user == null?string.Empty:user.UserName),
                        LogContent = string.Format("{0}#{1}", "Menu.List", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }
                finally
                {
                    dal.Close();
                }
            }
        }