Example #1
0
 /// <summary>
 /// 作者:Raymond
 /// 日期:2014-6-27
 /// 描述:新增报备
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool CreateReferral(Referral model)
 {
     using (var edb = new EmeEntities())
     {
         edb.Entry(model).State = EntityState.Added;
         return edb.SaveChanges() > 0;
     }
 }
Example #2
0
        /// <summary>
        /// 创建报备
        /// </summary>
        /// <param name="JsData"></param>
        /// <returns></returns>
        public ResultModel CreateReferral(string JsData)
        {
            var result = new ResultModel()
            {
                msg = APIModel.M_PARAMS_ERR,
                code = APIModel.C_PARAMS_ERR
            };
            ReferralModel crmReferral = null;

            try
            {
                // json数据转换
                crmReferral = JsonHelper.FromJson<ReferralModel>(JsData);
            }
            catch (InvalidOperationException e)//如果换成Json.Net 这里要用JsonExecption捕获
            {
                result.msg += "\r\nJson数据转换异常:" + e.Message;
                return result;
            }

            var crmReferralId = crmReferral.ReferralID;
            var list = new List<string>();
            list.Add(crmReferralId.ToString());
            result.results = list;

            var crmName = crmReferral.Name ?? "无";
            var crmSex = crmReferral.Sex;
            var crmMobile = crmReferral.Mobile;
            var crmCustomerId = crmReferral.CustomerID;
            var crmState = crmReferral.State;
            var crmStage = crmReferral.State;
            var crmAddress = crmReferral.Address;
            var crmVisitTime = crmReferral.VisitTime;
            var crmCreateTime = Common.DataConvert.JsonToDateTime(crmReferral.CreateTime);
            var crmSales = crmReferral.Sales;
            var emeUser = Eme.BLL.Eme.UserBLL.GetUserByUserName(crmCustomerId.ToString());
            if (emeUser == null)
            {
                result.msg += "老用户(学生EME号)不存在";
                return result;
            }

            var referralStageType = DataConvert.ConvertRefferralStageType(crmStage);
            var referralStatusType = DataConvert.ConvertRefferralStatusType(crmState);
            var userSex = DataConvert.ConvertSex(crmSex);

            var flag = false;
            var referral = Eme.BLL.Eme.ReferralBLL.GetReferralByCrmId(crmReferralId);
            if (referral != null)
            {
                referral.UserId = emeUser.Id;
                referral.CName = crmName;
                referral.Sex = userSex;
                referral.Mobile = crmMobile;
                referral.Address = crmAddress;
                referral.ReferralStageType = referralStageType;
                referral.ReferralStatusType = referralStatusType;
                referral.VisitTime = crmVisitTime;
                referral.Status = ConvertEnum.StatusTypeForActive;
                referral.UpdateBy = -1;
                referral.UpdateTime = crmCreateTime;
                referral.Remark = "接口同步更新";
                flag = Eme.BLL.Eme.ReferralBLL.UpdateReferral(referral);
            }
            else
            {
                referral = new Referral
                {
                    V3Id = crmReferralId,
                    UserId = emeUser.Id,
                    CName = crmName,
                    Sex = userSex,
                    Mobile = crmMobile,
                    Address = crmAddress,
                    ReferralStageType = referralStageType,
                    ReferralStatusType = referralStatusType,
                    Status = ConvertEnum.StatusTypeForActive,
                    VisitTime = crmVisitTime,
                    CreateTime = crmCreateTime,
                    CreateBy = -1,
                    UpdateBy = -1,
                    UpdateTime = crmCreateTime,
                    Remark = "导入:sales=" + crmSales.ToString(),
                };
                flag = Eme.BLL.Eme.ReferralBLL.CreateReferral(referral);
            }

            if (flag)
            {
                result.code = APIModel.C_SUCCESS;
                result.count += 1;
                result.msg = APIModel.M_SUCCESS;
            }
            return result;
        }
Example #3
0
        /// <summary>
        /// 作者:Raymond
        /// 日期:2014-7-22
        /// 描述:根系报备
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool UpdateReferral(Referral model)
        {
            using (var edb = new EmeEntities())
            {
                try
                {
                    var referral = edb.Referral.FirstOrDefault(p => p.Id == model.Id);
                    if (null == referral)
                        return false;

                    referral.V3Id = model.V3Id;
                    referral.UserId = model.UserId;
                    referral.CName = model.CName;
                    referral.EName = model.EName;
                    referral.Sex = model.Sex;
                    referral.Mobile = model.Mobile;
                    referral.Address = model.Address;
                    referral.ReferralStageType = model.ReferralStageType;
                    referral.ReferralStatusType = model.ReferralStatusType;
                    referral.VisitTime = model.VisitTime;
                    referral.Status = model.Status;
                    referral.UpdateBy = model.UpdateBy;
                    referral.UpdateTime = model.UpdateTime;
                    referral.Remark = model.Remark;

                    edb.Entry(referral).State = EntityState.Modified;
                    return edb.SaveChanges() > 0;
                }
                catch (Exception e)
                {
                    // 异常日志消息队列
                    Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs()
                    {
                        ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                        Message = string.Format("ReferralBLL-UpdateReferral:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                        IsTreat = false,
                        CreateBy = -1,
                        CreateTime = DateTime.Now
                    });
                    return false;
                }
            }
        }