public ContactAddAndUpdateDto GetContactDto(long id) { ContactAddAndUpdateDto dto = new ContactAddAndUpdateDto(); dto.contact = GetContact(id); if (dto.contact == null) { return(null); } var bll = new UserDefinedFieldsBLL(); dto.udf = bll.GetUdfValue(UDF_CATE.CONTACT, id, bll.GetUdf(UDF_CATE.CONTACT)); if (dto.contact.location_id != null) { dto.location = new LocationBLL().GetLocation((long)dto.contact.location_id); } if (dto.contact.location_id2 != null) { dto.location2 = new LocationBLL().GetLocation((long)dto.contact.location_id2); } var company = new CompanyBLL().GetCompany(dto.contact.account_id); dto.company_name = company.name; return(dto); }
/// <summary> /// 保存表单数据到对象 /// </summary> private void SaveFormData() { var param = new ContactAddAndUpdateDto(); param.contact = AssembleModel <crm_contact>(); param.contact.id = id; param.contact.name = param.contact.first_name + param.contact.last_name; param.contact.avatar = SavePic(); param.contact.is_active = active.Checked ? 1 : 0; param.contact.is_primary_contact = (sbyte)(primary.Checked ? 1 : 0); param.contact.is_optout_survey = (sbyte)(optoutSurvey.Checked ? 1 : 0); param.contact.is_optout_contact_group_email = (sbyte)(optoutEmail.Checked ? 1 : 0); param.contact.allow_notify_email_task_ticket = (sbyte)(allowEmail.Checked ? 1 : 0); if (contact_udfList != null && contact_udfList.Count > 0) // 首先判断是否有自定义信息 { var list = new List <UserDefinedFieldValue>(); foreach (var udf in contact_udfList) // 循环添加 { var new_udf = new UserDefinedFieldValue() { id = udf.id, value = Request.Form[udf.id.ToString()] == null ? "" : Request.Form[udf.id.ToString()], }; list.Add(new_udf); } param.udf = list; } dto = param; }
/// <summary> /// 新增联系人 /// </summary> /// <returns></returns> public ERROR_CODE Insert(ContactAddAndUpdateDto contactAddDto, long user_id) { var user = UserInfoBLL.GetUserInfo(user_id); if (user == null) { return(ERROR_CODE.USER_NOT_FIND); } #region 对联系人必填项的校验 // 必填项校验 if (string.IsNullOrEmpty(contactAddDto.contact.name) || string.IsNullOrEmpty(contactAddDto.contact.phone) || string.IsNullOrEmpty(contactAddDto.contact.first_name)) { return(ERROR_CODE.PARAMS_ERROR); // string类型的非空校验 } if (contactAddDto.contact.allow_notify_email_task_ticket == 1) { if (string.IsNullOrEmpty(contactAddDto.contact.email)) { return(ERROR_CODE.PARAMS_ERROR); // 如果任务和工单中允许发邮件,那么联系人的邮箱为必填项 } } #endregion #region 对联系人中的唯一性信息进行校验(联系人和移动电话) if (!string.IsNullOrEmpty(contactAddDto.contact.mobile_phone)) // 如果用户填写了移动电话,那么对电话进行唯一检验(全表内未删除的联系人进行检索,不局限于本客户联系人) { var same_phone_contact = _dal.GetContactByPhone(contactAddDto.contact.mobile_phone); if (same_phone_contact != null && same_phone_contact.Count > 0) // 查询到此手机号已经有联系人在使用,不可重复使用,返回错误 { return(ERROR_CODE.ERROR); } } // 联系人名称校验 var compare_contact = _dal.GetContactByName(contactAddDto.contact.account_id, contactAddDto.contact.name); if (compare_contact != null && compare_contact.Count > 0) // 该客户如果存在名称一样的未删除的用户,返回错误,提醒用户 { return(ERROR_CODE.ERROR); } #endregion if (contactAddDto.location != null) { var _location = contactAddDto.location; new LocationBLL().Insert(_location, user_id); } #region 如果是主要联系人,首先将原主要联系人设置为普通联系人 if (contactAddDto.contact.is_primary_contact == 1) // 客户将当前联系人设置为主要联系人,此时将原有的主要联系人更改为普通联系人 { var old_primary_contact = _dal.GetPrimaryContactByAccountId(contactAddDto.contact.account_id); // 获取到客户的主要联系人 if (old_primary_contact != null && old_primary_contact.id != contactAddDto.contact.id) { old_primary_contact.is_primary_contact = 0; if (_dal.Update(old_primary_contact)) // 更改主要联系人,插入操作日志 { new sys_oper_log_dal().Insert(new sys_oper_log() { user_cate = "用户", user_id = user.id, name = user.name, phone = user.mobile == null ? "" : user.mobile, oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.CONTACTS, oper_object_id = old_primary_contact.id, oper_type_id = (int)OPER_LOG_TYPE.UPDATE, oper_description = @"{""is_primary_contact"":""1→0""}", // 1 主要联系人 0 普通联系人 remark = "修改主要联系人为普通联系人", }); // 插入更改日志 } } } #endregion #region 保存联系人信息 //contactAddDto.contact.suffix_id = contactAddDto.contact.suffix_id == 0 ? null : contactAddDto.contact.suffix_id; contactAddDto.contact.id = contactAddDto.contact.id == 0 ? _dal.GetNextIdCom() : contactAddDto.contact.id; contactAddDto.contact.create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); contactAddDto.contact.create_user_id = user.id; contactAddDto.contact.update_time = contactAddDto.contact.create_time; contactAddDto.contact.update_user_id = user.id; _dal.Insert(contactAddDto.contact); new sys_oper_log_dal().Insert(new sys_oper_log() { user_cate = "用户", user_id = (int)user.id, name = user.name, phone = user.mobile == null ? "" : user.mobile, oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.CONTACTS, oper_object_id = contactAddDto.contact.id,// 操作对象id oper_type_id = (int)OPER_LOG_TYPE.ADD, oper_description = _dal.AddValue(contactAddDto.contact), remark = "新增联系人" }); // 插入日志 #endregion #region 保存联系人扩展信息 var udf_contact_list = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.CONTACT); // 联系人的自定义字段 var udf_con_list = contactAddDto.udf; // 传过来的联系人的自定义参数 new UserDefinedFieldsBLL().SaveUdfValue(DicEnum.UDF_CATE.CONTACT, user.id, contactAddDto.contact.id, udf_contact_list, udf_con_list, OPER_LOG_OBJ_CATE.CONTACTS_EXTENSION_INFORMATION); // 保存成功即插入日志 #endregion #region 更新客户最后活动时间 crm_account thisAccount = new CompanyBLL().GetCompany(contactAddDto.contact.account_id); if (thisAccount != null) { thisAccount.last_activity_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); new CompanyBLL().EditAccount(thisAccount, user_id); } #endregion return(ERROR_CODE.SUCCESS); }
protected void Page_Load(object sender, EventArgs e) { bool is_edit = long.TryParse(Request.QueryString["id"], out id); thisBookMark = new IndexBLL().GetSingBook(Request.RawUrl, LoginUserId); if (is_edit) { if (AuthBLL.GetUserContactAuth(LoginUserId, LoginUser.security_Level_id, id).CanEdit == false) { Response.End(); return; } } try { var account_id = Request.QueryString["account_id"]; if (!string.IsNullOrEmpty(account_id)) { account = new CompanyBLL().GetCompany(long.Parse(account_id)); } callBackFiled = Request.QueryString["callback"]; } catch (Exception) { Response.End(); } if (IsPostBack) { SaveFormData(); } else { var dic = new ContactBLL().GetField(); // 称谓 sufix.DataTextField = "show"; sufix.DataValueField = "val"; sufix.DataSource = dic.FirstOrDefault(_ => _.Key == "sufix").Value; sufix.DataBind(); sufix.Items.Insert(0, new ListItem() { Value = "0", Text = " ", Selected = true }); contact_udfList = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.CONTACT); if (is_edit) { dto = new ContactBLL().GetContactDto(long.Parse(Request.QueryString["id"])); active.Checked = dto.contact.is_active == 1 ? true : false; primary.Checked = dto.contact.is_primary_contact == 1 ? true : false; allowEmail.Checked = dto.contact.allow_notify_email_task_ticket == 1 ? true : false; optoutEmail.Checked = dto.contact.is_optout_contact_group_email == 1 ? true : false; optoutSurvey.Checked = dto.contact.is_optout_survey == 1 ? true : false; if (!string.IsNullOrEmpty(dto.contact.avatar)) { avatarPath = dto.contact.avatar; } } else { dto.contact = new crm_contact(); dto.udf = new List <UserDefinedFieldValue>(); dto.location = new crm_location(); dto.location2 = new crm_location(); active.Checked = true; allowEmail.Checked = true; } } }