//POST api/class public IHttpActionResult CreateClass(Class pClass) { if (!ModelState.IsValid) { return(BadRequest()); } _context.Classes.Add(pClass); _context.SaveChanges(); return(Created(new Uri(Request.RequestUri + "/" + pClass.ID_Class), pClass)); }
public IHttpActionResult CreateUniversity(University university) { if (!ModelState.IsValid) { return(BadRequest()); } _context.Universities.Add(university); _context.SaveChanges(); return(Created(new Uri(Request.RequestUri + "/" + university.ID_Uni), university)); }
public IHttpActionResult CreateDepartment(Department department) { if (!ModelState.IsValid) { return(BadRequest()); } _context.Departments.Add(department); _context.SaveChanges(); return(Created(new Uri(Request.RequestUri + "/" + department.ID_Dep), department)); }
public IHttpActionResult CreateStudent(Student student) { if (!ModelState.IsValid) { //throw new HttpResponseException(HttpStatusCode.BadRequest); return(BadRequest()); } //var student = Mapper.Map<StudentDTO, Student>(studentDTO); _context.Students.Add(student); _context.SaveChanges(); return(Created(new Uri(Request.RequestUri + "/" + student.ID_Stu), student)); }
public ActionResult Delete(Student student) { string id = student.ID_Stu; List <Student> students = _context.Students.ToList(); foreach (var stu in students) { if (stu.ID_Stu == id) { _context.Students.Remove(stu); _context.SaveChanges(); break; } } return(RedirectToAction("ListOut", "Student")); }
public ActionResult CreateUniversity(University university) { if (!ModelState.IsValid) { var temp = university; return(View("NewUniversity", temp)); } try { _context.Universities.Add(university); _context.SaveChanges(); } catch (DbEntityValidationException e) { Console.WriteLine(e); } return(RedirectToAction("ListOutUniversity", "University")); }
public ActionResult CreateClass(DepClassModel depClass) { if (!ModelState.IsValid) { var temp = depClass; return(View("NewClass", temp)); } Class nClass = depClass.newClass; try { _context.Classes.Add(nClass); _context.SaveChanges(); } catch (DbEntityValidationException e) { Console.WriteLine(e); } return(RedirectToAction("ListOutClass", "Class")); }
public ActionResult CreateDepartment(UniDepModel uniDep) { if (!ModelState.IsValid) { var temp = uniDep; return(View("NewDepartment", temp)); } Department nDep = uniDep.department; try { _context.Departments.Add(nDep); _context.SaveChanges(); } catch (DbEntityValidationException e) { Console.WriteLine(e); } return(RedirectToAction("ListOutDepartment", "Department")); }