コード例 #1
0
        public IHttpActionResult PutInvigilator(int id, Invigilator invigilator)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != invigilator.InvigilatorId)
            {
                return(BadRequest());
            }

            db.Entry(invigilator).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InvigilatorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "InvigilatorId,Username,FirstName,LastName,EmailAddress,PhoneNumber")] Invigilator invigilator)
 {
     if (ModelState.IsValid)
     {
         db.Entry(invigilator).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(invigilator));
 }
コード例 #3
0
        public IHttpActionResult GetInvigilator(int id)
        {
            Invigilator invigilator = db.Invigilators.Find(id);

            if (invigilator == null)
            {
                return(NotFound());
            }

            return(Ok(invigilator));
        }
コード例 #4
0
        public ActionResult Create([Bind(Include = "InvigilatorId,Username,FirstName,LastName,EmailAddress,PhoneNumber")] Invigilator invigilator)
        {
            if (ModelState.IsValid)
            {
                db.Invigilators.Add(invigilator);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(invigilator));
        }
コード例 #5
0
        public IHttpActionResult PostInvigilator(Invigilator invigilator)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Invigilators.Add(invigilator);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = invigilator.InvigilatorId }, invigilator));
        }
コード例 #6
0
        public IHttpActionResult DeleteInvigilator(int id)
        {
            Invigilator invigilator = db.Invigilators.Find(id);

            if (invigilator == null)
            {
                return(NotFound());
            }

            db.Invigilators.Remove(invigilator);
            db.SaveChanges();

            return(Ok(invigilator));
        }
コード例 #7
0
        // GET: Invigilators/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Invigilator invigilator = db.Invigilators.Find(id);

            if (invigilator == null)
            {
                return(HttpNotFound());
            }
            return(View(invigilator));
        }
コード例 #8
0
        public ActionResult DeleteConfirmed(int id)
        {
            Invigilator invigilator = db.Invigilators.Find(id);
            List <InvigilatorSession> invigSessions = db.InvigilatorSessions.Where(invigSess => invigSess.InvigilatorId == id).ToList();

            foreach (var invig in invigSessions)
            {
                db.InvigilatorSessions.Remove(invig);
            }
            db.SaveChanges();
            db.Invigilators.Remove(invigilator);
            db.SaveChanges();
            return(RedirectToAction("Dashboard", "Home", null));
        }
コード例 #9
0
        public ActionResult CreateWithSession([Bind(Include = "InvigilatorId,Username,FirstName,LastName,EmailAddress,PhoneNumber")] Invigilator invigilator)
        {
            if (ModelState.IsValid)
            {
                db.Invigilators.Add(invigilator);
                db.SaveChanges();
                var sessionId = Convert.ToInt32(Request["SessionId"]);
                InvigilatorSession invigSess = new InvigilatorSession();
                {
                    invigSess.InvigilatorId = invigilator.InvigilatorId;
                    invigSess.SessionId     = sessionId;
                }
                db.InvigilatorSessions.Add(invigSess);
                db.SaveChanges();
                var examStudents = db.ExamStudents.ToList <ExamStudent>();
                var matchedId    = -1;
                foreach (ExamStudent es in examStudents)
                {
                    if (db.Exams.Find(es.ExamId).SessionId == sessionId)
                    {
                        matchedId = es.ExamStudentId;
                        break;
                    }
                }
                if (matchedId > 0)
                {
                    Everything everything = new Everything();
                    {
                        everything.ExamStudentId        = matchedId;
                        everything.InvigilatorSessionId = invigSess.InvigilatorSessionId;
                    }
                    db.Everything.Add(everything);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }

            return(View(invigilator));
        }