Esempio n. 1
0
        /// <summary>
        /// 用户消息新增编辑
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ValidateResult <CrmEntity> > AddAndEdit(UserMsgequest request)
        {
            var validateResult  = new ValidateResult <CrmEntity>();
            var reusetCrmEntity = new CrmEntity("mcs_user_msg", new Guid());

            //新增
            if (string.IsNullOrWhiteSpace(request.mcs_user_msgid))
            {
                var createEntity = new CrmExecuteEntity("mcs_user_msg", Guid.NewGuid());
                BasicAssignment(createEntity, request);
                var reuset = await _crmService.Create(createEntity);

                reusetCrmEntity.Id = createEntity.Id;
            }
            //编辑
            if (!string.IsNullOrWhiteSpace(request.mcs_user_msgid))
            {
                var updateEntity = new CrmExecuteEntity("mcs_user_msg", Guid.Parse(request.mcs_user_msgid));
                BasicAssignment(updateEntity, request);
                await _crmService.Update(updateEntity);

                reusetCrmEntity.Id = updateEntity.Id;
            }
            validateResult.Data        = reusetCrmEntity;
            validateResult.Result      = true;
            validateResult.Description = "操作成功";
            return(validateResult);
        }
Esempio n. 2
0
        public async Task <ValidateResult <string> > Voice(VoiceRequest request)
        {
            var validateResult = new ValidateResult <string>();

            if (!string.IsNullOrEmpty(request.phone) && !string.IsNullOrEmpty(request.content))
            {
                var fetchXdoc    = _Repository.GetAccountFetchXml(request.phone);
                var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
                {
                    EntityName = "account",
                    FetchXml   = fetchXdoc.Result
                };
                var fetchResponse = await _crmService.Execute(fetchRequest);

                var detailResult = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
                var entity       = detailResult.Value.Results[0];
                if (entity != null)
                {
                    //插入logcall数据
                    var logcall = new CrmExecuteEntity("mcs_logcall", Guid.NewGuid());
                    logcall.Attributes.Add("mcs_fullname", "爱车APP语音转换");
                    logcall.Attributes.Add("mcs_mobilephone", request.phone);
                    logcall.Attributes.Add("mcs_content", request.content);
                    logcall.Attributes.Add("mcs_results", request.content);
                    logcall.Attributes.Add("mcs_visittime", DateTime.Now.ToUniversalTime());
                    logcall.Attributes.Add("mcs_accountid", new CrmEntityReference(entity.EntityName, entity.Id));
                    await _crmService.Create(logcall, null);
                }
            }
            validateResult.Result      = true;
            validateResult.Description = "操作成功";
            return(validateResult);
        }
Esempio n. 3
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ValidateResult> Add(UsermessageRequest model)
        {
            var userInfo       = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
            var validateResult = new ValidateResult();


            try
            {
                Guid id     = Guid.NewGuid();
                var  entity = new CrmExecuteEntity(entityName, id);
                if (!string.IsNullOrEmpty(model.phone))
                {
                    entity.Attributes.Add("mcs_phone", model.phone);
                }
                if (!string.IsNullOrEmpty(model.valcode))
                {
                    entity.Attributes.Add("mcs_name", model.valcode);
                }
                entity.Attributes.Add("mcs_type", model.type);
                await _crmService.Create(entity, userInfo?.systemuserid);


                #region 组装数据返回
                validateResult.Result      = true;
                validateResult.Description = "操作成功";
                #endregion
            }
            catch (Exception e)
            {
                validateResult.Result      = false;
                validateResult.Description = e.Message;
            }

            return(validateResult);
        }
