public async Task <IActionResult> ChangeDashboard(int id, Routine2Actions action, string description = "") { var userId = _contextAccessor.HttpContext.User.Identity.GetUserId(); var result = await _testService.ChangeStep(id, action, description, Convert.ToInt32(userId)); return(Json(result)); }
public async Task <IActionResult> ChangeDashboard(int id, Routine2Actions action, string description = "") { await this.IsPermeatedAsync(TestDashBoard.Applicant.ToString()); var result = await _testRoutinRepository.ChangeStep(UserId, 1, id, action, description); return(Json(result)); }
/// <summary> /// درصورتی از این توابع استفاده شود که جدول مورد نظر به صورت روتین باشد /// مرحله بعدی مربوط به یک آیتم به همراه شماره روتین آن را برمیگرداند /// </summary> /// <param name="id">شماره رکورد مورد نظر</param> /// <param name="RoutineId">شماره روتین</param> /// <param name="action">اکشن فعلی</param> /// <returns></returns> public async Task <int> GetNextStep(int id, int RoutineId, Routine2Actions action) { // آیتم مورد نظر را به دست میاوریم var entity = Entities .Find(id); // درصورتی که رکورد مورد نظر وجود نداشت باید خطا برگردانده شود if (entity == null) { throw new Exception($"دادهای با شناسه {id} یافت نشد"); } // مرحله فعلی آن را به دست میآوریم var currentStep = await GetStep(RoutineId, Convert.ToInt32(entity.GetPropertyValue("RoutineStep"))); int?nextStep = null; switch (action) { case Routine2Actions.F1: nextStep = currentStep.F1; break; case Routine2Actions.F2: nextStep = currentStep.F2; break; case Routine2Actions.F3: nextStep = currentStep.F3; break; case Routine2Actions.F4: nextStep = currentStep.F4; break; case Routine2Actions.F5: nextStep = currentStep.F5; break; case Routine2Actions.F6: nextStep = currentStep.F6; break; case Routine2Actions.F7: nextStep = currentStep.F7; break; } return(nextStep ?? -1); }
public static ContentResult DoAction(int entityId, Routine2Actions action, string description = "") { if (!string.IsNullOrWhiteSpace(description)) { description = WebUtility.HtmlEncode(description); description = JavaScriptEncoder.Default.Encode(description); } var content = $"<script>window.parent.Routine2.DoAction({entityId}, '{action}', \"{description}\");</script>"; return(new ContentResult() { Content = content, ContentType = "text/html; charset=utf-8" }); }
public int GetNextStep(int id, Routine2Actions action) { var entity = _context.Test .AsNoTracking() .FirstOrDefault(q => q.Id == id); if (entity == null) { throw new Exception($"دادهای با شناسه {id} یافت نشد"); } var currentStep = _routine2Repository.GetStep(TestRoutine.RoutineId, entity.RoutineStep); int?nextStep = null; switch (action) { case Routine2Actions.F1: nextStep = currentStep.F1; break; case Routine2Actions.F2: nextStep = currentStep.F2; break; case Routine2Actions.F3: nextStep = currentStep.F3; break; case Routine2Actions.F4: nextStep = currentStep.F4; break; case Routine2Actions.F5: nextStep = currentStep.F5; break; case Routine2Actions.F6: nextStep = currentStep.F6; break; case Routine2Actions.F7: nextStep = currentStep.F7; break; } return(nextStep ?? -1); }
public string GetActionTitle(int routineId, int fromStep, Routine2Actions action) { try { var routine2Action = _context.Routine2Action .AsNoTracking() .Where(q => q.RoutineId == routineId) .Where(q => q.Step == fromStep) .Where(q => q.Action == action.ToString()) .FirstOrDefault(); return(routine2Action == null ? action.ToString() : routine2Action.Title); } catch (Exception) { return(action.ToString()); } }
public int GetNextStep(Routine2Actions action, T entity, int rouitneId) { var currentStep = _routine2Repository.GetStep(rouitneId, entity.RoutineStep); int?nextStep = null; switch (action) { case Routine2Actions.F1: nextStep = currentStep.F1; break; case Routine2Actions.F2: nextStep = currentStep.F2; break; case Routine2Actions.F3: nextStep = currentStep.F3; break; case Routine2Actions.F4: nextStep = currentStep.F4; break; case Routine2Actions.F5: nextStep = currentStep.F5; break; case Routine2Actions.F6: nextStep = currentStep.F6; break; case Routine2Actions.F7: nextStep = currentStep.F7; break; } return(nextStep ?? -1); }
public async Task <ServiceResult <Routine2ChangeStepResult> > ChangeStep(int RoutineId, int EntityId, Routine2Actions Action, string Description) { try { // گرفتن رکورد مورد نظر var entity = table.Find(EntityId); // درصورتی که رکورد مورد نظر وجود نداشت باید خطا برگردانده شود if (entity == null) { throw new Exception($"دادهای با شناسه {EntityId} یافت نشد"); } // مرحله بعدی فرآیند دراین قسمت به دست میآید var nextStep = GetNextStep(Action, entity, RoutineId); // درصورتی که مرحله بعدی -1 باشد باید خطا نمایش داده شود if (nextStep == -1) { throw new Exception("Something went wrong, next dashboard couldn't be -1"); } //========================================================= int userId = _userResolverService.GetUserId(); var fromStep = entity.RoutineStep; //========================================================= // ثبت لاگ جدید برای این کاربر که رکورد مورد را از یک مرحله به مرحله دیگر انتقال داده است _routine2Repository.CreateLog(new CreateRoutine2LogViewModel { RoutineId = RoutineId, EntityId = EntityId, Description = Description, Action = _routine2Repository.GetActionTitle(RoutineId, fromStep, Action), Step = fromStep, ToStep = nextStep, UserId = userId, CreatorUserId = userId, RoutineRoleTitle = _routine2Repository.GetRoutineRoleTitle(RoutineId, entity.RoutineStep), }); var routineVm = new EditRoutine2ViewModel(nextStep, entity.RoutineFlownDate); // اگر در مرحله آخر باشیم، باید به روال برچست تمام شده بزنیم if (entity.DoneSteps.Contains(nextStep)) { routineVm.RoutineIsDone = true; } // به صورت پیشفرض طرح رد شده است، مگر اینکه در مراحل تایید باشیم if (entity.SucceededSteps.Contains(nextStep)) { routineVm.RoutineIsSucceeded = true; } entity.RoutineStep = nextStep; entity.RoutineFlownDate = DateTime.Now; entity.RoutineStepChangeDate = DateTime.Now; _context.SaveChanges(); var changeStepResult = new Routine2ChangeStepResult { Action = Action, Description = Description, UserId = userId, ToStep = nextStep, FromStep = fromStep, EntityId = EntityId, RoutineId = RoutineId, }; try { await _routine2Repository.SendNoticeAsync(changeStepResult); } catch (Exception) { } return(ServiceResult <Routine2ChangeStepResult> .Okay(changeStepResult)); } catch (Exception ex) { return(ServiceResult <Routine2ChangeStepResult> .Exception(ex)); } }
public static string SendLetterLink(int routineId, string templateKey, int entityId, Routine2Actions routineAction) { return($"/OfficialLetterTemplate/SendDraftLetters/?RoutineAction={routineAction}&RoutineId={routineId}&TemplateKey={templateKey}&EntityId={entityId}"); }
public static string RemoveButton(int entityId, Routine2Actions action) { return($"<script>Routine2.RemoveButton({entityId}, '{action}')</script>"); }
public Routine2ChangeStep(int entityId, Routine2Actions action) { this.EntityId = entityId; this.Action = action; }
/// <summary> /// درصورتی از این توابع استفاده شود که جدول مورد نظر به صورت روتین باشد /// </summary> /// <param name="userId"></param> /// <param name="RoutinId"></param> /// <param name="EntityId"></param> /// <param name="Action"></param> /// <param name="Description"></param> /// <returns></returns> public async Task <Routine2ChangeStepResult> ChangeStep(int userId, int RoutinId, int EntityId, Routine2Actions Action, string Description) { // گرفتن رکورد مورد نظر var entity = Entities.Find(EntityId); // زمان فعلی DateTime NowDateTime = DateTime.Now; // درصورتی که رکورد مورد نظر وجود نداشت باید خطا برگردانده شود if (entity == null) { throw new Exception($"دادهای با شناسه {EntityId} یافت نشد"); } // مرحله بعدی فرآیند دراین قسمت به دست میآید var nextStep = await GetNextStep(1, RoutinId, Action); // درصورتی که مرحله بعدی -1 باشد باید خطا نمایش داده شود if (nextStep == -1) { throw new Exception("Something went wrong, next dashboard couldn't be -1"); } // مرحله فعلی به دست آمده تا بتوان در ادامه با استفاده از آن تارخچه ثبت کنیم int fromStep = Convert.ToInt32(entity.GetPropertyValue("RoutineStep")); int RoutineStep = fromStep; #region ثبت لاگ جدید برای این کاربر که رکورد مورد را از یک مرحله به مرحله دیگر انتقال داده است CreateLog(new CreateRoutine2LogViewModel { RoutineId = RoutinId, EntityId = EntityId, Description = Description, Action = await GetActionTitle(RoutinId, fromStep, Action), Step = fromStep, ToStep = nextStep, UserId = userId, CreatorUserId = userId, RoutineRoleTitle = await GetRoutineRoleTitle(RoutinId, RoutineStep), }); #endregion var routineVm = new EditRoutine2ViewModel(nextStep, Convert.ToDateTime(entity.GetPropertyValue("RoutineFlownDate").ToString())); // اگر در مرحله آخر باشیم، باید به روال برچست تمام شده بزنیم //if (entity.DoneSteps.Contains(nextStep)) // routineVm.RoutineIsDone = true; //// در صورتی که این آیتم مقدار درستی را اختیار کند، یعنی روتین به اتمام رسیده است //if (entity.SucceededSteps.Contains(nextStep)) // routineVm.RoutineIsSucceeded = true; entity.SetPropertyValue("RoutineStep", nextStep); entity.SetPropertyValue("RoutineFlownDate", NowDateTime); entity.SetPropertyValue("RoutineStepChangeDate", NowDateTime); await DbContext.SaveChangesAsync(); var changeStepResult = new Routine2ChangeStepResult { Action = Action, Description = Description, UserId = userId, ToStep = nextStep, FromStep = fromStep, EntityId = EntityId, RoutineId = RoutinId, }; //TODO //try { await _routine2Repository.SendNoticeAsync(changeStepResult); } catch (Exception) { } return(changeStepResult); }
public async Task <ServiceResult <Routine2ChangeStepResult> > ChangeStep(int id, Routine2Actions action, string description, int userId) { try { var entity = _context.Test.FirstOrDefault(q => q.Id == id); if (entity == null) { throw new Exception($"دادهای با شناسه {id} یافت نشد"); } var nextStep = GetNextStep(id, action); if (nextStep == -1) { throw new Exception("Something went wrong, next dashboard couldn't be -1"); } var fromStep = entity.RoutineStep; _routine2Repository.CreateLog(new CreateRoutine2LogViewModel { RoutineId = TestRoutine.RoutineId, EntityId = id, Description = description, Action = _routine2Repository.GetActionTitle(TestRoutine.RoutineId, fromStep, action), Step = fromStep, ToStep = nextStep, UserId = userId, CreatorUserId = userId, RoutineRoleTitle = _routine2Repository.GetRoutineRoleTitle(TestRoutine.RoutineId, entity.RoutineStep), }); var routineVm = new EditRoutine2ViewModel(nextStep, entity.RoutineFlownDate); // اگر در مرحله آخر باشیم، باید به روال برچست تمام شده بزنیم if (TestRoutine.DoneSteps.Contains(nextStep)) { routineVm.RoutineIsDone = true; } // به صورت پیشفرض طرح رد شده است، مگر اینکه در مراحل تایید باشیم if (TestRoutine.SucceededSteps.Contains(nextStep)) { routineVm.RoutineIsSucceeded = true; } Mapper.Map(routineVm, entity); _context.SaveChanges(); var changeStepResult = new Routine2ChangeStepResult { Action = action, Description = description, UserId = userId, ToStep = nextStep, FromStep = fromStep, EntityId = entity.Id, RoutineId = TestRoutine.RoutineId, }; //try { await _routine2Repository.SendNoticeAsync(changeStepResult); } catch (Exception ex) { } return(ServiceResult <Routine2ChangeStepResult> .Okay(changeStepResult)); } catch (Exception ex) { return(ServiceResult <Routine2ChangeStepResult> .Exception(ex)); } }