public ActionResult Create(Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return RedirectToAction("Index"); } return View(student); }
// GET api/Student/5 public Student GetStudent(string id) { //Student student = db.Students.Find(id); //if (student == null) //{ // throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); //} //String[] tmpUserArr = id.Split('@'); String tmpUser = id.Split('@')[1]; Student testSession = new Student(); if (Global.USERSIN.Contains(id.Split('@')[1])) { testSession.password = "******"; testSession.stuName = id.Split('@')[0]; } return testSession; //return student; }
public ActionResult Edit(Student student) { if (ModelState.IsValid) { db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(student); }
// PUT api/Student/5 public HttpResponseMessage PutStudent(string id, Student student) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != student.stuName) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(student).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/Student public HttpResponseMessage PostStudent(Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, student); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = student.stuName })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// POST api/Auth public HttpResponseMessage PostStudent(Student student) { UBOnlineWebApiTest2Context db = new UBOnlineWebApiTest2Context(); if (ModelState.IsValid) { //db.Students.Add(student); //db.SaveChanges(); IQueryable<Student> stuOut = from s in db.Students where (s.stuName == student.stuName && s.password == student.password) orderby s.stuName select s; if (stuOut.Count<Student>()!=0) { //HttpContext.Current.Session["USERNAME"] = stuOut.ToList<Student>().ElementAt<Student>(0).stuName; //SessionFacade.USERNAME = stuOut.ToList<Student>().ElementAt<Student>(0).stuName; //Console.WriteLine(SessionFacade.USERNAME); //Application["USERNAME"] = stuOut.ToList<Student>().ElementAt<Student>(0).stuName; Global.USERSIN.Add(stuOut.ToList<Student>().ElementAt<Student>(0).stuName); } if (stuOut != null && stuOut.Count<Student>() != 0) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, student.stuName); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = student.stuName })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }