public ActionResult CreateJob(PeopleJobvm pjvm) { if (ModelState.IsValid) { Vaktir vakt = new Vaktir(); vakt.Date = pjvm.job.Date; vakt.End = pjvm.job.End; vakt.Start = pjvm.job.Start; vakt.Type = pjvm.job.Type; vakt.PersonID = pjvm.job.PersonID; string id = pjvm.job.PersonID; vakt.Type = pjvm.job.Type; Person vaktPerson = new Person(); vaktPerson = dbm.allPeoples.Find(x => x.PersonID.Equals(id)); vakt.Person = vaktPerson; dbm.addJob(vakt); String output = "Vakt no: " + vakt.VaktID + " has been added to database"; TempData["Success"] = output; return(RedirectToAction("Jobs")); } pjvm.ListOfPersons = dbm.allPeoples; return(View(pjvm)); }
public void releaseJob(Vaktir vakt) { var vaktToRelease = from v in vse.Vaktir where v.VaktID == vakt.VaktID select v; foreach (var v in vaktToRelease) { v.isFree = true; } try { vse.SaveChanges(); } /*catch (System.Exception e) * { * System.Console.WriteLine(e); * }*/ catch (System.Data.Entity.Validation.DbEntityValidationException ex) { foreach (var validationErrors in ex.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { System.Console.WriteLine("Property: {0} throws Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } }
public ActionResult EditJob(PeopleJobvm viewModel) { if (ModelState.IsValid) { Vaktir v = new Vaktir(); v.VaktID = viewModel.id; v.isFree = viewModel.job.isFree; v.Date = viewModel.job.Date; v.Start = viewModel.job.Start; v.End = viewModel.job.End; v.Type = viewModel.job.Type; v.PersonID = viewModel.job.PersonID; v.Person = dbm.getPerson(viewModel.job.PersonID); dbm.updateJob(v); String output = "vakt no" + v.VaktID + " has been updated"; TempData["Success"] = output; return(RedirectToAction("Jobs")); } viewModel.ListOfPersons = dbm.allPeoples; return(View(viewModel)); }
public ActionResult Take(int id) { Vaktir Vakt = dbm.allJobs.FirstOrDefault(v => v.VaktID == id); dbm.takeJob(Vakt); return(RedirectToAction("FreeVakt")); }
public ActionResult release(int id) { Vaktir Vakt = dbm.allJobs.FirstOrDefault(v => v.VaktID == id); dbm.releaseJob(Vakt); return(RedirectToAction("UserMain")); }
public ActionResult EditJob(int id) { Vaktir v = dbm.getVakt(id); PeopleJobvm viewModel = new PeopleJobvm(); viewModel.job = v; viewModel.ListOfPersons = dbm.allPeoples; return(View(viewModel)); }
public ActionResult TakeVakt(int id) { Vaktir Vakt = dbm.allJobs.FirstOrDefault(v => v.VaktID == id); if (dbm.takeJob(Vakt)) { return(RedirectToAction("FreeVakts")); } return(RedirectToAction("FreeVakts/1")); }
public bool deleteJob(Vaktir dVakt) { Vaktir tmpVakt = vse.Vaktir.Find(dVakt.VaktID); if (tmpVakt != null) { vse.Vaktir.Remove(dVakt); vse.SaveChanges(); return(true); } else { return(false); } }
public void updateJob(Vaktir v) { if (v != null) { vse.Vaktir.Find(v.VaktID).Date = v.Date; vse.Vaktir.Find(v.VaktID).End = v.End; vse.Vaktir.Find(v.VaktID).isFree = v.isFree; vse.Vaktir.Find(v.VaktID).Person = v.Person; vse.Vaktir.Find(v.VaktID).PersonID = v.PersonID; vse.Vaktir.Find(v.VaktID).Start = v.Start; vse.Vaktir.Find(v.VaktID).Type = v.Type; vse.SaveChanges(); } }
public ActionResult DeleteJob(int id) { Vaktir deleteVakt = dbm.getVakt(id); if (dbm.deleteJob(deleteVakt)) { String output = "Vakt no: " + deleteVakt.VaktID + " has been deleted"; TempData["Success"] = output; } else { String output = "Vakt no: " + deleteVakt.VaktID + " could not be deleted"; } return(RedirectToAction("Jobs")); }
public bool takeJob(Vaktir vakt) { bool canWork = true; var vaktToTake = from v in vse.Vaktir where v.VaktID == vakt.VaktID select v; var checkvakt = from v in vse.Vaktir where v.Date == vakt.Date where v.PersonID == LoggedIn.username select v; foreach (var v in checkvakt) { if ((vakt.Start > v.Start && vakt.Start < v.End) && (vakt.End > v.Start && vakt.End < v.End)) { canWork = false; } } if (canWork) { foreach (var v in vaktToTake) { v.isFree = false; v.PersonID = LoggedIn.username; } try { vse.SaveChanges(); } catch (System.Exception e) { System.Console.WriteLine(e); } } return(canWork); }
public void release(VaktirDTO vakt) { Vaktir Vakt = dbm.allJobs.FirstOrDefault(v => v.VaktID == vakt.VaktID); dbm.releaseJob(Vakt); }
public void addJob(Vaktir vakt) { vse.Vaktir.Add(vakt); vse.SaveChanges(); }
public Vaktir getVakt(int id) { Vaktir returnVakt = vse.Vaktir.Find(id); return(returnVakt); }