public ActionResult Delete(int id, string rtnact) { var ctx = new TaskAssignmentModel(); var task = ctx.Tasks.SingleOrDefault(t => t.Id == id); var asg = ctx.Assigns.Where(a => a.TaskId == id); if (asg != null && asg.Count() > 0) { ctx.Assigns.RemoveRange(asg); } // Notice: Attendance cascaded delete has been implement in DB by trigger if (task != null && task.Id != 0) { ctx.Tasks.Remove(task); ctx.SaveChanges(); // Won't work currently //ViewBag.Success = true; //ViewBag.Message = "该工作已删除。"; } if (rtnact == null || rtnact.Length == 0) { return(RedirectToAction("Add")); } else { return(RedirectToAction(rtnact)); } }
public ActionResult Edit(AddTask model) { if (model != null && model.Task != null && model.Task.Id > 0) { var ctx = new TaskAssignmentModel(); var task = ctx.Tasks.SingleOrDefault(t => t.Id == model.Task.Id); ctx.Assigns.RemoveRange(task.Assigns); task.ConditionId = model.Task.ConditionId; task.Content = model.Task.Content; task.Date = model.Task.Date; task.SubstationId = model.Task.SubstationId; task.TypeId = model.Task.TypeId; //task.Visible = model.Task.Visible; // Notice: Attendance cascaded delete has been implement in DB by trigger if (model.LeaderId > 0) { Assign leader = new Assign(); leader.MemberId = model.LeaderId; leader.IsLeader = true; leader.TaskId = task.Id; ctx.Assigns.Add(leader); Attendance att = new Attendance(); att.TaskId = model.Task.Id; att.MemberId = model.LeaderId; att.TypeId = Type4Outdoor; // The Type of outside work in DB is 2 (reffer to AttendanceType) att.StartDate = task.Date; att.FinishDate = task.Date; ctx.Attendances.Add(att); } foreach (var item in model.MemberId) { Assign asg = new Assign(); asg.MemberId = item; asg.IsLeader = false; asg.TaskId = task.Id; Attendance att = new Attendance(); att.TaskId = model.Task.Id; att.MemberId = item; att.TypeId = Type4Outdoor; // The Type of outside work in DB is 2 (reffer to AttendanceType) att.StartDate = task.Date; att.FinishDate = task.Date; ctx.Assigns.Add(asg); ctx.Attendances.Add(att); } ctx.SaveChanges(); } if (string.IsNullOrEmpty(model.ReturnAction)) { model.ReturnAction = "Add"; } return(RedirectToAction(model.ReturnAction)); }
public ActionResult Delete(long id) { var ctx = new TaskAssignmentModel(); var item = ctx.Attendances.SingleOrDefault(att => att.Id == id); ctx.Attendances.Remove(item); ctx.SaveChanges(); return(RedirectToAction("Absent")); }
public void TaskAdd_Test() { var ctx = new TaskAssignmentModel(); Task t = new Task(); t.Content = "Test task2"; t.Date = DateTime.Today; t.ConditionId = 2; t.TypeId = 1; ctx.Tasks.Add(t); ctx.SaveChanges(); }
public ActionResult Edit(AddAbsence model) { var ctx = new TaskAssignmentModel(); var item = ctx.Attendances.SingleOrDefault(abs => abs.Id == model.Attendance.Id); item.MemberId = model.Attendance.MemberId; item.StartDate = model.Attendance.StartDate; item.FinishDate = model.Attendance.FinishDate; item.TypeId = model.Attendance.TypeId; item.Comments = model.Attendance.Comments; ctx.SaveChanges(); string[] url = model.ReturnAction.Split('?'); return(RedirectToAction(url[0], new { id = url[1].Split('=')[1] })); }
public ActionResult Add(AddTask model) { // Only invoke in Add.cshtml Task t = model.Task; var ctx = new TaskAssignmentModel(); t.Visible = true; ctx.Tasks.Add(t); if (model.LeaderId > 0) { Assign leader = new Assign(); leader.MemberId = model.LeaderId; leader.IsLeader = true; leader.TaskId = t.Id; ctx.Assigns.Add(leader); Attendance att = new Attendance(); att.TaskId = t.Id; att.MemberId = model.LeaderId; att.StartDate = t.Date; att.FinishDate = t.Date; ctx.Attendances.Add(att); } foreach (var item in model.MemberId) { Assign asg = new Assign(); asg.MemberId = item; asg.IsLeader = false; asg.TaskId = t.Id; Attendance att = new Attendance(); att.TaskId = t.Id; att.MemberId = item; att.TypeId = Type4Outdoor; // The Type of outside work in DB is 2 (reffer to AttendanceType) att.StartDate = t.Date; att.FinishDate = t.Date; ctx.Assigns.Add(asg); ctx.Attendances.Add(att); } ctx.SaveChanges(); ViewBag.Success = true; ViewBag.Message = "该工作已添加。"; return(View()); }
public ActionResult Add(AddAbsence model) { var ctx = new TaskAssignmentModel(); ctx.Attendances.Add(model.Attendance); ctx.SaveChanges(); string[] url; if (!string.IsNullOrEmpty(model.ReturnAction)) { url = model.ReturnAction.Split('?'); string act = url[0]; string query = ""; if (url.Length > 1) { query = url[1].Split('=')[1]; } return(RedirectToAction(act, new { id = query })); } else { return(RedirectToAction("Absent")); } }