Пример #1
0
        /// <summary>
        /// 删除地址
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ValidateResult> Delete(ShippingaddressAddRequest model)
        {
            var validateResult = new ValidateResult();

            try
            {
                await _crmService.Delete(entityName, Guid.Parse(model.mcs_shippingaddressid));

                #region 组装数据返回
                validateResult.Result      = true;
                validateResult.Description = "操作成功";
                #endregion
            }
            catch (Exception e)
            {
                validateResult.Result      = false;
                validateResult.Description = e.Message;
            }
            return(validateResult);
        }
Пример #2
0
        /// <summary>
        /// 创建或编辑实体
        /// </summary>
        /// <param name="crmEntity"></param>
        /// <returns></returns>
        public async Task <ValidateResult <CrmEntity> > AddOrUpdate(JObject jo)
        {
            var supportorderGuid   = Guid.NewGuid();
            var supportorderEntity = new CrmExecuteEntity("mcs_supportorder", supportorderGuid);
            var outGuid            = Guid.NewGuid();

            #region 更新主要实体
            if (jo.ContainsKey("Id") && Guid.TryParse(jo["Id"].ToString(), out outGuid))
            {
                supportorderGuid      = Guid.Parse(jo.Value <string>("Id"));
                supportorderEntity.Id = supportorderGuid;
            }
            if (jo.ContainsKey("mcs_title"))
            {
                supportorderEntity.Attributes.Add("mcs_title", jo.Value <string>("mcs_title"));
            }
            if (jo.ContainsKey("mcs_serviceadvisorid") && Guid.TryParse(jo["mcs_serviceadvisorid"].ToString(), out outGuid))
            {
                supportorderEntity.Attributes.Add("mcs_serviceadvisorid", new CrmEntityReference("systemuser", Guid.Parse(jo.Value <string>("mcs_serviceadvisorid"))));
            }
            if (jo.ContainsKey("mcs_repairnameid") && Guid.TryParse(jo["mcs_repairnameid"].ToString(), out outGuid))
            {
                supportorderEntity.Attributes.Add("mcs_repairnameid", new CrmEntityReference("systemuser", Guid.Parse(jo.Value <string>("mcs_repairnameid"))));
            }
            if (jo.ContainsKey("mcs_serviceorderid") && Guid.TryParse(jo["mcs_serviceorderid"].ToString(), out outGuid))
            {
                supportorderEntity.Attributes.Add("mcs_serviceorderid", new CrmEntityReference("mcs_serviceproxy", Guid.Parse(jo.Value <string>("mcs_serviceorderid"))));
            }
            if (jo.ContainsKey("mcs_batterymodel"))
            {
                supportorderEntity.Attributes.Add("mcs_batterymodel", jo.Value <string>("mcs_batterymodel"));
            }
            if (jo.ContainsKey("mcs_batteryserialnumber"))
            {
                supportorderEntity.Attributes.Add("mcs_batteryserialnumber", jo.Value <string>("mcs_batteryserialnumber"));
            }
            if (jo.ContainsKey("mcs_carplate"))
            {
                supportorderEntity.Attributes.Add("mcs_carplate", jo.Value <string>("mcs_carplate"));
            }
            if (jo.ContainsKey("mcs_customerid") && Guid.TryParse(jo["mcs_customerid"].ToString(), out outGuid))
            {
                supportorderEntity.Attributes.Add("mcs_customerid", new CrmEntityReference("mcs_vehowner", Guid.Parse(jo.Value <string>("mcs_customerid"))));
            }
            if (jo.ContainsKey("mcs_customername"))
            {
                supportorderEntity.Attributes.Add("mcs_customername", jo.Value <string>("mcs_customername"));
            }
            if (jo.ContainsKey("mcs_customerphone"))
            {
                supportorderEntity.Attributes.Add("mcs_customerphone", jo.Value <string>("mcs_customerphone"));
            }
            if (jo.ContainsKey("mcs_diagnosiscontent"))
            {
                supportorderEntity.Attributes.Add("mcs_diagnosiscontent", jo.Value <string>("mcs_diagnosiscontent"));
            }
            if (jo.ContainsKey("mcs_email"))
            {
                supportorderEntity.Attributes.Add("mcs_email", jo.Value <string>("mcs_email"));
            }
            if (jo.ContainsKey("mcs_enginenumber"))
            {
                supportorderEntity.Attributes.Add("mcs_enginenumber", jo.Value <string>("mcs_enginenumber"));
            }
            if (jo.ContainsKey("mcs_ismodifiedparts"))
            {
                supportorderEntity.Attributes.Add("mcs_ismodifiedparts", jo.Value <bool?>("mcs_ismodifiedparts"));
            }
            if (jo.ContainsKey("mcs_malfunctioncontent"))
            {
                supportorderEntity.Attributes.Add("mcs_malfunctioncontent", jo.Value <string>("mcs_malfunctioncontent"));
            }
            if (jo.ContainsKey("mcs_malfunctiontypeid"))
            {
                supportorderEntity.Attributes.Add("mcs_malfunctiontypeid", new CrmEntityReference("mcs_malfunctiontype", Guid.Parse(jo.Value <string>("mcs_malfunctiontypeid"))));
            }
            if (jo.ContainsKey("mcs_mileage"))
            {
                supportorderEntity.Attributes.Add("mcs_mileage", jo.Value <decimal?>("mcs_mileage"));
            }
            if (jo.ContainsKey("mcs_modifiedpartscontent"))
            {
                supportorderEntity.Attributes.Add("mcs_modifiedpartscontent", jo.Value <string>("mcs_modifiedpartscontent"));
            }
            if (jo.ContainsKey("mcs_phone"))
            {
                supportorderEntity.Attributes.Add("mcs_phone", jo.Value <string>("mcs_phone"));
            }
            if (jo.ContainsKey("mcs_repairdate"))
            {
                supportorderEntity.Attributes.Add("mcs_repairdate", jo.Value <DateTime?>("mcs_repairdate").Value.ToUniversalTime());
            }
            if (jo.ContainsKey("mcs_techsystem"))
            {
                supportorderEntity.Attributes.Add("mcs_techsystem", jo.Value <int?>("mcs_techsystem"));
            }
            if (jo.ContainsKey("mcs_cartypeid") && Guid.TryParse(jo["mcs_cartypeid"].ToString(), out outGuid))
            {
                supportorderEntity.Attributes.Add("mcs_cartypeid", new CrmEntityReference("mcs_cartype", Guid.Parse(jo.Value <string>("mcs_cartypeid"))));
            }
            if (jo.ContainsKey("Id") && Guid.TryParse(jo["Id"].ToString(), out outGuid))
            {
                await _crmService.Update(supportorderEntity);
            }
            else
            {
                await _crmService.Create(supportorderEntity);
            }
            #endregion

            #region  除旧的经销商附件
            var deleteAttachmentList = await _crmService.RetrieveMultiple("mcs_attachment", $"$filter=_mcs_supportorderid_value eq {supportorderGuid}");

            foreach (var deleteAttachment in deleteAttachmentList.Results)
            {
                await _crmService.Delete("mcs_attachment", deleteAttachment.Id);
            }
            #endregion

            #region 更新经销商附件

            if (jo.ContainsKey("fileEntityArray"))
            {
                var fileArray = jo.Value <JArray>("fileEntityArray");
                foreach (var attachmentJo in fileArray)
                {
                    var attachmentGuid   = Guid.NewGuid();
                    var attachmentEntity = new CrmExecuteEntity("mcs_attachment", attachmentGuid);
                    attachmentEntity.Attributes.Add("mcs_supportorderid", new CrmEntityReference("mcs_supportorder", supportorderGuid));
                    attachmentEntity.Attributes.Add("mcs_filename", attachmentJo.Value <string>("mcs_filename"));
                    attachmentEntity.Attributes.Add("mcs_filesize", attachmentJo.Value <string>("mcs_filesize"));
                    attachmentEntity.Attributes.Add("mcs_fileurl", attachmentJo.Value <string>("mcs_fileurl"));
                    await _crmService.Create(attachmentEntity);
                }
            }
            #endregion


            var validateResult  = new ValidateResult <CrmEntity>();
            var reusetCrmEntity = await _crmService.Retrieve("mcs_supportorder", supportorderGuid, "$select=mcs_supportorderid,mcs_name");

            validateResult.Data        = reusetCrmEntity;
            validateResult.Result      = true;
            validateResult.Description = "操作成功";
            return(validateResult);
        }