public ActionResult AddEditlab(int?id, lab model) { try { if (ModelState.IsValid) { bool isNew = !id.HasValue; if (isNew) { _repo.labs.Insert(model); _repo.Save(); } else { _repo.labs.Update(model); } } } catch (Exception ex) { throw ex; } return(RedirectToAction("Index")); }
private void AddStudToLab(student s, lab l) { // add stud to new lab context.AddStudToLab(s, l); // add present for each labdate for student context.GetLabdatesOfLab(l.labID) .ForEach(lD => { dataAccess.PresentContext.AddOne( new present { labdate_labdateID = lD.labdateID, note = "", student_studentID = s.studentID, wasPresent = 0 }); }); // add TaskDone for each Task for student context.GetTasksOfLab(l.labID) .ForEach(t => { dataAccess.TaskDoneContext.AddOne( new taskdone { isDone = 0, student_studentID = s.studentID, task_taskID = t.taskID }); }); }
public ActionResult Save(lab com) { bool status = false; if (ModelState.IsValid) { using (TCMSDBEntities dc = new TCMSDBEntities()) { if (com.LabNo > 0) { // Edit var v = dc.labs.Where(a => a.LabNo == com.LabNo).FirstOrDefault(); if (v != null) { v.LabNo = com.LabNo; v.floor = com.floor; } else { //Save dc.labs.Add(com); } } dc.SaveChanges(); status = true; } } return(new JsonResult { Data = new { status = status, message = "Saved Successfully" } }); }
//rempve lab public void deletelab(int id) { lab labtodelete = db.labs.Where(a => a.lab_id == id).FirstOrDefault(); db.labs.Remove(labtodelete); db.SaveChanges(); }
public ActionResult DeleteConfirmed(int id) { lab lab = db.labs.Find(id); db.labs.Remove(lab); db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Deletelab(int id) { lab lab = _repo.labs.GetById(id); _repo.labs.Delete(id); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "lab_id,patient_id,test_name,test_cost")] lab lab) { if (ModelState.IsValid) { db.Entry(lab).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(lab)); }
public course GetCourseOfLab(int id) { using (se02team06 context = new se02team06()) { DbSet <lab> dbsetLab = context.Set <lab>(); lab labTmp = dbsetLab.Find(id); context.Entry(labTmp).Reference(s => s.course).Load(); context.SaveChanges(); return(labTmp.course); } }
public List <student> GetStudentsOfLab(int id) { using (se02team06 context = new se02team06()) { DbSet <lab> dbsetLab = context.Set <lab>(); lab labTmp = dbsetLab.Find(id); context.Entry(labTmp).Collection(s => s.students).Load(); context.SaveChanges(); return(labTmp.students.ToList()); } }
public ActionResult Create([Bind(Include = "lab_id,patient_id,test_name,test_cost")] lab lab) { if (ModelState.IsValid) { db.labs.Add(lab); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(lab)); }
private void FillLabs() { courseNames.ForEach(course => { labNumber.ForEach(lab => { lab tmpLab = new lab { labNumber = labNumber[labNumber.IndexOf(lab)] }; labsDbset.AddLab(tmpLab, courseNames.IndexOf(course) + 1); }); }); }
// update data public void updateLab(labVM labvm) { lab labtoupdate = db.labs.Where(a => a.lab_id == labvm.lab_id).FirstOrDefault(); labtoupdate.lab_name = labvm.lab_name; labtoupdate.lab_number = labvm.lab_number; labtoupdate.description = labvm.description; labtoupdate.floor_number = labvm.floor_number; labtoupdate.service_id = labvm.service_id; db.SaveChanges(); }
public IActionResult Postlab([FromBody] lab lab) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.labs.Insert(lab); return(CreatedAtAction("Getlab", new { id = lab.id }, lab)); }
public void AddStudToLab(student student, lab lab) { using (se02team06 context = new se02team06()) { DbSet <student> dbsetStudent = context.Set <student>(); DbSet <lab> dbsetLab = context.Set <lab>(); var tmpStud = dbsetStudent.Find(student.studentID); var tmpLab = dbsetLab.Find(lab.labID); tmpStud.labs.Add(tmpLab); context.SaveChanges(); } }
public lab AddLab(lab lab, int id) { using (se02team06 context = new se02team06()) { DbSet <lab> dbsetLab = context.Set <lab>(); DbSet <course> dbsetCourse = context.Set <course>(); lab.course_courseID = id; lab tmplab = dbsetLab.Add(lab); context.SaveChanges(); return(tmplab); } }
private void FillLabs() { courseNames.ForEach(course => { labNumber.ForEach(lab => { lab tmpLab = new lab { labNumber = labNumber[labNumber.IndexOf(lab)] }; labsDbset.AddLab(tmpLab, courseNames.IndexOf(course) + 1); }); }); Console.WriteLine("- - - - - - - Finished - - - - -"); }
//adding a lab public void AddLab(labVM labVM) { lab labToAdd = new lab(); labToAdd.lab_name = labVM.lab_name; labToAdd.lab_number = labVM.lab_number; labToAdd.description = labVM.description; labToAdd.floor_number = labVM.floor_number; labToAdd.service_id = labVM.service_id; db.labs.Add(labToAdd); db.SaveChanges(); }
// GET: labs/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } lab lab = db.labs.Find(id); if (lab == null) { return(HttpNotFound()); } return(View(lab)); }
public IActionResult AddEditLab(int?id) { lab model = new lab(); if (id.HasValue) { lab lab = _repo.labs.GetById(id.Value); if (lab != null) { model = lab; } } return(View(model)); }
public ActionResult Delete(int id) { using (TCMSDBEntities dc = new TCMSDBEntities()) { lab aa = new lab(); var v = dc.labs.Where(a => a.LabNo == id).FirstOrDefault(); if (v != null) { return(View(v)); } else { return(HttpNotFound()); } } }
public Lab ConvertLab(lab l) { Lab labor = new Lab { LabID = l.labID, LabNumber = l.labNumber, Course_courseID = l.course_courseID, Course = new Course(), Labdates = new List <Labdate>(), Tasks = new List <Tasks>(), Students = new List <Student>(), //new Property for UI LabDateCount = Context.GetLabdatesOfLab(l.labID).Count, StudentCount = Context.GetStudentsOfLab(l.labID).Count }; return(labor); }
// get lab by id public labVM getLabById(int id) { lab mylab = db.labs.Where(a => a.lab_id == id).FirstOrDefault(); labVM labvm = new labVM(); if (mylab != null) { labvm.lab_id = mylab.lab_id; labvm.lab_name = mylab.lab_name; labvm.description = mylab.description; labvm.floor_number = mylab.floor_number; labvm.service_id = mylab.service_id; labvm.lab_number = mylab.lab_number; return(labvm); } else { return(null); } }
private void RemoveStudFromLab(student s, lab l) { // delete old presents of student context.GetLabdatesOfLab(LabID).ForEach(ld => { context.GetPresentsOfLabdate(ld.labdateID) .Where(p => p.student_studentID == s.studentID) .ToList() .ForEach(p => { dataAccess.PresentContext.Remove(p.presentID); }); }); // delete old taskDones of student context.GetTasksOfLab(LabID).ForEach(t => { context.GetTaskDonesOfTask(t.taskID) .Where(tD => tD.student_studentID == s.studentID) .ToList() .ForEach(tD => { dataAccess.TaskDoneContext.Remove(tD.taskDoneID); }); }); context.RemoveStudFromLab(s, l); }
public IActionResult Putlab([FromRoute] int id, [FromBody] lab lab) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != lab.id) { return(BadRequest()); } lab.id = id; _context.labs.Update(lab); if (!labExists(id)) { return(NotFound()); } return(NoContent()); }
public IActionResult Details(int id) { lab lab = _repo.labs.GetById(id); return(View(lab)); }
// Update lab object in db with user input private void UpdateLabDetails() { if (SelectedLabNumber != 0 && SelectedStartYear != 0 && SelectedStartMonth != "" && SelectedStartDay != 0 && SelectedLabDuration != 0 && SelectedTaskNumber != 0) { // update lab //how much task in lab int taskCount = 0; if (SelectedLabDuration < SelectedTaskNumber) { OpenError("Zu Viele Aufgaben für die Anzahl der Wochen."); return; } taskCount = SelectedTaskNumber; lab updatedLab = new lab { labID = LabID, course_courseID = CourseID, labNumber = SelectedLabNumber }; dataAccess.LabContext.Update(LabID, updatedLab); //new startDate DateTime newStartDate = new DateTime( SelectedStartYear, CourseDetailViewModel.ConvertMonthToInt(SelectedStartMonth), SelectedStartDay, SelectedStartHour, SelectedStartMinutes, 0); DateTime tmpDate = newStartDate; //Delete Old Labdates List <labdate> oldLabdates = dataAccess.Context.GetLabdatesOfLab(LabID); foreach (var labdate in oldLabdates) { dataAccess.LabDateContext.Remove(labdate.labdateID); } //Create New Labdates for (int i = 0; i < SelectedLabDuration; i++) { //make new labdate labdate labdate = new labdate { date = tmpDate, lab_labID = LabID }; //Each Week tmpDate = tmpDate.AddDays(7); //Add labdate dataAccess.LabDateContext.AddOne(labdate); } var newLabdates = dataAccess.Context.GetLabdatesOfLab(LabID); //delete old tasks List <task> oldTasks = dataAccess.Context.GetTasksOfLab(LabID); foreach (var task in oldTasks) { dataAccess.TaskContext.Remove(task.taskID); } //Create new Tasks for (int i = 0; i < taskCount; i++) { //make new Task task newTask = new task { taskNumber = i + 1, dueDate = newLabdates[i].date, lab_labID = LabID, }; //Add task dataAccess.TaskContext.AddOne(newTask); } var studentInLab = context.GetStudentsOfLab(LabID); var allLabdates = context.GetLabdatesOfLab(LabID); var alltask = context.GetTasksOfLab(LabID); studentInLab.ForEach(student => { alltask.ForEach(task => { taskdone newTask = new taskdone { student_studentID = student.studentID, isDone = 0, task_taskID = task.taskID }; dataAccess.TaskDoneContext.AddOne(newTask); }); allLabdates.ForEach(dates => { present newPresent = new present { note = "", wasPresent = 0, student_studentID = student.studentID, labdate_labdateID = dates.labdateID }; dataAccess.PresentContext.AddOne(newPresent); }); }); //Update courseDetailPage LabDateCount = newLabdates.Count; LabHour = newLabdates.First().date.Hour; LabMinute = newLabdates.First().date.Minute; LabWeekday = newLabdates.First().date.DayOfWeek.ToString(); LabNumber = "Labornummer: " + SelectedLabNumber.ToString();; LabTime = $"{LabWeekday}, {LabHour}:{LabMinute}"; RefreshCourseDetailView(); FillAll(); // Change visibility of lab EditLabViewVisible ^= true; Console.WriteLine(); } ; }
public Controller(lab <Technics> Product) { obj = Product; }