public ActionResult DeleteConfirmed(int id)
        {
            tblStudents tblStudents = db.tblStudents.Find(id);

            db.tblStudents.Remove(tblStudents);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,Name,Regno,GradeId")] tblStudents tblStudents)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tblStudents).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.GradeId = new SelectList(db.tblGrades, "Id", "Name", tblStudents.GradeId);
     return(View(tblStudents));
 }
        // GET: tblStudents/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblStudents tblStudents = db.tblStudents.Find(id);

            if (tblStudents == null)
            {
                return(HttpNotFound());
            }
            return(View(tblStudents));
        }
        // GET: tblStudents/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblStudents tblStudents = db.tblStudents.Find(id);

            if (tblStudents == null)
            {
                return(HttpNotFound());
            }
            ViewBag.GradeId = new SelectList(db.tblGrades, "Id", "Name", tblStudents.GradeId);
            return(View(tblStudents));
        }
Example #5
0
        public Student AddStudent(Student newStudent)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var addStudnet = new tblStudents()
                {
                    NameAndSurname = newStudent.NameAndSurname,
                    StudyProgramId = newStudent.StudyProgramId,
                    Address        = newStudent.Address,
                    BirthDate      = newStudent.BirthDate,
                    Balance        = newStudent.Balance,
                    BirthPlace     = newStudent.BirthPlace,
                    Phone          = newStudent.Phone,
                    StudyYear      = newStudent.StudyYear,
                    Username       = newStudent.Username,
                    Password       = newStudent.Password
                };

                dbContext.tblStudents.Add(addStudnet);
                dbContext.SaveChanges();

                var newStudentId = dbContext.StudentView.SingleOrDefault(x => x.StudentId == addStudnet.StudentId);

                return(new Student()
                {
                    StudentId = newStudentId.StudentId,
                    NameAndSurname = newStudentId.NameAndSurname,
                    StudyProgramId = newStudentId.StudyProgramId,
                    StudyProgramName = newStudentId.StudyProgramName,
                    DepartmentId = newStudentId.DepartmentId,
                    DepartmentName = newStudentId.DepartmantName,
                    Address = newStudentId.Address,
                    Balance = newStudentId.Balance,
                    BirthDate = newStudentId.BirthDate,
                    BirthPlace = newStudentId.BirthPlace,
                    StudyYear = newStudentId.StudyYear,
                    Phone = newStudentId.Phone,
                    Username = newStudentId.Username,
                    Password = newStudentId.Password
                });
            }
        }