public IHttpActionResult PutInvigilatorSession(int id, InvigilatorSession invigilatorSession)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != invigilatorSession.InvigilatorSessionId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetInvigilatorSession(int id)
        {
            InvigilatorSession invigilatorSession = db.InvigilatorSessions.Find(id);

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

            return(Ok(invigilatorSession));
        }
        public IHttpActionResult PostInvigilatorSession(InvigilatorSession invigilatorSession)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.InvigilatorSessions.Add(invigilatorSession);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = invigilatorSession.InvigilatorSessionId }, invigilatorSession));
        }
        public IHttpActionResult DeleteInvigilatorSession(int id)
        {
            InvigilatorSession invigilatorSession = db.InvigilatorSessions.Find(id);

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

            db.InvigilatorSessions.Remove(invigilatorSession);
            db.SaveChanges();

            return(Ok(invigilatorSession));
        }
Ejemplo n.º 5
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));
        }