Esempio n. 4
0
        /// <summary>
        /// 登陆日志
        /// </summary>
        /// <param name="model"></param>
        /// <param name="id"></param>
        /// <param name="type">1 成功;2失败</param>
        public void LoginLog(UserLoginRequest model, Guid userid, int type)
        {
            var  userInfo = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
            Guid logid    = Guid.NewGuid();
            var  entity   = new CrmExecuteEntity("mcs_userloginlog", logid);

            entity.Attributes.Add("mcs_userid", new CrmEntityReference(entityName, userid));
            entity.Attributes.Add("mcs_ip", model.ip);
            entity.Attributes.Add("mcs_loginresult", type);
            entity.Attributes.Add("mcs_logintime", DateTime.Now.ToUniversalTime());
            _crmService.Create(entity, userInfo?.systemuserid);
        }
Esempio n. 5
0
        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;
            }
        }
Esempio n. 6
0
        /// <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;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 预约单创建与修改(包括取消预约)
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ValidateResult <CrmEntity> > AddOrEdit(AppointmentInfoAddOrEditRequest request)
        {
            var userInfo = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);

            if (userInfo != null && !string.IsNullOrWhiteSpace(userInfo.mcs_dealerid))
            {
                request.appointmentinfo.mcs_dealerid = Guid.Parse(userInfo.mcs_dealerid);
            }
            if (userInfo != null && userInfo.systemuserid != null)
            {
                request.appointmentinfo.mcs_serviceadvisorid = userInfo.systemuserid;
            }
            var validateResult  = new ValidateResult <CrmEntity>();
            var reusetCrmEntity = new CrmEntity("mcs_appointmentinfo", new Guid());

            //新增预约单
            if (request.appointmentinfo.mcs_appointmentinfoid == null)
            {
                var createEntity = new CrmExecuteEntity("mcs_appointmentinfo", Guid.NewGuid());
                //预约状态 创建默认是待跟进
                createEntity.Attributes.Add("mcs_status", 10);
                BasicAssignment(createEntity, request);
                var reuset = await _crmService.Create(createEntity, userInfo?.systemuserid);

                reusetCrmEntity.Id = createEntity.Id;
            }
            //编辑预约单
            if (request.appointmentinfo.mcs_appointmentinfoid != null)
            {
                var updateEntity = new CrmExecuteEntity("mcs_appointmentinfo", (Guid)request.appointmentinfo.mcs_appointmentinfoid);
                //预约状态
                if (request.appointmentinfo.mcs_status != null)
                {
                    updateEntity.Attributes.Add("mcs_status", request.appointmentinfo.mcs_status);
                }
                BasicAssignment(updateEntity, request);
                await _crmService.Update(updateEntity, userInfo?.systemuserid);

                reusetCrmEntity.Id = (Guid)request.appointmentinfo.mcs_appointmentinfoid;
            }
            validateResult.Data        = reusetCrmEntity;
            validateResult.Result      = true;
            validateResult.Description = "操作成功";
            return(validateResult);
        }
