/// <summary> /// 移动端保存表单(新增、修改) /// </summary> /// <param name="keyValue"></param> /// <param name="entity"></param> public void AppSaveForm(string keyValue, TrailRecordEntity entity) { #region 修改 if (!string.IsNullOrWhiteSpace(keyValue)) { this.BaseRepository().Update(entity); entity = this.GetEntity(entity.TrailId); #region 客户 string userId = entity.ModifyUserId; //销售阶段 CustomerFollowEntity followEntity = new CustomerFollowEntity(); followEntity.CustomerFollowId = Guid.NewGuid().ToString(); followEntity.CreateDate = DateTime.Now; followEntity.CreateUserId = entity.ModifyUserId; followEntity.CreateUserName = entity.ModifyUserName; followEntity.CustomerId = entity.ObjectId; followEntity.SaleStageId = entity.SaleStageId; followEntity.SaleStageName = entity.SaleStageName; followEntity.CustomerFollowId = entity.TrailId; IRepository db = new RepositoryFactory().BaseRepository(); db.BeginTrans(); try { CustomerEntity customerEntity = new CustomerEntity(); customerEntity.CustomerId = entity.ObjectId; customerEntity.ModifyDate = DateTime.Now; customerEntity.ModifyUserId = entity.ModifyUserId; customerEntity.ModifyUserName = entity.ModifyUserName; db.Update <CustomerEntity>(customerEntity); //更新日程 ScheduleEntity scheduleEntity = new ScheduleEntity(); scheduleEntity.ScheduleState = 1; scheduleEntity.Modify(entity.TrailId); scheduleEntity.ScheduleId = entity.TrailId; scheduleEntity.ModifyDate = DateTime.Now; scheduleEntity.ModifyUserId = entity.ModifyUserId; scheduleEntity.ModifyUserName = entity.ModifyUserName; db.Update(scheduleEntity); //删除已有的客户销售阶段 db.Delete <CustomerFollowEntity>(t => t.CustomerId == entity.ObjectId && t.CreateUserId == userId); //创建新销售阶段 db.Insert <CustomerFollowEntity>(followEntity); db.Commit(); } catch (Exception) { db.Rollback(); throw; } #endregion } #endregion #region 创建 else { string userId = entity.CreateUserId; //销售阶段 CustomerFollowEntity followEntity = new CustomerFollowEntity(); followEntity.CustomerFollowId = Guid.NewGuid().ToString(); followEntity.CreateDate = DateTime.Now; followEntity.CreateUserId = entity.CreateUserId; followEntity.CreateUserName = entity.CreateUserName; followEntity.CustomerId = entity.ObjectId; followEntity.SaleStageId = entity.SaleStageId; followEntity.SaleStageName = entity.SaleStageName; followEntity.CustomerFollowId = entity.TrailId; IRepository db = new RepositoryFactory().BaseRepository(); db.BeginTrans(); try { CustomerEntity customerEntity = new CustomerEntity(); customerEntity.CustomerId = entity.ObjectId; customerEntity.ModifyDate = DateTime.Now; customerEntity.ModifyUserId = entity.CreateUserId; customerEntity.ModifyUserName = entity.CreateUserName; db.Update <CustomerEntity>(customerEntity); db.Insert(entity); #region 计划任务增加到日程 if (entity.TrailType == 1) { ScheduleEntity scheduleEntity = new ScheduleEntity(); scheduleEntity.ScheduleContent = entity.ObjectName + "-" + entity.SaleStageName + "-" + entity.TrackContent; scheduleEntity.ScheduleState = 0; scheduleEntity.StartDate = entity.StartTime.ToDate(); scheduleEntity.StartTime = Convert.ToDateTime(entity.StartTime).ToString("HHmm"); scheduleEntity.EndDate = entity.EndTime.ToDate(); scheduleEntity.EndTime = Convert.ToDateTime(entity.EndTime).ToString("HHmm"); scheduleEntity.IsMailAlert = 0; scheduleEntity.IsMobileAlert = 0; scheduleEntity.IsWeChatAlert = 0; scheduleEntity.ScheduleId = entity.TrailId; scheduleEntity.ScheduleId = Guid.NewGuid().ToString(); scheduleEntity.ScheduleState = 0; scheduleEntity.EnabledMark = 1; scheduleEntity.DeleteMark = 0; scheduleEntity.CreateDate = DateTime.Now; scheduleEntity.CreateUserId = entity.CreateUserId; scheduleEntity.CreateUserName = entity.CreateUserId; db.Insert(scheduleEntity); } else { //删除已有的客户销售阶段 db.Delete <CustomerFollowEntity>(t => t.CustomerId == entity.ObjectId && t.CreateUserId == userId); //创建新销售阶段 db.Insert <CustomerFollowEntity>(followEntity); } #endregion db.Commit(); } catch (Exception) { db.Rollback(); throw; } } #endregion }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, TrailRecordEntity entity) { if (!string.IsNullOrWhiteSpace(keyValue)) { entity.Modify(keyValue); this.BaseRepository().Update(entity); entity = this.GetEntity(entity.TrailId); #region 商机 if (entity.ObjectSort == 1) { IRepository db = new RepositoryFactory().BaseRepository(); db.BeginTrans(); try { ChanceEntity chanceEntity = new ChanceEntity(); chanceEntity.Modify(entity.ObjectId); db.Update <ChanceEntity>(chanceEntity); db.Commit(); } catch (Exception) { db.Rollback(); throw; } } #endregion #region 客户 else if (entity.ObjectSort == 2) { string userId = OperatorProvider.Provider.Current().LoginInfo.UserId; //销售阶段 CustomerFollowEntity followEntity = new CustomerFollowEntity(); followEntity.Create(); followEntity.CustomerId = entity.ObjectId; followEntity.SaleStageId = entity.SaleStageId; followEntity.SaleStageName = entity.SaleStageName; followEntity.CustomerFollowId = entity.TrailId; IRepository db = new RepositoryFactory().BaseRepository(); db.BeginTrans(); try { CustomerEntity customerEntity = new CustomerEntity(); customerEntity.Modify(entity.ObjectId); db.Update <CustomerEntity>(customerEntity); //更新日程 ScheduleEntity scheduleEntity = new ScheduleEntity(); scheduleEntity.ScheduleState = 1; scheduleEntity.Modify(entity.TrailId); db.Update(scheduleEntity); //删除已有的客户销售阶段 db.Delete <CustomerFollowEntity>(t => t.CustomerId == entity.ObjectId && t.CreateUserId == userId); //创建新销售阶段 db.Insert <CustomerFollowEntity>(followEntity); db.Commit(); } catch (Exception) { db.Rollback(); throw; } } #endregion } else { entity.Create(); #region 商机 if (entity.ObjectSort == 1) { IRepository db = new RepositoryFactory().BaseRepository(); db.BeginTrans(); try { ChanceEntity chanceEntity = new ChanceEntity(); chanceEntity.Modify(entity.ObjectId); db.Update <ChanceEntity>(chanceEntity); db.Insert(entity); db.Commit(); } catch (Exception) { db.Rollback(); throw; } } #endregion #region 客户 else if (entity.ObjectSort == 2) { string userId = OperatorProvider.Provider.Current().LoginInfo.UserId; //销售阶段 CustomerFollowEntity followEntity = new CustomerFollowEntity(); followEntity.Create(); followEntity.CustomerId = entity.ObjectId; followEntity.SaleStageId = entity.SaleStageId; followEntity.SaleStageName = entity.SaleStageName; followEntity.CustomerFollowId = entity.TrailId; IRepository db = new RepositoryFactory().BaseRepository(); db.BeginTrans(); try { CustomerEntity customerEntity = new CustomerEntity(); customerEntity.Modify(entity.ObjectId); db.Update <CustomerEntity>(customerEntity); db.Insert(entity); #region 计划任务增加到日程 if (entity.TrailType == 1) { ScheduleEntity scheduleEntity = new ScheduleEntity(); scheduleEntity.ScheduleContent = entity.ObjectName + "-" + entity.SaleStageName + "-" + entity.TrackContent; scheduleEntity.ScheduleState = 0; scheduleEntity.StartDate = entity.StartTime.ToDate(); scheduleEntity.StartTime = Convert.ToDateTime(entity.StartTime).ToString("HHmm"); scheduleEntity.EndDate = entity.EndTime.ToDate(); scheduleEntity.EndTime = Convert.ToDateTime(entity.EndTime).ToString("HHmm"); scheduleEntity.IsMailAlert = 0; scheduleEntity.IsMobileAlert = 0; scheduleEntity.IsWeChatAlert = 0; scheduleEntity.Create(); scheduleEntity.ScheduleId = entity.TrailId; db.Insert(scheduleEntity); } else { //删除已有的客户销售阶段 db.Delete <CustomerFollowEntity>(t => t.CustomerId == entity.ObjectId && t.CreateUserId == userId); //创建新销售阶段 db.Insert <CustomerFollowEntity>(followEntity); } #endregion db.Commit(); } catch (Exception) { db.Rollback(); throw; } } #endregion } }