public static void UpdateAskForLeave(AskForLeave a) { SmallSimpleOAContext ctx = new SmallSimpleOAContext(); ctx.Update(a); ctx.SaveChanges(); }
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 static AskForLeave FindAskForLeaveById(int id) { SmallSimpleOAContext ctx = new SmallSimpleOAContext(); AskForLeave ask = ctx.AskForLeave.FirstOrDefault(a => a.Id.Equals(id) && a.Valid == true); ctx.Entry(ask).Reference(a => a.CurrentAt).Load(); ctx.Entry(ask).Reference(a => a.Applicant).Load(); return(ask); }
public static void RejectAskForLeave(AskForLeave ask) { SmallSimpleOAContext ctx = new SmallSimpleOAContext(); ctx.Update(ask); ask.CurrentAt.LeaveRequests.Remove(ask); ask.Status = (int)AskForLeaveStatus.Rejected; ctx.SaveChanges(); }
private void Askforleave_click(object sender, EventArgs e) { AskForLeave askforleave = new AskForLeave(); askforleave.TopLevel = false; askforleave.Dock = DockStyle.Fill; this.Student_panel.Controls.Add(askforleave); askforleave.Show(); }
public static AskForLeave AddAskForLeave(Uzer u, DateTime startTime, DateTime endTime, DateTime appTime, string reason, string memo) { AskForLeave afl = new AskForLeave(); afl.Valid = true; afl.StartTime = startTime; afl.EndTime = endTime; afl.AppTime = appTime; afl.Reason = reason; afl.Memo = memo; afl.Status = (int)AskForLeaveStatus.Applied; SmallSimpleOAContext ctx = new SmallSimpleOAContext(); ctx.Update(u); u.AskForLeaves.Add(afl); u.LeaveRequests.Add(afl); ctx.SaveChanges(); return(afl); }
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 })); }
public static void AskFlowToNextSupervisor(AskForLeave ask) { SmallSimpleOAContext ctx = new SmallSimpleOAContext(); Uzer supervisor = UserService.FindSupervisorByUid(ask.CurrentAt.Id); if (supervisor == null) { ctx.Update(ask); ask.Status = (int)AskForLeaveStatus.Approved; ask.CurrentAt.LeaveRequests.Remove(ask); ctx.SaveChanges(); } else { ctx.Update(ask); ask.Status = (int)AskForLeaveStatus.Reviewing; ask.CurrentAt.LeaveRequests.Remove(ask); ctx.SaveChanges(); ctx.Update(supervisor); supervisor.LeaveRequests.Add(ask); ctx.SaveChanges(); } }
public AskForLeaveDetailViewModel(AskForLeave ask) { AskForLeave = ask; }