Esempio n. 8
0
        /// <summary>
        /// 创建或编辑实体
        /// </summary>
        /// <param name="crmEntity"></param>
        /// <returns></returns>
        public async Task <Guid> AddOrEditEntity(TechnicalSupportRequest request)
        {
            #region 创建编辑主要实体
            Guid guid = Guid.Empty;
            try
            {
                guid = string.IsNullOrEmpty(request.Id) ? Guid.NewGuid() : Guid.Parse(request.Id);
                CrmExecuteEntity createorUpdateEntity = new CrmExecuteEntity(request.EntityName, guid);

                if (!string.IsNullOrEmpty(request.mcs_title))
                {
                    createorUpdateEntity.Attributes.Add("mcs_title", request.mcs_title);
                }

                if (!string.IsNullOrEmpty(request.mcs_serviceadvisorid))
                {
                    createorUpdateEntity.Attributes.Add("mcs_serviceadvisorid", new CrmEntityReference("systemuser", Guid.Parse(request.mcs_serviceadvisorid)));
                }

                if (!string.IsNullOrEmpty(request.mcs_repairnameid))
                {
                    createorUpdateEntity.Attributes.Add("mcs_repairnameid", new CrmEntityReference("systemuser", Guid.Parse(request.mcs_repairnameid)));
                }
                if (!string.IsNullOrEmpty(request.mcs_serviceorderid))
                {
                    createorUpdateEntity.Attributes.Add("mcs_serviceorderid", new CrmEntityReference("mcs_serviceproxy", Guid.Parse(request.mcs_serviceorderid)));
                }
                if (!string.IsNullOrEmpty(request.mcs_batterymodel))
                {
                    createorUpdateEntity.Attributes.Add("mcs_batterymodel", request.mcs_batterymodel);
                }
                if (!string.IsNullOrEmpty(request.mcs_batteryserialnumber))
                {
                    createorUpdateEntity.Attributes.Add("mcs_batteryserialnumber", request.mcs_batteryserialnumber);
                }
                if (!string.IsNullOrEmpty(request.mcs_carplate))
                {
                    createorUpdateEntity.Attributes.Add("mcs_carplate", request.mcs_carplate);
                }
                if (!string.IsNullOrEmpty(request.mcs_customerid))
                {
                    createorUpdateEntity.Attributes.Add("mcs_customerid", new CrmEntityReference("mcs_vehowner", Guid.Parse(request.mcs_customerid)));
                }
                if (!string.IsNullOrEmpty(request.mcs_customername))
                {
                    createorUpdateEntity.Attributes.Add("mcs_customername", request.mcs_customername);
                }
                if (!string.IsNullOrEmpty(request.mcs_customerphone))
                {
                    createorUpdateEntity.Attributes.Add("mcs_customerphone", request.mcs_customerphone);
                }
                if (!string.IsNullOrEmpty(request.mcs_diagnosiscontent))
                {
                    createorUpdateEntity.Attributes.Add("mcs_diagnosiscontent", request.mcs_diagnosiscontent);
                }
                if (!string.IsNullOrEmpty(request.mcs_email))
                {
                    createorUpdateEntity.Attributes.Add("mcs_email", request.mcs_email);
                }
                if (!string.IsNullOrEmpty(request.mcs_enginenumber))
                {
                    createorUpdateEntity.Attributes.Add("mcs_enginenumber", request.mcs_enginenumber);
                }
                if (request.mcs_ismodifiedparts.HasValue)
                {
                    createorUpdateEntity.Attributes.Add("mcs_ismodifiedparts", request.mcs_ismodifiedparts.Value);
                }
                if (!string.IsNullOrEmpty(request.mcs_malfunctioncontent))
                {
                    createorUpdateEntity.Attributes.Add("mcs_malfunctioncontent", request.mcs_malfunctioncontent);
                }
                if (!string.IsNullOrEmpty(request.mcs_malfunctiontypeid))
                {
                    createorUpdateEntity.Attributes.Add("mcs_malfunctiontypeid", new CrmEntityReference("mcs_malfunctiontype", Guid.Parse(request.mcs_malfunctiontypeid)));
                }
                if (request.mcs_mileage.HasValue)
                {
                    createorUpdateEntity.Attributes.Add("mcs_mileage", request.mcs_mileage.Value);
                }
                if (!string.IsNullOrEmpty(request.mcs_modifiedpartscontent))
                {
                    createorUpdateEntity.Attributes.Add("mcs_modifiedpartscontent", request.mcs_modifiedpartscontent);
                }
                if (!string.IsNullOrEmpty(request.mcs_phone))
                {
                    createorUpdateEntity.Attributes.Add("mcs_phone", request.mcs_phone);
                }
                if (request.mcs_repairdate.HasValue)
                {
                    createorUpdateEntity.Attributes.Add("mcs_repairdate", request.mcs_repairdate.Value);
                }
                if (!string.IsNullOrEmpty(request.mcs_techsystem))
                {
                    createorUpdateEntity.Attributes.Add("mcs_techsystem", int.Parse(request.mcs_techsystem));
                }
                if (!string.IsNullOrEmpty(request.mcs_cartypeid))
                {
                    createorUpdateEntity.Attributes.Add("mcs_cartypeid", new CrmEntityReference("mcs_cartype", Guid.Parse(request.mcs_cartypeid)));
                }

                if (!string.IsNullOrEmpty(request.Id))
                {
                    await _crmService.Update(createorUpdateEntity);
                }
                else
                {
                    guid = await _crmService.Create(createorUpdateEntity);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            #endregion



            return(guid);
        }
 public Guid CreateRecord(Entity entity)
 {
     return(crmService.Create(entity));
 }
Esempio n. 10
0
        public async Task <ValidateResult <CrmEntity> > AddOrUpdate(JObject jo)
        {
            var actionCode          = jo.Value <int>("actionCode");
            var vehownerJo          = jo.Value <JObject>("Vehowner");
            var carserviceadvisorJo = jo.Value <JObject>("Carserviceadvisor");

            var vehownerGuid          = Guid.NewGuid();
            var carserviceadvisorGuid = Guid.NewGuid();

            var vehownerEntity          = new CrmExecuteEntity("mcs_vehowner", vehownerGuid);
            var carserviceadvisorEntity = new CrmExecuteEntity("mcs_carserviceadvisor", carserviceadvisorGuid);
            var validateResult          = new ValidateResult <CrmEntity>();

            if (actionCode == 2)
            {
                vehownerGuid      = Guid.Parse(vehownerJo.Value <string>("mcs_vehownerid"));
                vehownerEntity.Id = vehownerGuid;

                carserviceadvisorGuid      = Guid.Parse(carserviceadvisorJo.Value <string>("mcs_carserviceadvisorid"));
                carserviceadvisorEntity.Id = carserviceadvisorGuid;
            }
            if (vehownerJo.ContainsKey("mcs_fullname"))
            {
                vehownerEntity.Attributes.Add("mcs_fullname", vehownerJo.Value <string>("mcs_fullname"));
                carserviceadvisorEntity.Attributes.Add("mcs_fullname", vehownerJo.Value <string>("mcs_fullname"));
            }
            if (vehownerJo.ContainsKey("mcs_vehplate"))
            {
                vehownerEntity.Attributes.Add("mcs_vehplate", vehownerJo.Value <string>("mcs_vehplate"));
            }
            if (vehownerJo.ContainsKey("mcs_mobilephone"))
            {
                vehownerEntity.Attributes.Add("mcs_mobilephone", vehownerJo.Value <string>("mcs_mobilephone"));
                carserviceadvisorEntity.Attributes.Add("mcs_mobilephone", vehownerJo.Value <string>("mcs_mobilephone"));
            }
            if (vehownerJo.ContainsKey("mcs_name"))
            {
                vehownerEntity.Attributes.Add("mcs_name", vehownerJo.Value <string>("mcs_name"));
            }
            if (vehownerJo.ContainsKey("mcs_enginennumber"))
            {
                vehownerEntity.Attributes.Add("mcs_enginennumber", vehownerJo.Value <string>("mcs_enginennumber"));
            }
            if (vehownerJo.ContainsKey("mcs_prodtime"))
            {
                vehownerEntity.Attributes.Add("mcs_prodtime", vehownerJo.Value <DateTime?>("mcs_prodtime"));
            }
            if (vehownerJo.ContainsKey("mcs_salesdate"))
            {
                vehownerEntity.Attributes.Add("mcs_salesdate", vehownerJo.Value <DateTime?>("mcs_salesdate"));
            }
            if (vehownerJo.ContainsKey("_mcs_vehtype_value"))
            {
                vehownerEntity.Attributes.Add("mcs_vehtype", new CrmEntityReference("mcs_carmodel", Guid.Parse(vehownerJo.Value <string>("_mcs_vehtype_value"))));
            }
            if (vehownerJo.ContainsKey("mcs_shuttlename"))
            {
                vehownerEntity.Attributes.Add("mcs_shuttlename", vehownerJo.Value <string>("mcs_shuttlename"));
                carserviceadvisorEntity.Attributes.Add("mcs_shuttlename", vehownerJo.Value <string>("mcs_shuttlename"));
            }
            if (vehownerJo.ContainsKey("mcs_shuttlephone"))
            {
                vehownerEntity.Attributes.Add("mcs_shuttlephone", vehownerJo.Value <string>("mcs_shuttlephone"));
                carserviceadvisorEntity.Attributes.Add("mcs_shuttlephone", vehownerJo.Value <string>("mcs_shuttlephone"));
            }


            if (actionCode == 1)
            {
                var dealeridGuid = Guid.Parse(jo.Value <string>("dealerid"));
                vehownerEntity.Attributes.Add("mcs_dealer", new CrmEntityReference("mcs_dealer", dealeridGuid));
                await _crmService.Create(vehownerEntity, null);

                carserviceadvisorEntity.Attributes.Add("mcs_customerid", new CrmEntityReference("mcs_vehowner", vehownerGuid));
                carserviceadvisorEntity.Attributes.Add("mcs_dealerid", new CrmEntityReference("mcs_dealer", dealeridGuid));
                await _crmService.Create(carserviceadvisorEntity, null);
            }
            else
            {
                await _crmService.Update(vehownerEntity, null);

                await _crmService.Update(carserviceadvisorEntity, null);
            }

            #region 组装数据返回
            validateResult.Result      = true;
            validateResult.Description = "操作成功";
            #endregion

            return(validateResult);
        }
Esempio n. 11
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ValidateResult> AddAnswercontent(QuestionAddRequest model)
        {
            var validateResult = new ValidateResult();

            try
            {
                var       crmRequestHelper = new CrmRequestHelper();
                XDocument fetchXdoc        = null;
                fetchXdoc = _questionRepository.QueryQiestion(model.mcs_questionnairesetting);
                var entities = await crmRequestHelper.ExecuteAsync(_crmService, "mcs_questionnairesetting", fetchXdoc);

                if (entities.Results.Count > 0)
                {
                    fetchXdoc = _questionRepository.QueryUser(model.mcs_answername);
                    var userentities = await crmRequestHelper.ExecuteAsync(_crmService, "mcs_user", fetchXdoc);

                    if (userentities.Results.Count > 0)
                    {
                        fetchXdoc = _questionRepository.QueryDeliverychannel(model.mcs_deliverychannel);
                        var deliverychannelentities = await crmRequestHelper.ExecuteAsync(_crmService, "mcs_deliverychannel", fetchXdoc);

                        //回答渠道获取
                        if (deliverychannelentities.Results.Count > 0)
                        {
                            foreach (var item in model.model)
                            {
                                Guid id     = Guid.NewGuid();
                                var  entity = new CrmExecuteEntity("mcs_answercontent", id);
                                entity.Attributes.Add("mcs_answername", new CrmEntityReference("mcs_user", userentities.Results[0].Id));
                                entity.Attributes.Add("mcs_deliverychannel", new CrmEntityReference("mcs_deliverychannel", deliverychannelentities.Results[0].Id));
                                entity.Attributes.Add("mcs_questionnairesetting", new CrmEntityReference("mcs_questionnairesetting", entities.Results[0].Id));

                                string starttime = entities.Results[0].Attributes["*****@*****.**"].ToString();
                                string endtime   = entities.Results[0].Attributes["*****@*****.**"].ToString();
                                if ((!string.IsNullOrEmpty(starttime)) && (!string.IsNullOrEmpty(starttime)))
                                {
                                    if (DateTime.Parse(starttime) <= DateTime.Now && DateTime.Parse(endtime) >= DateTime.Now)
                                    {
                                        string mcs_awardcategory = entities.Results[0].Attributes["*****@*****.**"].ToString();
                                        string mcs_awardamount   = entities.Results[0].Attributes["*****@*****.**"].ToString();
                                        string mcs_awardcount    = string.Format("奖励类别:{0},奖励数量{1}", mcs_awardcategory, mcs_awardamount);
                                        entity.Attributes.Add("mcs_awardcount", mcs_awardcount);
                                        entity.Attributes.Add("mcs_isaward", 1);
                                    }
                                    else
                                    {
                                        entity.Attributes.Add("mcs_isaward", 2);
                                    }
                                }
                                else
                                {
                                    entity.Attributes.Add("mcs_isaward", 2);
                                }

                                if (!string.IsNullOrEmpty(item.mcs_answer))
                                {
                                    entity.Attributes.Add("mcs_answer", item.mcs_answer);
                                }
                                if (!string.IsNullOrEmpty(item.mcs_answercontentcode))
                                {
                                    entity.Attributes.Add("mcs_answercontentcode", item.mcs_answercontentcode);
                                }
                                if (!string.IsNullOrEmpty(item.mcs_name))
                                {
                                    entity.Attributes.Add("mcs_name", item.mcs_name);
                                }
                                entity.Attributes.Add("mcs_questions", new CrmEntityReference("mcs_questions", item.mcs_questions));
                                await _crmService.Create(entity);
                            }
                            //判断是否有试驾记录,如果有写入试驾反馈
                            if (!string.IsNullOrEmpty(model.driverecordid))
                            {
                                fetchXdoc = _questionRepository.GetDriverecord(model.driverecordid);
                                var driverecord = await crmRequestHelper.ExecuteAsync(_crmService, "mcs_driverecord", fetchXdoc);

                                if (driverecord.Results.Count > 0)
                                {
                                    Guid id     = Guid.NewGuid();
                                    var  entity = new CrmExecuteEntity("mcs_testdrivefeedbackmaster", id);
                                    entity.Attributes.Add("mcs_username", userentities.Results[0].Attributes["mcs_name"].ToString());
                                    //新逻辑 存储id
                                    //entity.Attributes.Add("mcs_userid", userentities.Results[0].Attributes["mcs_code"].ToString());
                                    entity.Attributes.Add("mcs_userid", userentities.Results[0].Attributes["mcs_userid"].ToString());
                                    entity.Attributes.Add("mcs_driverecordid", new CrmEntityReference("mcs_driverecord", driverecord.Results[0].Id));
                                    entity.Attributes.Add("mcs_surveytime", DateTime.Now);
                                    entity.Attributes.Add("mcs_userphone", userentities.Results[0].Attributes["mcs_phone"].ToString());

                                    fetchXdoc = _questionRepository.GetOnlylead(userentities.Results[0].Id.ToString());
                                    var onlylead = await crmRequestHelper.ExecuteAsync(_crmService, "mcs_onlylead", fetchXdoc);

                                    if (onlylead.Results.Count > 0)
                                    {
                                        entity.Attributes.Add("mcs_onlyleadid", new CrmEntityReference("mcs_onlylead", onlylead.Results[0].Id));
                                    }
                                    await _crmService.Create(entity);

                                    foreach (var item in model.model)
                                    {
                                        Guid testdriveid     = Guid.NewGuid();
                                        var  testdriveentity = new CrmExecuteEntity("mcs_testdrivefeedback", testdriveid);
                                        testdriveentity.Attributes.Add("mcs_survey", model.mcs_questionnairesetting);
                                        testdriveentity.Attributes.Add("mcs_username", userentities.Results[0].Attributes["mcs_name"].ToString());
                                        testdriveentity.Attributes.Add("mcs_userphone", userentities.Results[0].Attributes["mcs_phone"].ToString());
                                        testdriveentity.Attributes.Add("mcs_userid", userentities.Results[0].Attributes["mcs_code"].ToString());
                                        testdriveentity.Attributes.Add("mcs_surveyquestion", item.mcs_name);
                                        testdriveentity.Attributes.Add("mcs_suveryanswer", item.mcs_answer);
                                        testdriveentity.Attributes.Add("mcs_surveytype", item.mcs_type);
                                        testdriveentity.Attributes.Add("mcs_driverecordid", new CrmEntityReference("mcs_driverecord", driverecord.Results[0].Id));
                                        if (onlylead.Results.Count > 0)
                                        {
                                            testdriveentity.Attributes.Add("mcs_onlyleadid", new CrmEntityReference("mcs_onlylead", onlylead.Results[0].Id));
                                        }
                                        testdriveentity.Attributes.Add("mcs_testdrivefeedbackmasterid", new CrmEntityReference("mcs_testdrivefeedbackmaster", id));
                                        await _crmService.Create(testdriveentity);
                                    }
                                }
                            }


                            #region 组装数据返回
                            validateResult.Result      = true;
                            validateResult.Description = "操作成功";
                            return(validateResult);

                            #endregion
                        }
                    }
                }
                validateResult.Result      = false;
                validateResult.Description = "来源数据异常!";
            }
            catch (Exception e)
            {
                validateResult.Result      = false;
                validateResult.Description = e.Message;
            }

            return(validateResult);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        /// <summary>
        /// 新增修改
        /// </summary>
        /// <param name="model"></param>
        public async Task <ValidateResult> AddOrUpdate(ShippingaddressAddRequest model)
        {
            var validateResult = new ValidateResult();

            try
            {
                var  userInfo = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
                Guid id       = Guid.NewGuid();
                var  entity   = new CrmExecuteEntity(entityName, id);
                if (model.userid.HasValue)
                {
                    entity.Attributes.Add("mcs_userid", new CrmEntityReference("mcs_user", model.userid.Value));
                }
                if (model.mcs_area.HasValue)
                {
                    entity.Attributes.Add("mcs_area", new CrmEntityReference("mcs_sysarea", model.mcs_area.Value));
                }
                if (model.mcs_city.HasValue)
                {
                    entity.Attributes.Add("mcs_city", new CrmEntityReference("mcs_sysarea", model.mcs_city.Value));
                }
                if (model.mcs_province.HasValue)
                {
                    entity.Attributes.Add("mcs_province", new CrmEntityReference("mcs_sysarea", model.mcs_province.Value));
                }
                if (!string.IsNullOrEmpty(model.mcs_address))
                {
                    entity.Attributes.Add("mcs_address", model.mcs_address);
                }
                if (model.mcs_isdefault != null)
                {
                    entity.Attributes.Add("mcs_isdefault", model.mcs_isdefault.Value == 0 ? true : false);
                }
                if (!string.IsNullOrEmpty(model.mcs_phone))
                {
                    entity.Attributes.Add("mcs_phone", model.mcs_phone);
                }
                if (!string.IsNullOrEmpty(model.mcs_name))
                {
                    entity.Attributes.Add("mcs_name", model.mcs_name);
                }
                //如果当前收货地址设置为默认,当前用户其它地址初始化为不默认
                if (model.mcs_isdefault.Value == 0)
                {
                    ShippingaddressListRequest req = new ShippingaddressListRequest();
                    req.PageIndex  = 1;
                    req.PageSize   = 100;
                    req.mcs_userid = model.userid.Value;
                    ValidateResult <List <CrmEntity> > list = GetList(req);
                    if (list.Data != null)
                    {
                        foreach (var item in list.Data)
                        {
                            var entaddress = new CrmExecuteEntity(entityName, item.Id);
                            entaddress.Attributes.Add("mcs_isdefault", false);
                            await _crmService.Update(entaddress);
                        }
                    }
                }

                if (string.IsNullOrEmpty(model.mcs_shippingaddressid))
                {
                    await _crmService.Create(entity, userInfo?.systemuserid);
                }
                else
                {
                    entity.Id = Guid.Parse(model.mcs_shippingaddressid);
                    await _crmService.Update(entity);
                }

                #region 组装数据返回
                validateResult.Result      = true;
                validateResult.Description = "操作成功";
                #endregion
            }
            catch (Exception e)
            {
                validateResult.Result      = false;
                validateResult.Description = e.Message;
            }
            return(validateResult);
        }
Esempio n. 14
0
        private void CreateNote(ICrmService crmService, string entityName, Guid entityId, string subject, string body)
        {
            // Create the Note object and set the parent object.
            var note = new annotation
            {
                objectid = new Lookup(entityName, entityId),
                objecttypecode = new EntityNameReference(entityName),
                subject = subject,
                notetext = body
            };

            // Set the note text and subject

            // Create the note
            crmService.Create(note);
        }
Esempio n. 15
0
        /// <summary>
        /// 修改新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ValidateResult> AddOrUpdate(ActivityEditRequest model)
        {
            var userInfo       = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
            var validateResult = new ValidateResult();

            try
            {
                var entity = new CrmExecuteEntity("mcs_activity", model.id);
                if (model.mcs_activitystatus != null)
                {
                    entity.Attributes.Add("mcs_activitystatus", model.mcs_activitystatus.Value);
                }
                if (model.mcs_endtime != null)
                {
                    entity.Attributes.Add("mcs_endtime", model.mcs_endtime.Value.ToUniversalTime());
                }
                if (model.mcs_excutestatus != null)
                {
                    entity.Attributes.Add("mcs_excutestatus", model.mcs_excutestatus.Value);
                }
                if (model.mcs_iffollowed != null)
                {
                    entity.Attributes.Add("mcs_iffollowed", model.mcs_iffollowed.Value);
                }
                if (model.mcs_ifsystemcreate != null)
                {
                    entity.Attributes.Add("mcs_ifsystemcreate", model.mcs_ifsystemcreate.Value);
                }
                if (model.mcs_importantlevel != null)
                {
                    entity.Attributes.Add("mcs_importantlevel", model.mcs_importantlevel.Value);
                }
                if (model.mcs_isaddedtodes != null)
                {
                    entity.Attributes.Add("mcs_isaddedtodes", model.mcs_isaddedtodes.Value);
                }
                if (!string.IsNullOrEmpty(model.mcs_name))
                {
                    entity.Attributes.Add("mcs_name", model.mcs_name);
                }
                if (model.mcs_nextfollowupcontent != null)
                {
                    entity.Attributes.Add("mcs_nextfollowupcontent", model.mcs_nextfollowupcontent);
                }
                if (model.mcs_nextfollowuptime != null)
                {
                    entity.Attributes.Add("mcs_nextfollowuptime", model.mcs_nextfollowuptime.Value.ToUniversalTime());
                }
                if (model.mcs_thisfollowupcontent != null)
                {
                    entity.Attributes.Add("mcs_thisfollowupcontent", model.mcs_thisfollowupcontent);
                }
                if (model.mcs_accountid != Guid.Empty && model.mcs_accountid != null)
                {
                    entity.Attributes.Add("mcs_accountid", new CrmEntityReference("mcs_account", model.mcs_accountid.Value));
                }
                if (model.mcs_onlyleadid != Guid.Empty && model.mcs_onlyleadid != null)
                {
                    entity.Attributes.Add("mcs_onlyleadid", new CrmEntityReference("mcs_onlylead", model.mcs_onlyleadid.Value));
                }
                if (model.mcs_contactid != Guid.Empty && model.mcs_contactid != null)
                {
                    entity.Attributes.Add("mcs_contactid", new CrmEntityReference("mcs_contact", model.mcs_contactid.Value));
                }
                //判断修改还是删除
                if (Guid.Empty == model.id)
                {
                    entity.Id = Guid.NewGuid();
                    await _crmService.Create(entity, userInfo?.systemuserid);
                }
                else
                {
                    entity.Id = model.id;
                    await _crmService.Update(entity, null);
                }


                #region 组装数据返回
                validateResult.Result      = true;
                validateResult.Description = "操作成功";
                #endregion
            }
            catch (Exception e)
            {
                validateResult.Result      = false;
                validateResult.Description = e.Message;
            }

            return(validateResult);
        }