public IActionResult DoAction(string id, string act) { int?uid = HttpContext.Session.GetInt32("uid"); if (uid == null) { return(RedirectToAction("Login", "Login")); } int askId; if (!Int32.TryParse(id, out askId)) { return(RedirectToAction("List", "AskForLeave")); } AskForLeave ask = AskForLeaveService.FindAskForLeaveById(askId); if (ask == null) { return(RedirectToAction("List", "AskForLeave")); } if (act.Equals("reject")) { AskForLeaveService.RejectAskForLeave(ask); } else if (act.Equals("approve")) { AskForLeaveService.AskFlowToNextSupervisor(ask); } return(RedirectToAction("Home", "Home")); }
public IActionResult Home(string ep, string tp) { const int PAGE_SIZE = 10; int? uid = HttpContext.Session.GetInt32("uid"); if (uid == null) { return(RedirectToAction("Login", "Login")); } int eventPage, todoPage; if (!Int32.TryParse(ep, out eventPage)) { eventPage = 1; } if (!Int32.TryParse(tp, out todoPage)) { todoPage = 1; } Uzer u = UserService.FindUserByID((int)uid); int eventCount = AskForLeaveService.FindCountByCurrentAt(u); int todoCount = TodoTaskService.FindUndoneCountByUser((int)uid); int eventPages = eventCount % PAGE_SIZE == 0 ? eventCount / PAGE_SIZE : eventCount / PAGE_SIZE + 1; int todoPages = todoCount % PAGE_SIZE == 0 ? todoCount / PAGE_SIZE : todoCount / PAGE_SIZE + 1; if (eventPage > eventPages) { eventPage = eventPages; } if (todoPage > todoPages) { todoPage = todoPages; } if (eventPage <= 0) { eventPage = 1; } if (todoPage <= 0) { todoPage = 1; } List <AskForLeave> asks = AskForLeaveService.FindAskForLeaveByCurrentAtAndPageAndPagesize(u, eventPage, PAGE_SIZE); List <TodoTask> todos = TodoTaskService.FindUndoneTodoTaskByUserAndPageAndPagesize((int)uid, todoPage, PAGE_SIZE); List <Attendance> attendanceList = AttendanceService.FindAttendanceByUserAndDateAndType((int)uid, DateTime.Now, AttendanceType.In); Boolean need = (attendanceList == null || attendanceList.Count <= 0) ? true : false; HomeHomeViewModel homeHomeViewModel = new HomeHomeViewModel(asks, eventPages, eventPage, todos, todoPages, todoPage, need); return(View(homeHomeViewModel)); }
public IActionResult Detail(string id) { int?uid = HttpContext.Session.GetInt32("uid"); if (uid == null) { return(RedirectToAction("Login", "Login")); } int i; if (null == id || !Int32.TryParse(id, out i)) { return(RedirectToAction("List", "AskForLeave")); } AskForLeave ask = AskForLeaveService.FindAskForLeaveById(i); AskForLeaveDetailViewModel model = new AskForLeaveDetailViewModel(ask); return(View(model)); }
public IActionResult DoNew(string startTime, string endTime, string reason, string memo) { string result = "0"; if (startTime == null || endTime == null || reason == null || startTime.Trim().Equals("") || endTime.Trim().Equals("") || reason.Trim().Equals("") ) { result = "Fields of 'From', 'To' and 'Reason' should be filled."; return(RedirectToAction("New", "AskForLeave", new { r = result })); } int?uid = HttpContext.Session.GetInt32("uid"); DateTime st, et; if (!DateTime.TryParse(startTime, out st) || !DateTime.TryParse(endTime, out et)) { result = "Time format not valid."; return(RedirectToAction("New", "AskForLeave", new { r = result })); } if (uid == null) { return(RedirectToAction("Login", "Login")); } Uzer u = UserService.FindUserByID((int)uid); AskForLeave ask = AskForLeaveService.AddAskForLeave(u, st, et, DateTime.Now, reason, memo); AskForLeaveService.AskFlowToNextSupervisor(ask); return(RedirectToAction("New", "AskForLeave", new { r = result })); }
// GET: /<controller>/ public IActionResult List(string p) { const int PAGE_SIZE = 10; int? uid = HttpContext.Session.GetInt32("uid"); if (uid == null) { return(RedirectToAction("Login", "Login")); } int page; if (!Int32.TryParse(p, out page)) { page = 1; } Uzer u = UserService.FindUserByID((int)uid); int count = AskForLeaveService.FindCountByApplicant(u); int pages = count % PAGE_SIZE == 0 ? count / PAGE_SIZE : count / PAGE_SIZE + 1; if (page > pages) { page = pages; } if (page <= 0) { page = 1; } List <AskForLeave> asks = AskForLeaveService.FindAskForLeaveByApplicantAndPageAndPagesize(u, page, PAGE_SIZE); AskForLeaveListViewModel askForLeaveListViewModel = new AskForLeaveListViewModel(asks, pages, page); return(View(askForLeaveListViewModel)); }