Exemplo n.º 1
0
        // GET api/customerapi/5
        public CCustomer 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))
            {
                CCustomer customer;
                try
                {
                    dal.Open();
                    customer = CustomerBll.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}", "Customer.Get", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }

                if (customer == null)
                {
                    throw new HttpResponseException(new DataNotFoundMessage());
                }
                return(customer);
            }
        }