Example #1
0
        public ActionResult Delete(int id)
        {
            using (var db = new StudentTestApiContext())
            {
                var stud = db.Students.Where(x => x.Id == id).FirstOrDefault();

                return(View(stud));
            }
        }
Example #2
0
 // POST api/values
 public void Post([FromBody] Student student)
 {
     using (StudentTestApiContext db = new StudentTestApiContext())
     {
         if (student != null)
         {
             db.Students.Add(student);
             db.SaveChanges();
         }
     }
 }
Example #3
0
 public ActionResult Delete(Student stud)
 {
     using (var db = new StudentTestApiContext())
     {
         var student = db.Students.Where(x => x.Id == stud.Id).FirstOrDefault();
         if (student != null)
         {
             db.Students.Remove(student);
             db.SaveChanges();
             return(RedirectToAction("AllStudents"));
         }
         return(HttpNotFound($"Could not find a student with Id = {stud.Id}"));
     }
 }
Example #4
0
 // DELETE api/values/5
 public IHttpActionResult Delete(int id)
 {
     using (var db = new StudentTestApiContext())
     {
         var stud = db.Students.Where(x => x.Id == id).FirstOrDefault();
         if (stud != null)
         {
             db.Students.Remove(stud);
             db.SaveChanges();
             return(Redirect("https://localhost:44314/api/Values"));
         }
         return(NotFound());
     }
 }
Example #5
0
 // GET api/values/5
 public string Get(int id)
 {
     using (StudentTestApiContext db = new StudentTestApiContext())
     {
         var stud = db.Students.Where(x => x.Id == id).FirstOrDefault();
         if (stud != null)
         {
             return(JsonConvert.SerializeObject(stud));
         }
         else
         {
             return(JsonConvert.SerializeObject("Not Found"));
         }
     }
 }
Example #6
0
 // PUT api/values/5
 public IHttpActionResult Put(int id, [FromBody] Student student)
 {
     using (var db = new StudentTestApiContext())
     {
         var stud = db.Students.Where(x => x.Id == id).FirstOrDefault();
         if (stud != null)
         {
             stud.Id     = student.Id;
             stud.Name   = student.Name;
             stud.email  = student.email;
             stud.Degree = student.Degree;
             db.SaveChanges();
         }
         return(Redirect("https://localhost:44314/api/Values"));
     }
 }
Example #7
0
        public ActionResult Update(Student stud)
        {
            using (var db = new StudentTestApiContext())
            {
                var student = db.Students.Where(x => x.Id == stud.Id).FirstOrDefault();

                if (student != null)
                {
                    if (student.email != stud.email)
                    {
                        SendMail(stud.email, stud.ConfirmCode);
                    }
                    student.Name   = stud.Name;
                    student.email  = stud.email;
                    student.Degree = stud.Degree;
                    db.SaveChanges();
                    return(RedirectToAction("AllStudents"));
                }
                return(HttpNotFound($"Could not update student data with Id = {stud.Id}"));
            }
        }
Example #8
0
        public ActionResult Add(Student stud)
        {
            using (var db = new StudentTestApiContext())
            {
                string _code   = Request.Form["Code_"].ToString();
                int    conCode = Convert.ToInt32(_code);

                if (stud.ConfirmCode == conCode)
                {
                    if (stud != null)
                    {
                        db.Students.Add(stud);
                        db.SaveChanges();

                        return(RedirectToAction("AllStudents"));
                    }
                }

                return(HttpNotFound());
            }
        }
Example #9
0
        public ActionResult AllStudents()
        {
            var db = new StudentTestApiContext();

            return(View(db.Students));
        }