public Guid InsertCase(CaseEntity caseEntity) { Guid result; Database db = DatabaseFactory.CreateDatabase(Constant.DiaryDBConnectionString); DbCommand dbCommand = db.GetStoredProcCommand("usp_CaseInsert"); db.AddInParameter(dbCommand, "@Case", DbType.String, caseEntity.Case); db.AddInParameter(dbCommand, "@Code", DbType.String, caseEntity.Code); db.AddInParameter(dbCommand, "@ClientID", DbType.Guid, caseEntity.ClientId); db.AddInParameter(dbCommand, "@OffenceTypeId", DbType.Guid, caseEntity.OffenceTypeId); db.AddInParameter(dbCommand, "@CourtId", DbType.Guid, caseEntity.CourtId); db.AddInParameter(dbCommand, "@CaseTypeId", DbType.Guid, caseEntity.CaseTypeId); db.AddInParameter(dbCommand, "@Email", DbType.String, caseEntity.Email); db.AddInParameter(dbCommand, "@Contact", DbType.String, caseEntity.Contact); db.AddInParameter(dbCommand, "@CreatedBy", DbType.Guid, caseEntity.CreatedBy); db.AddOutParameter(dbCommand, "@CaseId", DbType.Guid, 30); db.ExecuteNonQuery(dbCommand); result = new Guid(db.GetParameterValue(dbCommand, "@CaseId").ToString()); caseEntity.CaseId = result; this.InsertUpdateDelete(caseEntity); return(result); }
private bool InsertUpdateDelete(CaseEntity caseEntity) { Database db = DatabaseFactory.CreateDatabase(Constant.DiaryDBConnectionString); DbCommand commandInsert = db.GetStoredProcCommand("usp_CaseDescriptionInsert"); db.AddInParameter(commandInsert, "@CaseId", DbType.Guid, caseEntity.CaseId); db.AddInParameter(commandInsert, "@ClientId", DbType.Guid, "ClientId", DataRowVersion.Current); db.AddInParameter(commandInsert, "@CreatedBy", DbType.Guid, "CreatedBy", DataRowVersion.Current); DbCommand commandUpdate = db.GetStoredProcCommand("usp_CaseDescriptionUpdate"); db.AddInParameter(commandUpdate, "@CaseDescriptionId", DbType.Int32, "CaseDescriptionId", DataRowVersion.Current); db.AddInParameter(commandUpdate, "@CaseId", DbType.Guid, "CaseId", DataRowVersion.Current); db.AddInParameter(commandUpdate, "@ClientId", DbType.Guid, "ClientId", DataRowVersion.Current); db.AddInParameter(commandUpdate, "@UpdatedBy", DbType.Guid, "UpdatedBy", DataRowVersion.Current); DbCommand commandDelete = db.GetStoredProcCommand("usp_CaseDescriptionDelete"); db.AddInParameter(commandDelete, "@CaseDescriptionId", DbType.Int64, "CaseDescriptionId", DataRowVersion.Current); db.UpdateDataSet(caseEntity.Clients, caseEntity.Clients.Tables[0].TableName, commandInsert, commandUpdate, commandDelete, UpdateBehavior.Transactional); return(true); }
public static CaseFlow GetCaseFlow(CaseEntity @case) { var averages = new Dictionary <Lite <IWorkflowNodeEntity>, double?>(); averages.AddRange(@case.Workflow.WorkflowActivities().Select(a => KeyValuePair.Create((Lite <IWorkflowNodeEntity>)a.ToLite(), a.AverageDuration()))); averages.AddRange(@case.Workflow.WorkflowEvents().Where(e => e.Type == WorkflowEventType.IntermediateTimer).Select(e => KeyValuePair.Create((Lite <IWorkflowNodeEntity>)e.ToLite(), e.AverageDuration()))); var caseActivities = @case.CaseActivities().Select(ca => new CaseActivityStats { CaseActivity = ca.ToLite(), PreviousActivity = ca.Previous, WorkflowActivity = ca.WorkflowActivity.ToLite(), WorkflowActivityType = (WorkflowActivityType?)(ca.WorkflowActivity as WorkflowActivityEntity) !.Type, WorkflowEventType = (WorkflowEventType?)(ca.WorkflowActivity as WorkflowEventEntity) !.Type, SubWorkflow = (ca.WorkflowActivity as WorkflowActivityEntity).Try(wa => wa.SubWorkflow).Try(sw => sw.Workflow.ToLite()), BpmnElementId = ca.WorkflowActivity.BpmnElementId, Notifications = ca.Notifications().Count(), StartDate = ca.StartDate, DoneDate = ca.DoneDate, DoneType = ca.DoneType, DoneBy = ca.DoneBy, Duration = ca.Duration, AverageDuration = averages.TryGetS(ca.WorkflowActivity.ToLite()), EstimatedDuration = ca.WorkflowActivity is WorkflowActivityEntity ? ((WorkflowActivityEntity)ca.WorkflowActivity).EstimatedDuration : ((WorkflowEventEntity)ca.WorkflowActivity).Timer !.Duration == null ? (double?)null : ((WorkflowEventEntity)ca.WorkflowActivity).Timer !.Duration !.ToTimeSpan().TotalMinutes, }).ToDictionary(a => a.CaseActivity);
public static bool IsTempCase(this CaseEntity caseEntity) { return(caseEntity.CaseType == CaseType.TempBan || caseEntity.CaseType == CaseType.TempMute || caseEntity.CaseType == CaseType.TempBlock || caseEntity.CaseType == CaseType.TempRoleBan); }
public bool UpdateCase(CaseEntity caseEntity) { bool result = false; Database db = DatabaseFactory.CreateDatabase(Constant.DiaryDBConnectionString); DbCommand dbCommand = db.GetStoredProcCommand("usp_CaseUpdate"); db.AddInParameter(dbCommand, "@CaseId", DbType.Guid, caseEntity.CaseId); db.AddInParameter(dbCommand, "@Code", DbType.String, caseEntity.Code); db.AddInParameter(dbCommand, "@Case", DbType.String, caseEntity.Case); db.AddInParameter(dbCommand, "@ClientID", DbType.Guid, caseEntity.ClientId); db.AddInParameter(dbCommand, "@OffenceTypeId", DbType.Guid, caseEntity.OffenceTypeId); db.AddInParameter(dbCommand, "@CourtId", DbType.Guid, caseEntity.CourtId); db.AddInParameter(dbCommand, "@CaseTypeId", DbType.Guid, caseEntity.CaseTypeId); db.AddInParameter(dbCommand, "@Email", DbType.String, caseEntity.Email); db.AddInParameter(dbCommand, "@Contact", DbType.String, caseEntity.Contact); db.AddInParameter(dbCommand, "@UpdatedBy", DbType.Guid, caseEntity.UpdatedBy); db.ExecuteNonQuery(dbCommand); this.InsertUpdateDelete(caseEntity); result = true; return(result); }
/// <summary> /// Initialize new instance of <see cref="EmailTemplateLanguageHelper" />. /// </summary> /// <param name="caseId">Case record identifier.</param> /// <param name="userConnection">User connection.</param> public EmailTemplateLanguageHelper(Guid caseId, UserConnection userConnection) { UserConnection = userConnection; EntitySchema caseSchema = UserConnection.EntitySchemaManager.FindInstanceByName("Case"); CaseEntity = caseSchema.CreateEntity(UserConnection) as Case; CaseEntity.FetchFromDB(caseId); }
/// <summary> /// Initialize new instance of <see cref="EmailTemplateCommLangHandler" />. /// </summary> /// <param name="caseId">Case record identifier.</param> /// <param name="userConnection">User connection.</param> protected EmailTemplateCommLangHandler(Guid caseId, UserConnection userConnection) { UserConnection = userConnection; EntitySchema caseSchema = UserConnection.EntitySchemaManager.FindInstanceByName("Case"); CaseEntity = caseSchema.CreateEntity(UserConnection) as Case; CaseEntity.FetchFromDB(caseId); }
public JsonResult Delete([FromForm] string token, [FromForm] int caseId) { DataResult dr = new DataResult(); try { if (caseId < 10000) { dr.code = "201"; dr.msg = "参数错误"; return(Json(dr)); } CaseBLL caseBLL = new CaseBLL(); CaseEntity caseEntity = caseBLL.GetById(caseId); if (caseEntity == null) { dr.code = "201"; dr.msg = "不存在该说说"; return(Json(dr)); } UserEntity userEntity = this.GetUserByToken(token); if (caseEntity.userId != userEntity.userId) { dr.code = "201"; dr.msg = "不是该用户的说说"; return(Json(dr)); } caseEntity.isDel = true; caseEntity.modifyDate = DateTime.Now; int rows = caseBLL.ActionDal.ActionDBAccess.Updateable(caseEntity).ExecuteCommand(); //增加阅读记录 ReadBLL readBLL = new ReadBLL(); readBLL.Create(userEntity.userId, (int)Entity.TypeEnumEntity.TypeEnum.案例, caseId); if (rows > 0) { dr.code = "200"; dr.msg = "成功"; } else { dr.code = "201"; dr.msg = "失败"; } } catch (Exception ex) { dr.code = "999"; dr.msg = ex.Message; } return(Json(dr)); }
/// <summary> /// Entry point for language searching. /// </summary> /// <param name="templateId">Email template identifier.</param> /// <param name="templateLoader">Email template store.</param> /// <returns>Language identifier for email template.</returns> public override Guid Handle(Guid templateId, ITemplateLoader templateLoader) { var contactId = CaseEntity.GetTypedColumnValue <Guid>("ContactId"); Guid contactLanguageId = _commLang.Get(contactId); if (contactLanguageId != default(Guid) && IsTemplateValid(templateId, contactLanguageId, templateLoader)) { return(contactLanguageId); } return(Successor != null?Successor.Handle(templateId, templateLoader) : Guid.Empty); }
/// <summary> /// Get recipients mailboxes. /// </summary> /// <returns>All recipients mailboxes.</returns> private string[] GetRecipientMailboxes() { var parentActivityId = CaseEntity.GetTypedColumnValue <Guid>("ParentActivityId"); if (parentActivityId != default(Guid)) { string allRecipients = GetRecipients(parentActivityId); return(ActivityUtils.ParseEmailAddress(allRecipients).ToArray()); } return(new string[0]); }
public BaseModel ToModel(IBaseEntity Case) { CaseEntity CaseEntity = (CaseEntity)Case; return(new CaseModel { Id = Case.Id, Name = Case.Name, MotherboardTypeСompatibility = (MotherboardType)Enum.Parse(typeof(MotherboardType), CaseEntity.MotherboardTypeСompatibility), PowerSupplyTypeCompatybility = (PowerSupplyType)Enum.Parse(typeof(PowerSupplyType), CaseEntity.PowerSupplyTypeCompatybility), DetailType = CaseEntity.DetailType }); }
static internal CaseInfo ConvertCaseInfo(CaseEntity c) { var ci = new CaseInfo() { Identifier = c.ID, ClientAddress = c.ClientEmail, Created = c.Created, Description = c.Description, Task = c.Task, Finished = c.Finished }; return(ci); }
/// <summary> /// 详细页面 /// </summary> /// <param name="id"></param> /// <returns></returns> public IActionResult Detail(int id) { CaseBLL caseBLL = new CaseBLL(); CaseEntity caseEntity = caseBLL.GetById(id); CaseTagCorrelationBLL caseTagCorrelationBLL = new CaseTagCorrelationBLL(); caseEntity.caseTagEntities = caseTagCorrelationBLL.CaseTagListByCaseId(caseEntity.caseId); CaseStepBLL caseStepBLL = new CaseStepBLL(); caseEntity.caseStepEntities = caseStepBLL.ListByCaseId(caseEntity.caseId); return(View(caseEntity)); }
public JsonResult GetById([FromForm] string token, [FromForm] int caseId) { DataResult dr = new DataResult(); try { CaseBLL caseBLL = new CaseBLL(); CaseEntity caseEntity = caseBLL.GetById(caseId); CommentBLL commentBLL = new CommentBLL(); caseEntity.commentCount = commentBLL.ListByTypeAndObjId((int)Entity.TypeEnumEntity.TypeEnum.案例, caseEntity.caseId).Count(); EndorseBLL endorseBLL = new EndorseBLL(); List <EndorseEntity> endorseEntities = endorseBLL.ListByTypeAndObjId((int)Entity.TypeEnumEntity.TypeEnum.案例, caseEntity.caseId); caseEntity.endorseCount = endorseEntities.Count(); UserEntity userEntity = new UserEntity(); if (!string.IsNullOrWhiteSpace(token)) { userEntity = this.GetUserByToken(token); if (endorseEntities.ToList().Exists(it => it.userId == userEntity.userId)) { caseEntity.isEndorse = true; } } CaseStepBLL caseStepBLL = new CaseStepBLL(); caseEntity.caseStepEntities = caseStepBLL.ListByCaseId(caseEntity.caseId); CaseTagCorrelationBLL caseTagCorrelationBLL = new CaseTagCorrelationBLL(); caseEntity.caseTagEntities = caseTagCorrelationBLL.CaseTagListByCaseId(caseEntity.caseId); dr.code = "200"; dr.data = caseEntity; } catch (Exception ex) { dr.code = "999"; dr.msg = ex.Message; } return(Json(dr)); }
public CaseInfo CreateCase(CaseInfo caseInfo) { using (var ctx = new Server.System.Repository.DataAccess.CaseHandlingDatabaseContext()) { if (caseInfo.Created == null) { caseInfo.Created = DateTime.Now; } var c = new CaseEntity() { ID = Guid.NewGuid(), Description = caseInfo.Description, Task = caseInfo.Task, ClientEmail = caseInfo.ClientAddress }; c.Created = caseInfo.Created.Value; ctx.CaseEntities.AddObject(c); ctx.SaveChanges(); caseInfo.Identifier = c.ID; return(caseInfo); } }
private static WorkflowEventEntity GetStartEvent(CaseEntity @case, Lite <CaseActivityEntity> firstActivity, WorkflowNodeGraph gr) { var wet = Database.Query <OperationLogEntity>() .Where(l => l.Operation == CaseActivityOperation.CreateCaseFromWorkflowEventTask.Symbol && l.Target.RefersTo(@case)) .Select(l => new { l.Origin, l.User }) .SingleOrDefaultEx(); if (wet != null) { var lite = (wet.Origin as Lite <WorkflowEventTaskEntity>).InDB(a => a.Event); return(lite == null ? null : gr.Events.GetOrThrow(lite)); } bool register = Database.Query <OperationLogEntity>() .Where(l => l.Operation == CaseActivityOperation.Register.Symbol && l.Target.Is(firstActivity) && l.Exception == null) .Any(); if (register) { return(gr.Events.Values.SingleEx(a => a.Type == WorkflowEventType.Start)); } return(gr.Events.Values.Where(a => a.Type.IsStart()).Only()); }
public async Task RoleBanUser(string targetStr, string roleStr, string time, [Remainder] string reason) { var target = await GetMentionedUser(targetStr, null, false); if (target == null) { await ReplyAsync("Target could not be found."); return; } var targetGuildUser = Context.Guild.GetUser(target.Id); if (targetGuildUser != null && targetGuildUser.Hierarchy > Context.User.Hierarchy) { await ReplyAsync("The target got a higher rank than you."); return; } if (!GetTime(time, out DateTimeOffset? dateTimeOffset, out bool isPerma)) { await ReplyAsync( @"Invalid time: 'roleban [@user] [role] [time] [reason]'. Please use with X as number: 'Xs' or 'Xsec' for seconds, 'Xm' or 'Xmin' for minutes, 'Xh', 'Xst' for hours, 'Xd', 'Xt' for days, '-1', '-', 'perma' or 'never' for perma, '0', 'unban', 'no' or 'stop' for unban."); return; } var role = GetRole(roleStr); if (role is null) { await ReplyAsync("Role could not be found."); return; } SocketRole otherRole = null; var guildEntity = _databaseHandler.Get <GuildEntity>(Context.Guild.Id); string muteRolesSuffix = guildEntity.RoleForMutedSuffix; if (muteRolesSuffix != default) { var mutedOrUnmutedOtherRoleName = role.Name.EndsWith("Muted") ? role.Name.Substring(0, role.Name.Length - muteRolesSuffix.Length) : role.Name + muteRolesSuffix; otherRole = GetRole(mutedOrUnmutedOtherRoleName); if (!otherRole.Name.EndsWith("Muted")) { var roleTemp = role; role = otherRole; otherRole = roleTemp; } } string rolebanId = $"{target.Id}-{role.Id}-RoleBan"; var previousRoleBan = _databaseHandler.Get <CaseEntity>(rolebanId); if (previousRoleBan != null) { await ReplyAsync("Previous roleban removed:"); await ReplyAsync(embed: previousRoleBan.ToEmbed(Context.Client)); _databaseHandler.Delete(previousRoleBan); } if (dateTimeOffset.HasValue || isPerma) // not unban { var dmChannel = await target.GetOrCreateDMChannelAsync(); await dmChannel?.SendMessageAsync( @$ "You've got a role ban in {Context.Guild.Name} Discord server for the role {role.Name} by {Context.User.Username}. Reason: {reason} Expires: {(isPerma ? " never " : dateTimeOffset.Value.ToString())}"); //await Context.Guild.AddBanAsync(target, 0, reason); var caseEntity = new CaseEntity { Id = rolebanId, UserId = target.Id, CaseType = isPerma ? CaseType.RoleBan : CaseType.TempRoleBan, CreatedOn = DateTimeOffset.Now, GuildId = Context.Guild.Id, ModeratorId = Context.User.Id, Reason = reason, }; if (dateTimeOffset.HasValue) { caseEntity.ExpiresOn = dateTimeOffset.Value; } _databaseHandler.Save(caseEntity); try { await targetGuildUser.RemoveRoleAsync(role); if (otherRole is { }) { await targetGuildUser.RemoveRoleAsync(otherRole); } }
public async Task BanUser(string targetStr, string time, [Remainder] string reason) { var target = await GetBannedUser(targetStr); if (target == null) { await ReplyAsync("User could not be found."); return; } var targetGuildUser = Context.Guild.GetUser(target.Id); if (targetGuildUser != null && targetGuildUser.Hierarchy > Context.User.Hierarchy) { await ReplyAsync("The target got a higher rank than you."); return; } if (!GetTime(time, out DateTimeOffset? dateTimeOffset, out bool isPerma)) { await ReplyAsync( @"Invalid time: 'ban [@user] [time] [reason]'. Please use with X as number: 'Xs' or 'Xsec' for seconds, 'Xm' or 'Xmin' for minutes, 'Xh', 'Xst' for hours, 'Xd', 'Xt' for days, '-1', '-', 'perma' or 'never' for perma, '0', 'unban', 'no' or 'stop' for unban."); return; } string banId = $"{target.Id}-Ban"; var previousBan = _databaseHandler.Get <CaseEntity>(banId); if (previousBan != null) { await ReplyAsync("Previous ban removed:"); await ReplyAsync(embed: previousBan.ToEmbed(Context.Client)); _databaseHandler.Delete(previousBan); } // Gives exception if there is no ban try { await Context.Guild.RemoveBanAsync(target); } catch { // ignored } if (dateTimeOffset.HasValue || isPerma) // not unban { var dmChannel = await target.GetOrCreateDMChannelAsync(); await dmChannel?.SendMessageAsync( @$ "You've been banned in {Context.Guild.Name} Discord server by {Context.User.Username}. Reason: {reason} Expires: {(isPerma ? " never " : dateTimeOffset.Value.ToString())}"); await Context.Guild.AddBanAsync(target, 0, reason); var caseEntity = new CaseEntity { Id = banId, UserId = target.Id, CaseType = isPerma ? CaseType.Ban : CaseType.TempBan, CreatedOn = DateTimeOffset.Now, GuildId = Context.Guild.Id, ModeratorId = Context.User.Id, Reason = reason, }; if (dateTimeOffset.HasValue) { caseEntity.ExpiresOn = dateTimeOffset.Value; } _databaseHandler.Save(caseEntity); await ReplyAsync($"Ban saved for {target.Username}. Use 'baninfo [@user]' or 'info [@user]' for informations."); } else { await ReplyAsync($"The user {target.Username} got unbanned."); var dmChannel = await target.GetOrCreateDMChannelAsync(); dmChannel?.SendMessageAsync($"You got unbanned in {Context.Guild.Name} Discord server by {Context.User.Username}. Reason: {reason}"); } }
public async Task MuteMember(string targetMention, string time, [Remainder] string reason) { var targetSocketUser = await GetMentionedUser(targetMention, "mute [@user] [time] [reason]"); if (targetSocketUser == null) { return; } string muteId = $"{targetSocketUser.Id}-Mute"; var previousMute = _databaseHandler.Get <CaseEntity>(muteId); if (previousMute != null) { await ReplyAsync("Previous mute removed:"); await ReplyAsync(embed : previousMute.ToEmbed(Context.Client)); _databaseHandler.Delete(previousMute); } if (!GetTime(time, out DateTimeOffset? dateTimeOffset, out bool isPerma)) { await ReplyAsync( @"Invalid time: 'mute [@user] [time] [reason]'. Please use with X as number: 'Xs' or 'Xsec' for seconds, 'Xm' or 'Xmin' for minutes, 'Xh', 'Xst' for hours, 'Xd', 'Xt' for days, '-1', '-', 'perma', 'permamute' or 'never' for perma, '0', 'unmute', 'no' or 'stop' for unmute."); return; } if (!dateTimeOffset.HasValue && !isPerma) // unmute { if (previousMute != null && (targetSocketUser is SocketGuildUser target)) { _rolesHandler.ChangeRolesToUnmute(target); } await ReplyAsync($"Unmuted user {targetSocketUser.Username}."); } else { if (previousMute == null && (targetSocketUser is SocketGuildUser target)) { _rolesHandler.ChangeRolesToMute(target); } var caseEntity = new CaseEntity { Id = muteId, UserId = targetSocketUser.Id, CaseType = isPerma ? CaseType.Mute : CaseType.TempMute, CreatedOn = DateTimeOffset.Now, GuildId = Context.Guild.Id, ModeratorId = Context.User.Id, Reason = reason, }; if (dateTimeOffset.HasValue) { caseEntity.ExpiresOn = dateTimeOffset.Value; } _databaseHandler.Save(caseEntity); await ReplyAsync($"Mute saved for user {targetSocketUser.Username}. Use 'muteinfo [@user]' or 'info [@user]' for informations."); } }
/// <summary> /// 打赏案例 /// </summary> /// <param name="userEntity"></param> /// <param name="caseId"></param> /// <returns></returns> private DataResult SponsorCase(UserEntity userEntity, int caseId) { DataResult dr = new DataResult(); CaseBLL caseBLL = new CaseBLL(); CaseEntity caseEntity = caseBLL.GetById(caseId); if (caseEntity.isDel) { dr.code = "201"; dr.msg = "说说已被删除"; return(dr); } if (caseEntity.userId < 10000) { dr.code = "201"; dr.msg = "无主案例"; return(dr); } var result = caseBLL.ActionDal.ActionDBAccess.Ado.UseTran(() => { //积分减1 userEntity.integral = userEntity.integral - 1; var rows1 = caseBLL.ActionDal.ActionDBAccess.Updateable(userEntity).ExecuteCommand(); IntegralDetailEntity integralDetailEntity = new IntegralDetailEntity() { createDate = DateTime.Now, integral = -1, isDel = false, modifyDate = DateTime.Now, objId = caseId, type = (int)Entity.TypeEnumEntity.TypeEnum.案例, userId = userEntity.userId }; var rows2 = caseBLL.ActionDal.ActionDBAccess.Insertable(integralDetailEntity).ExecuteCommand(); //积分加1 UserEntity user = caseBLL.ActionDal.ActionDBAccess.Queryable <UserEntity>().Where(it => it.userId == caseEntity.userId).First(); user.integral = user.integral + 1; var rows3 = caseBLL.ActionDal.ActionDBAccess.Updateable(user).ExecuteCommand(); IntegralDetailEntity integralDetail = new IntegralDetailEntity() { createDate = DateTime.Now, integral = 1, isDel = false, modifyDate = DateTime.Now, objId = caseId, type = (int)Entity.TypeEnumEntity.TypeEnum.案例, userId = user.userId }; var rows4 = caseBLL.ActionDal.ActionDBAccess.Insertable(integralDetail).ExecuteCommand(); caseEntity.integral = caseEntity.integral + 1; var rows5 = caseBLL.ActionDal.ActionDBAccess.Updateable(caseEntity).ExecuteCommand(); }); //增加阅读记录 ReadBLL readBLL = new ReadBLL(); readBLL.Create(userEntity.userId, (int)Entity.TypeEnumEntity.TypeEnum.案例, caseId); if (result.IsSuccess) { dr.code = "200"; dr.msg = "成功"; } else { dr.code = "201"; dr.msg = "失败"; } return(dr); }
public JsonResult Create([FromForm] string token, [FromForm] string title, [FromForm] string coverImage, [FromForm] string describe, [FromForm] string tips, [FromForm] string caseStep, [FromForm] string caseTag) { DataResult dr = new DataResult(); try { if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(describe) || string.IsNullOrWhiteSpace(coverImage)) { dr.code = "201"; dr.msg = "参数错误"; return(Json(dr)); } UserEntity userEntity = this.GetUserByToken(token); CaseBLL caseBLL = new CaseBLL(); CaseEntity caseEntity = caseBLL.Create(userEntity.userId, title, coverImage, describe, tips); string msg = string.Empty; if (caseEntity != null) { msg += "创建案例成功"; if (!string.IsNullOrWhiteSpace(caseStep)) { List <CaseStepEntity> caseStepEntities = JsonConvert.DeserializeObject <List <CaseStepEntity> >(caseStep); caseStepEntities = caseStepEntities.Where(it => !string.IsNullOrWhiteSpace(it.img) || !string.IsNullOrWhiteSpace(it.contents)).ToList(); caseStepEntities.ForEach(it => { it.caseId = caseEntity.caseId; it.img = it.img ?? ""; it.contents = it.contents ?? ""; }); if (caseStepEntities.Count > 0) { int rows = caseBLL.ActionDal.ActionDBAccess.Insertable(caseStepEntities).ExecuteCommand(); if (rows > 0) { msg += ",步骤添加成功"; } } } if (!string.IsNullOrWhiteSpace(caseTag)) { int[] caseTags = JsonConvert.DeserializeObject <int[]>(caseTag); if (caseTags.Length > 0) { List <CaseTagCorrelationEntity> caseTagCorrelationEntities = new List <CaseTagCorrelationEntity>(); for (int i = 0; i < caseTags.Length; i++) { caseTagCorrelationEntities.Add(new CaseTagCorrelationEntity { caseId = caseEntity.caseId, caseTagId = caseTags[i], createDate = DateTime.Now, isDel = false, modifyDate = DateTime.Now }); } int rows = caseBLL.ActionDal.ActionDBAccess.Insertable(caseTagCorrelationEntities).ExecuteCommand(); if (rows > 0) { msg += ",标签添加成功"; } } } } dr.code = "200"; dr.msg = msg; } catch (Exception ex) { dr.code = "999"; dr.msg = ex.Message; } return(Json(dr)); }
public Guid InsertCase(CaseEntity caseEntity) { return(caseDao.InsertCase(caseEntity)); }
public static CaseFlow GetCaseFlow(CaseEntity @case) { var averages = @case.Workflow.WorkflowActivities().Select(w => KVP.Create(w.ToLite(), w.CaseActivities().Average(a => a.Duration))).ToDictionary(); var caseActivities = @case.CaseActivities().Select(ca => new CaseActivityStats { CaseActivity = ca.ToLite(), PreviousActivity = ca.Previous, WorkflowActivity = ca.WorkflowActivity.ToLite(), WorkflowActivityType = ca.WorkflowActivity.Type, SubWorkflow = ca.WorkflowActivity.SubWorkflow.Workflow.ToLite(), BpmnElementId = ca.WorkflowActivity.BpmnElementId, Notifications = ca.Notifications().Count(), StartDate = ca.StartDate, DoneDate = ca.DoneDate, DoneType = ca.DoneType, DoneBy = ca.DoneBy, Duration = ca.Duration, AverageDuration = averages.TryGetS(ca.WorkflowActivity.ToLite()), EstimatedDuration = ca.WorkflowActivity.EstimatedDuration, }).ToDictionary(a => a.CaseActivity); var gr = WorkflowLogic.GetWorkflowNodeGraph(@case.Workflow.ToLite()); var connections = caseActivities.Values .Where(cs => cs.PreviousActivity != null && caseActivities.ContainsKey(cs.PreviousActivity)) .SelectMany(cs => { var prev = caseActivities.GetOrThrow(cs.PreviousActivity); var from = gr.Activities.GetOrThrow(prev.WorkflowActivity); var to = gr.Activities.GetOrThrow(cs.WorkflowActivity); if (IsNormal(prev.DoneType.Value)) { var conns = GetAllConnections(gr, from, to); if (conns.Any()) { return(conns.Select(c => new CaseConnectionStats { BpmnElementId = c.BpmnElementId, Connection = c.ToLite(), FromBpmnElementId = c.From.BpmnElementId, ToBpmnElementId = c.To.BpmnElementId, DoneBy = prev.DoneBy, DoneDate = prev.DoneDate.Value, DoneType = prev.DoneType.Value })); } } return(new[] { new CaseConnectionStats { FromBpmnElementId = from.BpmnElementId, ToBpmnElementId = to.BpmnElementId, DoneBy = prev.DoneBy, DoneDate = prev.DoneDate.Value, DoneType = prev.DoneType.Value } }); }).ToList(); var firsts = caseActivities.Values.Where(a => (a.PreviousActivity == null || !caseActivities.ContainsKey(a.PreviousActivity))); foreach (var f in firsts) { WorkflowEventEntity start = GetStartEvent(@case, f.CaseActivity, gr); connections.AddRange(GetAllConnections(gr, start, gr.Activities.GetOrThrow(f.WorkflowActivity)).Select(c => new CaseConnectionStats { BpmnElementId = c.BpmnElementId, Connection = c.ToLite(), FromBpmnElementId = c.From.BpmnElementId, ToBpmnElementId = c.To.BpmnElementId, DoneBy = f.DoneBy, DoneDate = f.StartDate, })); } if (@case.FinishDate != null) { var lasts = caseActivities.Values.Where(last => !caseActivities.Values.Any(a => a.PreviousActivity.Is(last.CaseActivity))).ToList(); var ends = gr.Events.Values.Where(a => a.Type == WorkflowEventType.Finish); foreach (var last in lasts) { foreach (var end in ends) { connections.AddRange(GetAllConnections(gr, gr.Activities.GetOrThrow(last.WorkflowActivity), end).Select(c => new CaseConnectionStats { BpmnElementId = c.BpmnElementId, Connection = c.ToLite(), FromBpmnElementId = c.From.BpmnElementId, ToBpmnElementId = c.To.BpmnElementId, DoneBy = last.DoneBy, DoneDate = last.DoneDate.Value, })); } } } return(new CaseFlow { Activities = caseActivities.Values.GroupToDictionary(a => a.BpmnElementId), Connections = connections.Where(a => a.BpmnElementId != null).GroupToDictionary(a => a.BpmnElementId), Jumps = connections.Where(a => a.BpmnElementId == null).ToList(), AllNodes = connections.Select(a => a.FromBpmnElementId).Union(connections.Select(a => a.ToBpmnElementId)).ToList() }); }
public bool UpdateCase(CaseEntity caseEntity) { return(caseDao.UpdateCase(caseEntity)); }