public async Task <bool> UpdateCustomerTrans(CHIS.Models.CHIS_Code_Customer customer, Models.CHIS_Code_Customer_HealthInfo health, DbContext.CHISEntitiesSqlServer db = null) { db = db ?? _db; db.BeginTransaction(); try { var aCust = db.CHIS_Code_Customer.AsNoTracking().First(m => m.CustomerID == customer.CustomerID); //添加患者需要更新的属性 aCust.Address = customer.Address; aCust.AddressAreaId = customer.AddressAreaId; aCust.Birthday = customer.Birthday; aCust.CertificateNo = customer.CertificateNo; aCust.CertificateTypeId = customer.CertificateTypeId; aCust.ContactMan = customer.ContactMan; aCust.ContactPhone = customer.ContactPhone; aCust.CustomerName = customer.CustomerName; aCust.EduLevel = customer.EduLevel; aCust.Email = customer.Email; aCust.CustomerPic = customer.CustomerPic; aCust.NamePY = Ass.Data.Chinese2Spell.GetFstAndFullLettersLower(customer.CustomerName); //搜索码 //aCust.Explain = customer.Explain; //aCust.FeeType = customer.FeeType; aCust.IDcard = customer.IDcard; aCust.InsuranceNo = customer.InsuranceNo; //aCust.LeftAmount = customer.LeftAmount; aCust.Marriage = customer.Marriage; //aCust.Nation = customer.Nation; aCust.Presfession = customer.Presfession; //aCust.PriceType = customer.PriceType; //aCust.Relation = customer.Relation; aCust.Remark = customer.Remark; //aCust.SaveAmount = customer.SaveAmount; aCust.Gender = customer.Gender; //aCust.Special = customer.Special; //aCust.Status = customer.Status; aCust.LoginName = customer.LoginName; aCust.Telephone = customer.Telephone; aCust.CustomerMobile = customer.CustomerMobile; // aCust.UserPWD = customer.UserPWD; aCust.IsVIP = customer.IsVIP == true; aCust.VIPcode = customer.VIPcode; //aCust.VisitCard = customer.VisitCard; //aCust.WorkCode = customer.WorkCode; aCust.ContactMan = customer.ContactMan; aCust.ContactPhone = customer.ContactPhone; aCust.WorkUnit = customer.WorkUnit; aCust.WXCode = customer.WXCode; //aCust.ZipCode = customer.ZipCode; //附加信息 // aCust.sysSource = "WEB"; // aCust.StationID = user.StationId; aCust.OpID = controller.UserSelf.OpId; aCust.OpMan = controller.UserSelf.OpMan; aCust.sysLatestActiveTime = aCust.OpTime = DateTime.Now; var hm = db.CHIS_Code_Customer_HealthInfo.AsNoTracking().First(m => m.CustomerId == customer.CustomerID); //添加患者健康基本属性 hm.Allergic = health.Allergic; //过敏史 hm.BirthChildrenNum = health.BirthChildrenNum; //生孩子数量 hm.BloodType = health.BloodType; //血型 hm.Height = health.Height; //身高 hm.MenstruationEndOldYear = health.MenstruationEndOldYear; //月经初潮时期 hm.MenstruationStartOldYear = health.MenstruationStartOldYear; //绝经日期 hm.PastMedicalHistory = health.PastMedicalHistory; //既往史 hm.PregnancyNum = health.PregnancyNum; //怀孕次数 hm.Weight = health.Weight; //体重 db.CHIS_Code_Customer.Update(aCust); db.CHIS_Code_Customer_HealthInfo.Update(hm); await db.SaveChangesAsync(); //如果 关键登陆信息改了,则登陆信息也改变 //手机和邮箱 //身份证不进行调整 var login = db.CHIS_Sys_Login.AsNoTracking().FirstOrDefault(m => m.CustomerId == customer.CustomerID); if (login == null) { await db.CHIS_Sys_Login.AddAsync(new Models.CHIS_Sys_Login { CustomerId = customer.CustomerID, Mobile = customer.CustomerMobile, IdCardNumber = customer.IDcard, Email = customer.Email, IsLock = false, LoginPassword = "******" }); } else { if (login.Mobile != customer.CustomerMobile && customer.CustomerMobile.GetStringType().IsMobile) { login.Mobile = customer.CustomerMobile; } if (login.Email != customer.Email && customer.Email.GetStringType().IsEmail) { login.Email = customer.Email; } if (login.IdCardNumber.IsEmpty() && customer.IDcard.GetStringType().IsIdCardNumber) { login.IdCardNumber = customer.IDcard; } db.CHIS_Sys_Login.Update(login); } await db.SaveChangesAsync(); db.CommitTran(); return(true); } catch (Exception ex) { db.RollbackTran(); if (ex.InnerException != null) { ex = ex.InnerException; } throw ex; } }