static void Main(string[] args) { string connectionString = "Url=https://dynamicscrmnext.crm5.dynamics.com; [email protected]; Password=P@$$w0rd1;"; Microsoft.Xrm.Client.CrmConnection connection = CrmConnection.Parse(connectionString); try { using (OrganizationService orgService = new OrganizationService(connection)) { CrmEntityReference target = new CrmEntityReference(); target.Id = new Guid("AAD1D9DD-7B98-E411-80D6-C4346BADB628"); target.LogicalName = Incident.EntityLogicalName; MergeRequest mergeRequest = new MergeRequest(); mergeRequest.SubordinateId = new Guid("ACD1D9DD-7B98-E411-80D6-C4346BADB628"); mergeRequest.Target = target; mergeRequest.PerformParentingChecks = false; Incident incidentUpdate = new Incident(); incidentUpdate.Title = "Merged2"; mergeRequest.UpdateContent = incidentUpdate; MergeResponse mergeResponse = (MergeResponse)orgService.Execute(mergeRequest); string s = ""; } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
private async Task <CrmEntityReference> GetBehaviorEntityByCode(string code) { CrmEntityReference referenceEntity = null; try { var fetchXml = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='mcs_behavior'> <attribute name='mcs_behaviorid' /> <attribute name='mcs_name' /> <attribute name='createdon' /> <order attribute='mcs_name' descending='false' /> <filter type='and'> <condition attribute='statecode' operator='eq' value='0' /> <condition attribute='mcs_code' operator='eq' value='{code}' /> </filter> </entity> </fetch>"; var fetchXdoc = XDocument.Parse(fetchXml); var crmRequestHelper = new CrmRequestHelper(); var entities = await crmRequestHelper.ExecuteAsync(_crmService, "mcs_behavior", fetchXdoc); if (entities != null && entities.Results[0] != null) { var entity = entities.Results[0]; referenceEntity = new CrmEntityReference(entity.EntityName, entity.Id); } } catch (Exception ex) { referenceEntity = null; } return(referenceEntity); }
/// <summary> /// 基础字段赋值 /// </summary> /// <param name="createEntity"></param> /// <param name="request"></param> private void BasicAssignment(CrmExecuteEntity entity, UserMsgequest request) { //消息标题 if (!string.IsNullOrWhiteSpace(request.mcs_name)) { entity.Attributes["mcs_name"] = request.mcs_name; } //C端用户Id if (!string.IsNullOrWhiteSpace(request.mcs_user)) { var useref = new CrmEntityReference("mcs_user", Guid.Parse(request.mcs_user)); entity.Attributes["mcs_user"] = useref; } //跳转链接 if (!string.IsNullOrWhiteSpace(request.mcs_url)) { entity.Attributes["mcs_url"] = request.mcs_url; } //阅读时间 if (request.mcs_readdate != null) { var readdate = request.mcs_readdate.Value.ToUniversalTime(); entity.Attributes["mcs_readdate"] = readdate; } //导航图片Url if (!string.IsNullOrWhiteSpace(request.mcs_head_imageurl)) { entity.Attributes["mcs_head_imageurl"] = request.mcs_head_imageurl; } //消息内容 if (!string.IsNullOrWhiteSpace(request.mcs_content)) { entity.Attributes["mcs_content"] = request.mcs_content; } //删除时间 if (request.mcs_deletedate != null) { var deletedate = request.mcs_deletedate.Value.ToUniversalTime(); entity.Attributes["mcs_deletedate"] = deletedate; } //消息类型 if (request.mcs_type != null) { entity.Attributes["mcs_type"] = request.mcs_type; } //阅读状态 if (request.mcs_readstatus != null) { entity.Attributes["mcs_readstatus"] = request.mcs_readstatus; } //删除状态 if (request.mcs_deletestatus != null) { entity.Attributes["mcs_deletestatus"] = request.mcs_deletestatus; } }
/// <summary> /// 基础字段 /// </summary> /// <param name="updateEntity"></param> /// <param name="request"></param> private void BasicAssignment(CrmExecuteEntity updateEntity, OnlyLeadEditRequest request) { // 姓名 if (!string.IsNullOrWhiteSpace(request.onlylead.mcs_name)) { updateEntity.Attributes.Add("mcs_name", request.onlylead.mcs_name); } // 线索来源 if (request.onlylead.mcs_leadorigin != null) { updateEntity.Attributes.Add("mcs_leadorigin", request.onlylead.mcs_leadorigin); } // 性别 if (request.onlylead.mcs_gender != null) { updateEntity.Attributes.Add("mcs_gender", request.onlylead.mcs_gender); } // 邮箱 if (!string.IsNullOrWhiteSpace(request.onlylead.mcs_emailaddress1)) { updateEntity.Attributes.Add("mcs_emailaddress1", request.onlylead.mcs_emailaddress1); } // 评分 if (request.onlylead.mcs_accountpoints != null) { updateEntity.Attributes.Add("mcs_accountpoints", request.onlylead.mcs_accountpoints); } // 用车省份 if (!string.IsNullOrWhiteSpace(request.onlylead.mcs_usecarprovince)) { updateEntity.Attributes.Add("mcs_usecarprovince", request.onlylead.mcs_usecarprovince); } // 用车城市 if (!string.IsNullOrWhiteSpace(request.onlylead.mcs_usecarcity)) { updateEntity.Attributes.Add("mcs_usecarcity", request.onlylead.mcs_usecarcity); } // 省份ID if (request.onlylead.mcs_provinceid != null) { var provinceEntityRf = new CrmEntityReference("mcs_sysarea", (Guid)request.onlylead.mcs_provinceid); updateEntity.Attributes.Add("mcs_provinceid", provinceEntityRf); } // 市ID if (request.onlylead.mcs_cityid != null) { var cityEntityRf = new CrmEntityReference("mcs_sysarea", (Guid)request.onlylead.mcs_cityid); updateEntity.Attributes.Add("mcs_cityid", cityEntityRf); } // 区ID if (request.onlylead.mcs_districtid != null) { var districtEntityRf = new CrmEntityReference("mcs_sysarea", (Guid)request.onlylead.mcs_districtid); updateEntity.Attributes.Add("mcs_districtid", districtEntityRf); } }
public async Task <ValidateResult <string> > addorderpay(OrderPayEditRequest orderPayEditRequest) { try { var validateResult = new ValidateResult <string>(); var crmRequestHelper = new CrmRequestHelper(); var entity = await crmRequestHelper.Retrieve(_crmService, entityName, Guid.Parse(orderPayEditRequest.delivery)); if (entity != null) { var deliverystatus = entity.Attributes.Value <int>("mcs_deliverystatus"); //已检测 if (deliverystatus >= 5) { validateResult.Result = false; validateResult.Description = "交车单状态不符合!"; return(validateResult); } var deliveryef = new CrmEntityReference(entity.EntityName, entity.Id); var createentity = new CrmExecuteEntity(orderpayEntityName, Guid.NewGuid()); createentity.Attributes.Add("mcs_paycategory", orderPayEditRequest.paycategory); createentity.Attributes.Add("mcs_payon", orderPayEditRequest.payon.ToUniversalTime()); createentity.Attributes.Add("mcs_vehdelivery", deliveryef); var vehorderId = entity.Attributes.Value <string>("_mcs_vehorder_value"); if (!string.IsNullOrEmpty(vehorderId)) { var vehorderrf = new CrmEntityReference(roEntityName, Guid.Parse(vehorderId)); createentity.Attributes.Add("mcs_vehorder", vehorderrf); } var dealerid = entity.Attributes.Value <string>("_mcs_dealer_value"); if (!string.IsNullOrEmpty(dealerid)) { var dealerrf = new CrmEntityReference(dealerEntityName, Guid.Parse(dealerid)); createentity.Attributes.Add("mcs_dealer", dealerrf); } createentity.Attributes.Add("mcs_amount", orderPayEditRequest.amount); createentity.Attributes.Add("mcs_batchcode", orderPayEditRequest.batchcode); await _crmService.Create(createentity); validateResult.Result = true; validateResult.Description = "操作成功"; return(validateResult); } else { validateResult.Result = false; validateResult.Description = "交车单不存在!"; return(validateResult); } } catch (Exception ex) { throw ex; } }
/// <summary> /// 创建原始线索 /// </summary> public async Task <OriginalclueCreateResponse> create(OriginalclueCreateRequest originalclueCreateRequest) { try { var createEntity = new CrmExecuteEntity(entityName, Guid.NewGuid()); createEntity.Attributes.Add("lastname", originalclueCreateRequest.username); createEntity.Attributes.Add("mobilephone", originalclueCreateRequest.mobile); if (!string.IsNullOrEmpty(originalclueCreateRequest.mail)) { createEntity.Attributes.Add("emailaddress1", originalclueCreateRequest.mail); } createEntity.Attributes.Add("mcs_leadorigin", Int32.Parse(originalclueCreateRequest.clues)); createEntity.Attributes.Add("mcs_accountpoints", Int32.Parse(originalclueCreateRequest.score)); createEntity.Attributes.Add("description", originalclueCreateRequest.describe); createEntity.Attributes.Add("mcs_gender", originalclueCreateRequest.gender); if (!string.IsNullOrWhiteSpace(originalclueCreateRequest.province)) { var salesarea = new CrmEntityReference("mcs_salesarea", Guid.Parse(originalclueCreateRequest.province)); createEntity.Attributes.Add("mcs_provinceid", salesarea); } if (!string.IsNullOrWhiteSpace(originalclueCreateRequest.city)) { var salesarea = new CrmEntityReference("mcs_salesarea", Guid.Parse(originalclueCreateRequest.city)); createEntity.Attributes.Add("mcs_cityid", salesarea); } if (!string.IsNullOrWhiteSpace(originalclueCreateRequest.area)) { var salesarea = new CrmEntityReference("mcs_salesarea", Guid.Parse(originalclueCreateRequest.area)); createEntity.Attributes.Add("mcs_districtid", salesarea); } var dealer = new CrmEntityReference("mcs_dealer", Guid.Parse(originalclueCreateRequest.dealerid)); createEntity.Attributes.Add("mcs_dealerid", dealer); //var mcs_behaviorEntityRefence = new CrmEntityReference("mcs_behavior", Guid.Parse(originalclueCreateRequest.behaviorid)); var mcs_behaviorEntityRefence = await GetBehaviorEntityByCode(originalclueCreateRequest.behaviorcode); if (mcs_behaviorEntityRefence != null) { createEntity.Attributes.Add("mcs_behaviorid", mcs_behaviorEntityRefence); } var entityId = await _crmService.Create(createEntity, Guid.Parse(originalclueCreateRequest.UserId)); return(new OriginalclueCreateResponse() { Id = entityId.ToString() }); } catch (Exception ex) { throw ex; } }
public async Task <ValidateResult <string> > submitpdi(DeliveryEditRequest deliveryEditRequest) { try { var validateResult = new ValidateResult <string>(); var crmRequestHelper = new CrmRequestHelper(); var entity = await crmRequestHelper.Retrieve(_crmService, entityName, Guid.Parse(deliveryEditRequest.id)); if (entity != null) { var deliverystatus = entity.Attributes.Value <int>("mcs_deliverystatus"); //待检测 if (deliverystatus != 2) { validateResult.Result = false; validateResult.Description = "交车单状态不符合!"; return(validateResult); } var delivery = new CrmExecuteEntity(entityName, Guid.Parse(deliveryEditRequest.id)); var systemuser = new CrmEntityReference(systemuserEntityName, Guid.Parse(deliveryEditRequest.adviser)); delivery.Attributes.Add("mcs_serviceproxyid", systemuser); delivery.Attributes.Add("mcs_deliverystatus", 3); delivery.Attributes.Add("mcs_submitpdi", true); delivery.Attributes.Add("mcs_submitpdion", DateTime.UtcNow); await _crmService.Update(delivery); validateResult.Result = true; validateResult.Description = "操作成功"; return(validateResult); } else { validateResult.Result = false; validateResult.Description = "交车单不存在!"; return(validateResult); } } catch (Exception ex) { throw ex; } }
public async Task <object> Execute(JToken json, Dictionary <string, object> extensionParameters = null) { if (json.Type == JTokenType.Null) { return(await Task.FromResult(default(CrmEntityReference))); } if (json["@odata.id"] == null) { var fragment = new TextFragment() { Code = TextCodes.CrmJTokenConvertEntityReferenceNotFoundAttribute, DefaultFormatting = "在Crm的JToken转换EntityReference服务{0}中,传入的JToken中找不到属性{1},JToken值为{2}", ReplaceParameters = new List <object>() { this.GetType().FullName, "@odata.id", json.ToString() } }; throw new UtilityException((int)Errors.CrmJTokenConvertEntityReferenceNotFoundAttribute, fragment); } if (json["@odata.id"].Type == JTokenType.Null) { return(await Task.FromResult(default(CrmEntityReference))); } var strEntityReferenceId = json["@odata.id"].Value <string>(); Regex reg = new Regex(@"/([A-Za-z0-9_]+)\((\{?[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}}?)\)"); var matchs = reg.Match(strEntityReferenceId); CrmEntityReference result = null; if (matchs.Groups.Count >= 3) { result = new CrmEntityReference(matchs.Groups[1].Value, Guid.Parse(matchs.Groups[2].Value)); } return(result); }
/// <summary> /// 预约单基础数据赋值 /// </summary> /// <param name="createEntity"></param> /// <param name="request"></param> private CrmExecuteEntity BasicAssignment(CrmExecuteEntity entity, AppointmentInfoAddOrEditRequest request) { //VIN码 if (request.appointmentinfo.mcs_customerid != null) { var vinEntityRef = new CrmEntityReference("mcs_vehowner", (Guid)request.appointmentinfo.mcs_customerid); entity.Attributes.Add("mcs_customerid", vinEntityRef); } //车主 if (!string.IsNullOrWhiteSpace(request.appointmentinfo.mcs_customername)) { entity.Attributes.Add("mcs_customername", request.appointmentinfo.mcs_customername); } //车牌 if (!string.IsNullOrWhiteSpace(request.appointmentinfo.mcs_carplate)) { entity.Attributes.Add("mcs_carplate", request.appointmentinfo.mcs_carplate); } //车型 if (request.appointmentinfo.mcs_cartype != null) { var carTypeEntityRef = new CrmEntityReference("mcs_carmodel", (Guid)request.appointmentinfo.mcs_cartype); entity.Attributes.Add("mcs_cartype", carTypeEntityRef); } //手机号 if (!string.IsNullOrWhiteSpace(request.appointmentinfo.mcs_customerphone)) { entity.Attributes.Add("mcs_customerphone", request.appointmentinfo.mcs_customerphone); } //客户标签 if (!string.IsNullOrWhiteSpace(request.appointmentinfo.mcs_tag)) { entity.Attributes.Add("mcs_tag", request.appointmentinfo.mcs_tag); } //预约服务类型 if (request.appointmentinfo.mcs_ordertype != null) { entity.Attributes.Add("mcs_ordertype", request.appointmentinfo.mcs_ordertype); } //预约日期 if (request.appointmentinfo.mcs_appointmentat != null) { var mcs_appointmentat = request.appointmentinfo.mcs_appointmentat.Value.ToUniversalTime();//.ToString("yyyy-MM-dd"); entity.Attributes.Add("mcs_appointmentat", mcs_appointmentat); } //预约时段 if (request.appointmentinfo.mcs_appointmentconfigid != null) { var configEntityRef = new CrmEntityReference("mcs_appointmentconfig", (Guid)request.appointmentinfo.mcs_appointmentconfigid); entity.Attributes.Add("mcs_appointmentconfigid", configEntityRef); } //可预约数量 if (request.appointmentinfo.mcs_surplusnum != null) { entity.Attributes.Add("mcs_surplusnum", request.appointmentinfo.mcs_surplusnum); } //客户要求 if (!string.IsNullOrWhiteSpace(request.appointmentinfo.mcs_customercomment)) { entity.Attributes.Add("mcs_customercomment", request.appointmentinfo.mcs_customercomment); } //问题描述 if (!string.IsNullOrWhiteSpace(request.appointmentinfo.mcs_appointmendescript)) { entity.Attributes.Add("mcs_appointmendescript", request.appointmentinfo.mcs_appointmendescript); } //取消原因 if (request.appointmentinfo.mcs_cancelreasonnew != null) { entity.Attributes.Add("mcs_cancelreasonnew", request.appointmentinfo.mcs_cancelreasonnew); } //取消描述 if (!string.IsNullOrWhiteSpace(request.appointmentinfo.mcs_canceldes)) { entity.Attributes.Add("mcs_canceldes", request.appointmentinfo.mcs_canceldes); } //预约厅店 if (request.appointmentinfo.mcs_dealerid != null) { var dealerEntityEF = new CrmEntityReference("mcs_dealer", (Guid)request.appointmentinfo.mcs_dealerid); entity.Attributes.Add("mcs_dealerid", dealerEntityEF); } //服务顾问 if (request.appointmentinfo.mcs_serviceadvisorid != null) { var systemUserEntityEF = new CrmEntityReference("systemuser", (Guid)request.appointmentinfo.mcs_serviceadvisorid); entity.Attributes.Add("mcs_serviceadvisorid", systemUserEntityEF); } return(entity); }
/// <summary> /// 修改用户信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <ValidateResult> UpdateUser(UserAddRequest model) { var validateResult = new ValidateResult(); try { var entity = new CrmExecuteEntity(entityName, model.userid); if (!string.IsNullOrEmpty(model.phone)) { entity.Attributes.Add("mcs_phone", model.phone); } if (!string.IsNullOrEmpty(model.birthday)) { entity.Attributes.Add("mcs_birthday", DateTime.Parse(model.birthday).ToUniversalTime()); } if (!string.IsNullOrEmpty(model.company)) { entity.Attributes.Add("mcs_company", model.company); } if (!string.IsNullOrEmpty(model.description)) { entity.Attributes.Add("mcs_description", model.description); } if (model.gender != null) { entity.Attributes.Add("mcs_gender", model.gender); } if (model.marriagestatus != null) { entity.Attributes.Add("mcs_marriagestatus", model.marriagestatus); } if (!string.IsNullOrEmpty(model.mcs_cardid)) { entity.Attributes.Add("mcs_cardid", model.mcs_cardid); } entity.Attributes.Add("mcs_email", model.mcs_email); if (!string.IsNullOrEmpty(model.name)) { entity.Attributes.Add("mcs_name", model.name); } if (!string.IsNullOrEmpty(model.nickname)) { entity.Attributes.Add("mcs_nickname", model.nickname); } if (!string.IsNullOrEmpty(model.profession)) { entity.Attributes.Add("mcs_profession", model.profession); } if (!string.IsNullOrEmpty(model.signature)) { entity.Attributes.Add("mcs_signature", model.signature); } if (!string.IsNullOrEmpty(model.province)) { var province = new CrmEntityReference("mcs_sysarea", Guid.Parse(model.province)); entity.Attributes.Add("mcs_province", province); } if (!string.IsNullOrEmpty(model.city)) { var city = new CrmEntityReference("mcs_sysarea", Guid.Parse(model.city)); entity.Attributes.Add("mcs_city", city); } if (!string.IsNullOrEmpty(model.area)) { var area = new CrmEntityReference("mcs_sysarea", Guid.Parse(model.area)); entity.Attributes.Add("mcs_area", area); } //c端用户实体 await _crmService.Update(entity); //#region 积分完善个人资料埋点 ////判断完善个人资料积分是否发送,如果已发送,不能再次发送 //string code = await GetConfig(IntegralUserInfo_Key); //var crmRequestHelper = new CrmRequestHelper(); //XDocument fetchXdoc = null; //fetchXdoc = await _repository.GetMemberintegraldetail(entity.Id, code); //var entities = await crmRequestHelper.ExecuteAsync(_crmService, "mcs_memberintegraldetail", fetchXdoc); //if (entities.Results.Count == 0) //{ // await IntegralCreate(IntegralUserInfo_Key, entity.Id.ToString()); //} //#endregion #region 组装数据返回 validateResult.Result = true; validateResult.Description = "操作成功"; #endregion } catch (Exception e) { validateResult.Result = false; validateResult.Description = e.Message; } return(validateResult); }
public async Task <ValidateResult <CrmEntity> > create(LeadRequest request) { var validateResult = new ValidateResult <CrmEntity>(); try { var createEntity = new CrmExecuteEntity("lead", Guid.NewGuid()); if (!string.IsNullOrEmpty(request.mcs_mobilephone)) { createEntity.Attributes.Add("mobilephone", request.mcs_mobilephone); } if (!string.IsNullOrEmpty(request.emailaddress1)) { createEntity.Attributes.Add("emailaddress1", request.emailaddress1); } if (request.mcs_leadorigin != null) { createEntity.Attributes.Add("mcs_leadorigin", request.mcs_leadorigin); } if (request.mcs_accountpoints != null) { createEntity.Attributes.Add("mcs_accountpoints", request.mcs_accountpoints); } if (!string.IsNullOrEmpty(request.description)) { createEntity.Attributes.Add("description", request.description); } if (request.mcs_gender != null) { createEntity.Attributes.Add("mcs_gender", request.mcs_gender); } if (!string.IsNullOrWhiteSpace(request.mcs_provinceid)) { var salesarea = new CrmEntityReference("mcs_salesarea", Guid.Parse(request.mcs_provinceid)); createEntity.Attributes.Add("mcs_provinceid", salesarea); } if (!string.IsNullOrWhiteSpace(request.mcs_cityid)) { var salesarea = new CrmEntityReference("mcs_salesarea", Guid.Parse(request.mcs_cityid)); createEntity.Attributes.Add("mcs_cityid", salesarea); } if (!string.IsNullOrWhiteSpace(request.mcs_areaid)) { var salesarea = new CrmEntityReference("mcs_salesarea", Guid.Parse(request.mcs_areaid)); createEntity.Attributes.Add("mcs_districtid", salesarea); } if (!string.IsNullOrWhiteSpace(request.mcs_dealerid)) { var dealer = new CrmEntityReference("mcs_dealer", Guid.Parse(request.mcs_dealerid)); createEntity.Attributes.Add("mcs_dealerid", dealer); } var mcs_behaviorEntityRefence = await GetBehaviorEntityByCode(request.behaviorcode); if (mcs_behaviorEntityRefence != null) { createEntity.Attributes.Add("mcs_behaviorid", mcs_behaviorEntityRefence); } //预约意向车型 if (!string.IsNullOrWhiteSpace(request.mcs_blindordervehtype)) { createEntity.Attributes.Add("mcs_blindordervehtype", request.mcs_blindordervehtype); } //订单号 if (!string.IsNullOrWhiteSpace(request.mcs_order)) { createEntity.Attributes.Add("mcs_order", request.mcs_order); } //预约号 if (!string.IsNullOrWhiteSpace(request.mcs_premiumcode)) { createEntity.Attributes.Add("mcs_premiumcode", request.mcs_premiumcode); } //用车城市 if (!string.IsNullOrWhiteSpace(request.mcs_usecarcity)) { createEntity.Attributes.Add("mcs_usecarcity", request.mcs_usecarcity); } //下单时间 if (request.mcs_ordertime != null) { var ordertime = request.mcs_ordertime.Value.ToUniversalTime(); createEntity.Attributes.Add("mcs_ordertime", ordertime); } //订单状态 if (request.mcs_optiontype != null) { createEntity.Attributes.Add("mcs_optiontype", request.mcs_optiontype); } //线索媒体 if (!string.IsNullOrWhiteSpace(request.mediacode)) { var mediaef = await GetMediaEntityByCode(request.mediacode);; if (mediaef != null) { createEntity.Attributes.Add("mcs_mediaid", mediaef); } } //线索终端 if (!string.IsNullOrWhiteSpace(request.terminalcode)) { var terminalef = await GetTerminalEntityByCode(request.terminalcode); if (terminalef != null) { createEntity.Attributes.Add("mcs_terminalid", terminalef); } } //引流渠道 if (request.mcs_channel != null) { createEntity.Attributes.Add("mcs_channel", request.mcs_channel); } //用户Id if (!string.IsNullOrWhiteSpace(request.mcs_userid)) { createEntity.Attributes.Add("mcs_userid", request.mcs_userid); } //全名 if (!string.IsNullOrWhiteSpace(request.mcs_fullname)) { createEntity.Attributes.Add("lastname", request.mcs_fullname); } //数据来源 createEntity.Attributes.Add("mcs_leadsource", request.mcs_leadsource); //预售描述 if (!string.IsNullOrWhiteSpace(request.mcs_orderdescription)) { createEntity.Attributes.Add("mcs_orderdescription", request.mcs_orderdescription); } var entityId = await _crmService.Create(createEntity); validateResult.Result = true; validateResult.Description = "操作成功"; } catch (Exception ex) { validateResult.Result = false; validateResult.Description = "操作失败"; } return(validateResult); }
/// <summary> /// 试乘试驾新增修改 /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <ValidateResult <CrmEntity> > AddOrEdit(DriveRecordAddOrEditRequest request) { var userInfo = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo); if (userInfo != null && !string.IsNullOrWhiteSpace(userInfo.mcs_dealerid)) { request.driveRecord.mcs_dealerid = Guid.Parse(userInfo.mcs_dealerid); } if (userInfo != null && userInfo.systemuserid != null) { request.driveRecord.mcs_consultantid = userInfo.systemuserid; } var validateResult = new ValidateResult <CrmEntity>(); var reusetCrmEntity = new CrmEntity("mcs_driverecord", new Guid()); //新增预约单 if (request.driveRecord.mcs_driverecordid == null) { var createEntity = new CrmExecuteEntity("mcs_driverecord", Guid.NewGuid()); //预约状态 创建默认是已提交 createEntity.Attributes.Add("mcs_drivestatus", 10); BasicAssignment(createEntity, request); await _crmService.Create(createEntity, userInfo?.systemuserid); reusetCrmEntity.Id = createEntity.Id; } //编辑预约单 if (request.driveRecord.mcs_driverecordid != null) { var updateEntity = new CrmExecuteEntity("mcs_driverecord", (Guid)request.driveRecord.mcs_driverecordid); //预约状态 if (request.driveRecord.mcs_drivestatus != null) { updateEntity.Attributes.Add("mcs_drivestatus", request.driveRecord.mcs_drivestatus); #region 判断如果试驾结束,为用户推送试驾反馈站内信 if (request.driveRecord.mcs_drivestatus.Value == 15) { //获取试驾结束站内信发送配置json var fetchString = _driveRecordRepository.GetConfigFetchXml(DCEM_APP_DriveOverMsgJson); var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage() { EntityName = "mcs_cepconfig", FetchXml = fetchString //ProxyUserId = userInfo?.systemuserid }; fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]); var fetchResponse = await _crmService.Execute(fetchRequest); var fetchResponseResult = fetchResponse as CrmRetrieveMultipleFetchResponseMessage; if (fetchResponseResult.Value.Results.Count > 0) { //获取试驾明细 var detail = GetDetail((Guid)request.driveRecord.mcs_driverecordid); if (detail != null && detail.Result.Detail.Attributes.ContainsKey("mcs_userid")) { //用户获取 fetchString = _driveRecordRepository.GetUser(detail.Result.Detail.Attributes["mcs_userid"].ToString()); fetchRequest = new CrmRetrieveMultipleFetchRequestMessage() { EntityName = "mcs_user", FetchXml = fetchString //ProxyUserId = userInfo?.systemuserid }; fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]); fetchResponse = await _crmService.Execute(fetchRequest); var responseUser = fetchResponse as CrmRetrieveMultipleFetchResponseMessage; if (responseUser.Value.Results.Count > 0)//判断试驾用户信息是否存在 { var obj = JsonConvert.DeserializeObject <DriveRecordEndSendMsg>(fetchResponseResult.Value.Results[0].Attributes["mcs_val"].ToString()); var createUsermsgEntity = new CrmExecuteEntity("mcs_user_msg", Guid.NewGuid()); createUsermsgEntity.Attributes.Add("mcs_name", obj.mcs_name); createUsermsgEntity.Attributes.Add("mcs_content", obj.mcs_content); createUsermsgEntity.Attributes.Add("mcs_type", 2); createUsermsgEntity.Attributes.Add("mcs_readstatus", 0); var mcs_url = string.Format(obj.mcs_url, responseUser.Value.Results[0].Attributes["mcs_code"], detail.Result.Detail.Attributes["mcs_name"]); createUsermsgEntity.Attributes.Add("mcs_url", mcs_url); var UserEntityEF = new CrmEntityReference("mcs_user", responseUser.Value.Results[0].Id); createUsermsgEntity.Attributes.Add("mcs_user", UserEntityEF); await _crmService.Create(createUsermsgEntity); } } } } #endregion } BasicAssignment(updateEntity, request); await _crmService.Update(updateEntity, userInfo?.systemuserid); reusetCrmEntity.Id = (Guid)request.driveRecord.mcs_driverecordid; } validateResult.Data = reusetCrmEntity; validateResult.Result = true; validateResult.Description = "操作成功"; return(validateResult); }
/// <summary> /// 基础字段赋值 /// </summary> /// <param name="createEntity"></param> /// <param name="request"></param> private CrmExecuteEntity BasicAssignment(CrmExecuteEntity entity, DriveRecordAddOrEditRequest request) { //姓名 if (!string.IsNullOrWhiteSpace(request.driveRecord.mcs_fullname)) { entity.Attributes.Add("mcs_fullname", request.driveRecord.mcs_fullname); } //手机号 if (!string.IsNullOrWhiteSpace(request.driveRecord.mcs_mobilephone)) { entity.Attributes.Add("mcs_mobilephone", request.driveRecord.mcs_mobilephone); } //试驾车型 if (request.driveRecord.mcs_carmodel != null) { var carModelEntityRef = new CrmEntityReference("mcs_carmodel", (Guid)request.driveRecord.mcs_carmodel); entity.Attributes.Add("mcs_carmodel", carModelEntityRef); } //业务类型 if (!string.IsNullOrWhiteSpace(request.driveRecord.mcs_businesstype)) { var mcs_businesstype = int.Parse(request.driveRecord.mcs_businesstype); entity.Attributes.Add("mcs_businesstype", mcs_businesstype); } //预约日期 if (request.driveRecord.mcs_ordertime != null) { var ordertime = request.driveRecord.mcs_ordertime.Value.ToUniversalTime(); entity.Attributes.Add("mcs_ordertime", ordertime); } //预约试驾时段 if (request.driveRecord.mcs_testdrivetime != null) { var configEntityRef = new CrmEntityReference("mcs_reservationconfiguration", (Guid)request.driveRecord.mcs_testdrivetime); entity.Attributes.Add("mcs_testdrivetime", configEntityRef); } //预约厅店 if (request.driveRecord.mcs_dealerid != null) { var dealerEntityEF = new CrmEntityReference("mcs_dealer", (Guid)request.driveRecord.mcs_dealerid); entity.Attributes.Add("mcs_dealerid", dealerEntityEF); } //销售顾问 if (request.driveRecord.mcs_consultantid != null) { var systemUserEntityEF = new CrmEntityReference("systemuser", (Guid)request.driveRecord.mcs_consultantid); entity.Attributes.Add("mcs_consultantid", systemUserEntityEF); } //试驾车辆 if (request.driveRecord.mcs_drivecar != null) { var drivecarEntityEF = new CrmEntityReference("mcs_testdrivecar", (Guid)request.driveRecord.mcs_drivecar); entity.Attributes.Add("mcs_drivecar", drivecarEntityEF); } //试驾路线 if (request.driveRecord.mcs_appointedrouteid != null) { var appointedRouteEntityEF = new CrmEntityReference("mcs_driveroute", (Guid)request.driveRecord.mcs_appointedrouteid); entity.Attributes.Add("mcs_appointedrouteid", appointedRouteEntityEF); } //取消原因 if (!string.IsNullOrWhiteSpace(request.driveRecord.mcs_cancelreason)) { entity.Attributes.Add("mcs_cancelreason", request.driveRecord.mcs_cancelreason); } //试驾开始时间 if (request.driveRecord.mcs_starton != null) { var starton = request.driveRecord.mcs_starton.Value.ToUniversalTime();; entity.Attributes.Add("mcs_starton", starton); } //试驾结束时间 if (request.driveRecord.mcs_endon != null) { var endon = request.driveRecord.mcs_endon; entity.Attributes.Add("mcs_endon", endon); } return(entity); }