public ActionResult JoinIn(FormCollection f) { int ceid = int.Parse(f["ceId"]); var exam = db.ChairitiesExams.SingleOrDefault(r => r.CharityExamID == ceid); var begin = exam.Examination.BeginDate; DateTime now = System.DateTime.Now; var equal = new TimeSpan(); equal = now - begin; double totalMilliseconds = equal.TotalMilliseconds; if (Math.Abs((totalMilliseconds / 86400000)) > 3) { Account acc = (Account) Session["acc"]; Volunteer vo = db.Volunteers.SingleOrDefault(r => r.AccountID == acc.AccountID); ParticipantVolunteer pe = new ParticipantVolunteer(); pe.VolunteerID = vo.VolunteerID; pe.CharityExamID = int.Parse(f["ceId"]); pe.IsApproved = false; db.ParticipantVolunteers.Add(pe); db.SaveChanges(); return RedirectToAction("Index"); } return RedirectToAction("ErrorPage", "Home"); }
protected bool AssignTheVolunteer(List<ExaminationsPaper> eps, IEnumerable<ParticipantVolunteer> pvs) { ParticipantVolunteer pv = new ParticipantVolunteer(); foreach (ExaminationsPaper ep in eps) if (ep.CarID == null && ep.ParticipantVolunteerID == null) // this ep need to be assigned. { pv = pvs.FirstOrDefault(r => r.ExamPaperID == null); if (pv == null) // there is no volunteer available now! --> cannot assigning anymore! { db.SaveChanges(); return false; } ep.ParticipantVolunteerID = pv.ParticipantVolunteerID; pv.ExamPaperID = ep.ExamPaperID; } db.SaveChanges(); return true; // assigned all successful! }
public ActionResult ResetCars(int id, bool ReAssign) { ChairitiesExam ce = db.ChairitiesExams.SingleOrDefault(r => r.CharityExamID == id); var cars = ce.Cars; foreach (Car c in cars) { c.AvailableSlots = c.TotalSlots; } ParticipantVolunteer pe = new ParticipantVolunteer(); var eps = ce.ExaminationsPapers; foreach (ExaminationsPaper ep in eps) { ep.CarID = null; if (ep.ParticipantVolunteerID != null) { pe = db.ParticipantVolunteers.SingleOrDefault(r => r.ParticipantVolunteerID == ep.ParticipantVolunteerID); pe.ExamPaperID = null; ep.ParticipantVolunteerID = null; } } db.SaveChanges(); if (!ReAssign) return RedirectToAction("AssignCar", new { id = id }); else return RedirectToAction("AssignToCar", new { id = id }); }