public IActionResult Manage(int routineId, int from, int?to, RoutneAction action) { if (action == RoutneAction.ConfirmAndFinihs || action == RoutneAction.Cancel) { to = null; } _context.RoutineSteps.Add(new RoutineStep { Action = action, FromStep = from, ToStep = to, RoutineId = routineId }); _context.SaveChanges(); return(RedirectToAction(nameof(Manage), new { id = routineId })); }
public IActionResult ChangeDash(int id, DashboardType type, string dashboard = "", RoutneAction action = RoutneAction.Send, int recordId = 0) { var userId = Convert.ToInt32(User.Identity.Name); var routine = _context.Routines.Include(c => c.Steps).FirstOrDefault(c => c.Id.Equals(id)); var tblName = routine.TitleEn; var record = _connection.Query <dynamic>($"select * from {tblName} where Id={recordId}").FirstOrDefault(); var currentStep = record.RoutineStep; var toStep = routine.Steps.Where(c => c.Action == action && c.FromStep == currentStep).FirstOrDefault().ToStep; // log _context.RoutineLog.Add(new RoutineLog { Action = action, FromStep = currentStep, UserId = userId, RoutineId = id, ToStep = toStep, EntityId = recordId }); _context.SaveChanges(); var toStepStr = "null"; if (toStep.HasValue) { toStepStr = toStep.Value.ToString(); } // update current record var update_query = $"update {tblName} set RoutineStep={toStepStr} ,"; if (!record.RoutineIsFlown) { update_query += " RoutineIsFlown=1 ,"; } if (action == RoutneAction.ConfirmAndFinihs) { update_query += " RoutineIsDone=1 , RoutineIsSuccess=1 ,"; } if (action == RoutneAction.Cancel) { update_query += " RoutineIsDone=1 , RoutineIsSuccess=0 ,"; } if (update_query.EndsWith(",")) { update_query = update_query.Remove(update_query.Length - 1); } update_query += $" where Id={recordId}"; var update_query_result = _connection.Execute(update_query); return(RedirectToAction(nameof(Manage), new { id = id, type = type, dashboard = dashboard })); }