//客户登录和验证
        public int CheckCustomer(Customer entity, out CustomerViewResult result)
        {
            result = new CustomerViewResult();

            using (var db = new HouseMarketEntities())
            {
                var customer = db.Customers.FirstOrDefault(c => c.CustomerName == entity.CustomerName);
                if (customer == null)
                {
                    result = null;
                    return (int)Errors.UserErrors.NameNotExisted;
                }
                else
                {
                    if (customer.Password != entity.Password)
                    {
                        result = null;
                        return (int)Errors.UserErrors.WrongPassword;
                    }
                    else
                    {
                        PropertyFunction.CopyEntity(customer, result);
                        return 0;
                    }
                }
            }
        }
        /// <summary>
        /// 查询客户或用户登录
        /// </summary>
        /// <returns>客户视图,总页数</returns>
        public HttpResponseMessage Get()
        {
            int totalPage = 0;
            List<CustomerViewResult> result = new List<CustomerViewResult>();

            var queryString = Request.GetQueryNameValuePairs();

            if (queryString.Any(q => q.Key.ToLower() == "password"))
            {
                string customerName = queryString.FirstOrDefault(q => q.Key.ToLower() == "customername").Value;
                string password = queryString.FirstOrDefault(q => q.Key.ToLower() == "password").Value;

                Customer entity = new Customer() { CustomerName = customerName, Password = password };
                CustomerViewResult logonCustomer = new CustomerViewResult();

                var customerFunction = new CustomerFunction();
                int error = customerFunction.CheckCustomer(entity, out logonCustomer);

                if (error == 0)
                {
                    return Request.CreateResponse(HttpStatusCode.OK, logonCustomer);
                }
                else
                {
                    return GetResponse.UserResponse(error);
                }
            }
            else
            {
                var queryConditions = new CustomerQueryConditions();
                queryConditions.GetValues(queryString);

                CustomerFunction customerFunction = new CustomerFunction();
                customerFunction.QueryCustomers(queryConditions, out result, out totalPage);

                List<object> objectResult = new List<object>() { result, new { totalPage = totalPage } };
                return Request.CreateResponse(HttpStatusCode.OK, objectResult);
            }
        }
        //新增客户
        public int AddCustomer(Customer entity, out CustomerViewResult result)
        {
            result = new CustomerViewResult();

            using (var db = new HouseMarketEntities())
            {
                if (string.IsNullOrEmpty(entity.CustomerName) || string.IsNullOrEmpty(entity.Password))
                {
                    return (int)Errors.UserErrors.WrongParameter;
                }
                else if (db.Customers.Any(c => c.CustomerName == entity.CustomerName))
                {
                    return (int)Errors.UserErrors.NameExisted;
                }
                else
                {
                    var entityResult = db.Customers.Add(entity);
                    db.SaveChanges();
                    PropertyFunction.CopyEntity(entityResult, result);
                    return 0;
                }
            }
        }
        /// <summary>
        /// 新增客户
        /// </summary>
        /// <param name="entity">客户视图</param>
        public HttpResponseMessage Post([FromBody]Customer entity)
        {
            var result = new CustomerViewResult();
            var response = new HttpResponseMessage();

            if (entity == null)
            {
                return new HttpResponseMessage(HttpStatusCode.BadRequest);
            }
            else
            {
                var customerFunction = new CustomerFunction();
                int error = customerFunction.AddCustomer(entity, out result);
                if (error == 0)
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, result);
                }
                else
                {
                    response = GetResponse.UserResponse(error);
                }

                return response;
            }
        }