Exemplo n.º 1
0
        /// <summary>
        /// 保存客户信息
        /// </summary>
        /// <param name="customer">客户模型</param>
        /// <returns></returns>
        public bool Save(Customer customer)
        {
            //参数验证
            if (customer == null || string.IsNullOrEmpty(customer.Mobile) || string.IsNullOrEmpty(customer.ServiceSpaceID))
            {
                return(false);
            }

            //客户是否存在
            DataEntity customerEntity = null;

            if (!string.IsNullOrEmpty(customer.ID))
            {
                customerEntity = _customerProvider.Get(customer.ID);
            }
            if (customerEntity == null)
            {
                customer.ID    = System.Guid.NewGuid().ToString();
                customerEntity = new DataEntity();
                customerEntity.Add("ID", customer.ID);
                customerEntity.Add("ServiceSpaceID", string.IsNullOrEmpty(customer.ServiceSpaceID) ? "" : customer.ServiceSpaceID);
                customerEntity.Add("Address", string.IsNullOrEmpty(customer.Address) ? "" : customer.Address);
                customerEntity.Add("Area", string.IsNullOrEmpty(customer.Area) ? "" : customer.Area);
                customerEntity.Add("Remark", string.IsNullOrEmpty(customer.Remark) ? "" : customer.Remark);
                customerEntity.Add("CompanyName", string.IsNullOrEmpty(customer.CompanyName) ? "" : customer.CompanyName);
                customerEntity.Add("Gender", (int)customer.Gender);
                customerEntity.Add("Mail", string.IsNullOrEmpty(customer.Mail) ? "" : customer.Mail);
                customerEntity.Add("Mobile", string.IsNullOrEmpty(customer.Mobile) ? "" : customer.Mobile);
                customerEntity.Add("Name", string.IsNullOrEmpty(customer.Name) ? "" : customer.Name);
                customerEntity.Add("UserName", string.IsNullOrEmpty(customer.UserName) ? customer.Mobile : customer.UserName);
                customerEntity.Add("Password", string.IsNullOrEmpty(customer.Password) ? "" : customer.Password);
                customerEntity.Add("WeChat", string.IsNullOrEmpty(customer.WeChat) ? "" : customer.WeChat);
                customerEntity.Add("RecentService", string.IsNullOrEmpty(customer.RecentService) ? "" : customer.RecentService);
                customerEntity.Add("HeadImg", string.IsNullOrEmpty(customer.HeadImg) ? "" : customer.HeadImg);
                customerEntity.Add("Contact", string.IsNullOrEmpty(customer.Contact) ? "" : customer.Contact);
                customerEntity.Add("LabelIDs", string.IsNullOrEmpty(customer.LabelIDs) ? "" : customer.LabelIDs);
                customerEntity.Add("ServiceNetworkID", string.IsNullOrEmpty(customer.ServiceNetworkID) ? "" : customer.ServiceNetworkID);
                return(_customerProvider.Add(customerEntity));
            }
            else
            {
                customerEntity["Address"].Value       = string.IsNullOrEmpty(customer.Address) ? "" : customer.Address;
                customerEntity["Area"].Value          = string.IsNullOrEmpty(customer.Area) ? "" : customer.Area;
                customerEntity["Remark"].Value        = string.IsNullOrEmpty(customer.Remark) ? "" : customer.Remark;
                customerEntity["CompanyName"].Value   = string.IsNullOrEmpty(customer.CompanyName) ? "" : customer.CompanyName;
                customerEntity["Gender"].Value        = (int)customer.Gender;
                customerEntity["Mail"].Value          = string.IsNullOrEmpty(customer.Mail) ? "" : customer.Mail;
                customerEntity["Mobile"].Value        = string.IsNullOrEmpty(customer.Mobile) ? "" : customer.Mobile;
                customerEntity["Name"].Value          = string.IsNullOrEmpty(customer.Name) ? "" : customer.Name;
                customerEntity["Password"].Value      = string.IsNullOrEmpty(customer.Password) ? "" : customer.Password;
                customerEntity["WeChat"].Value        = string.IsNullOrEmpty(customer.WeChat) ? "" : customer.WeChat;
                customerEntity["RecentService"].Value = string.IsNullOrEmpty(customer.RecentService) ? "" : customer.RecentService;
                customerEntity["HeadImg"].Value       = string.IsNullOrEmpty(customer.HeadImg) ? "" : customer.HeadImg;
                customerEntity["Contact"].Value       = string.IsNullOrEmpty(customer.Contact) ? "" : customer.Contact;
                customerEntity["LabelIDs"].Value      = string.IsNullOrEmpty(customer.LabelIDs) ? "" : customer.LabelIDs;

                return(_customerProvider.Update(customerEntity));
            }
        }