예제 #1
0
        public ActionResult Create([Bind(Include = "id,id_student,id_subject,examen1,examen2,examen3,examen4")] Studentsubject studentsubject)
        {
            if (ModelState.IsValid)
            {
                Studentsubject ss2 = db.Studentsubjects.ToList().Find(value => value.id_student == studentsubject.id_student && value.id_subject == studentsubject.id_subject);
                if (ss2 == null)
                {
                    if (studentsubject.examen1 >= 0 && studentsubject.examen1 <= 10 && studentsubject.examen2 >= 0 && studentsubject.examen2 <= 10 && studentsubject.examen3 >= 0 && studentsubject.examen3 <= 10 && studentsubject.examen4 >= 0 && studentsubject.examen4 <= 10)
                    {
                        db.Studentsubjects.Add(studentsubject);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ViewBag.error = "Error, Score must be between 0 and 10";
                    }
                }
                else
                {
                    ViewBag.error = "Error, Student already have the score!";
                }
            }

            ViewBag.id_student = new SelectList(db.Students, "id", "name", studentsubject.id_student);
            ViewBag.id_subject = new SelectList(db.Subjects, "id", "name_subject", studentsubject.id_subject);
            return(View(studentsubject));
        }
예제 #2
0
        public IHttpActionResult PutStudentsubject(int id, Studentsubject studentsubject)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Studentsubject studentsubject = db.Studentsubjects.Find(id);

            db.Studentsubjects.Remove(studentsubject);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #4
0
        public IHttpActionResult GetStudentsubject(int id)
        {
            Studentsubject studentsubject = db.Studentsubjects.Find(id);

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

            return(Ok(studentsubject));
        }
예제 #5
0
        public IHttpActionResult PostStudentsubject(Studentsubject studentsubject)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Studentsubjects.Add(studentsubject);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = studentsubject.id }, studentsubject));
        }
예제 #6
0
        public IHttpActionResult DeleteStudentsubject(int id)
        {
            Studentsubject studentsubject = db.Studentsubjects.Find(id);

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

            db.Studentsubjects.Remove(studentsubject);
            db.SaveChanges();

            return(Ok(studentsubject));
        }
예제 #7
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Studentsubject studentsubject = db.Studentsubjects.Find(id);

            if (studentsubject == null)
            {
                return(HttpNotFound());
            }
            return(View(studentsubject));
        }
예제 #8
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Studentsubject studentsubject = db.Studentsubjects.Find(id);

            if (studentsubject == null)
            {
                return(HttpNotFound());
            }
            ViewBag.id_student = new SelectList(db.Students, "id", "name", studentsubject.id_student);
            ViewBag.id_subject = new SelectList(db.Subjects, "id", "name_subject", studentsubject.id_subject);
            return(View(studentsubject));
        }
예제 #9
0
 public ActionResult Edit([Bind(Include = "id,id_student,id_subject,examen1,examen2,examen3,examen4")] Studentsubject studentsubject)
 {
     if (ModelState.IsValid)
     {
         if (studentsubject.examen1 >= 0 && studentsubject.examen1 <= 10 && studentsubject.examen2 >= 0 && studentsubject.examen2 <= 10 && studentsubject.examen3 >= 0 && studentsubject.examen3 <= 10 && studentsubject.examen4 >= 0 && studentsubject.examen4 <= 10)
         {
             db.Entry(studentsubject).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             ViewBag.error = "Error, Score must be between 0 and 10";
         }
     }
     ViewBag.id_student = new SelectList(db.Students, "id", "name", studentsubject.id_student);
     ViewBag.id_subject = new SelectList(db.Subjects, "id", "name_subject", studentsubject.id_subject);
     return(View(studentsubject));
 }