Esempio n. 1
0
        //客户登录和验证
        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;
                    }
                }
            }
        }
Esempio n. 2
0
 //删除客户
 public int DeleteCustomer(Customer entity)
 {
     using (var db = new HouseMarketEntities())
     {
         var customer = db.Customers.FirstOrDefault(c => c.CustomerID == entity.CustomerID);
         if (customer == null)
         {
             return (int)Errors.UserErrors.IDNotExisted;
         }
         else
         {
             db.Customers.Remove(customer);
             db.SaveChanges();
             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);
            }
        }
Esempio n. 4
0
        //新增客户
        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;
                }
            }
        }
Esempio n. 5
0
        //编辑客户
        public int EditCustomer(Customer entity)
        {
            using (var db = new HouseMarketEntities())
            {
                var customer = db.Customers.FirstOrDefault(c => c.CustomerID == entity.CustomerID);
                if (customer == null)
                {
                    return (int)Errors.UserErrors.IDNotExisted;
                }
                else
                {
                    if (string.IsNullOrEmpty(entity.Password))
                    {
                        if (string.IsNullOrEmpty(entity.CustomerName))
                        {
                            return (int)Errors.UserErrors.WrongParameter;
                        }
                        else
                        {
                            customer.CustomerName = entity.CustomerName;
                            customer.Tele = entity.Tele;
                        }
                    }
                    else
                    {
                        customer.Password = entity.Password;
                    }

                    if (db.Customers.Count(c=>c.CustomerName == customer.CustomerName) > 1)
                    {
                        return (int)Errors.UserErrors.NameExisted;
                    }
                    else
                    {
                        db.SaveChanges();
                        return 0;
                    }
                }
            }
        }