Пример #1
0
        public ActionResult Create(FormCollection collection)
        {
            Student.Models.Parent _parent = new Student.Models.Parent();
            try
            {
                // TODO: Add insert logic here
                using (TritonEntities EFDbContext = new TritonEntities())
                {
                    Student.Models.Parent _info = new Student.Models.Parent();
                    TryUpdateModel <Student.Models.Parent>(_info, collection);
                    // Student _student = new Student();
                    _parent.StudentID = _info.StudentID;
                    _parent.Pa_name   = _info.Pa_name;
                    _parent.Pa_sex    = _info.Pa_sex;

                    EFDbContext.Parents.Add(_parent);
                    EFDbContext.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Пример #2
0
        // GET: Parent/Details/5
        public ActionResult Details(int id)
        {
            Student.Models.Parent _parent = new Student.Models.Parent();
            using (TritonEntities EFDbContext = new TritonEntities())
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }


                var ParentData = from ParentTable in EFDbContext.Parents
                                 where ParentTable.ParentID == id
                                 select ParentTable;
                if (ParentData.Any())
                {
                    _parent.ParentID  = ParentData.First().ParentID;
                    _parent.Pa_name   = ParentData.First().Pa_name;
                    _parent.Pa_sex    = ParentData.First().Pa_sex;
                    _parent.StudentID = ParentData.First().StudentID;
                }
                else
                {
                    return(HttpNotFound());
                }
            }
            return(View(_parent));
        }
Пример #3
0
        // GET: Parent/Delete/5
        public ActionResult Delete(int id)
        {
            Student.Models.Parent _parent = new Student.Models.Parent();
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            using (TritonEntities EFDbContext = new TritonEntities())
            {
                var ParentData = from ParentTable in EFDbContext.Parents
                                 where ParentTable.ParentID == id
                                 select ParentTable;
                if (ParentData.Any())
                {
                    //_student = studentData.First();
                    //EFDbContext.Students.Remove(_student);
                    //EFDbContext.SaveChanges();

                    return(View(ParentData));
                }
                else
                {
                    return(HttpNotFound());
                }
            }
            return(View());
        }
Пример #4
0
 // GET: Parent/Edit/5
 public ActionResult Edit(int id)
 {
     Student.Models.Parent _parent = new Student.Models.Parent();
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     using (TritonEntities EFDbContext = new TritonEntities())
     {
         var ParentData = from ParentTable in EFDbContext.Parents
                          where ParentTable.ParentID == id
                          select ParentTable;
         if (ParentData.Any())
         {
             Dropdownlist _student = new Dropdownlist();
             ViewBag.studentID = _student.DrowStudentID();
             _parent.StudentID = ParentData.First().StudentID;
             _parent.ParentID  = ParentData.First().ParentID;
             _parent.Pa_name   = ParentData.First().Pa_name;
             _parent.Pa_sex    = ParentData.First().Pa_sex;
             //EFDbContext.SaveChanges();
             return(View(_parent));
         }
         else
         {
             return(HttpNotFound());
         }
     }
     return(View(_parent));
 }
Пример #5
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            Student.Models.Parent _parent = new Student.Models.Parent();

            try
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                if (ModelState.IsValid)
                {
                    using (TritonEntities EFDbContext = new TritonEntities())
                    {
                        Student.Models.Parent _info = new Student.Models.Parent();
                        TryUpdateModel <Student.Models.Parent>(_info, collection);
                        //var studentData = from studenTable in EFDbContext.Students
                        //                  where studenTable.StudentID == id
                        //                  select studenTable;
                        //if (studentData.Any())
                        //{
                        _parent.StudentID = _info.StudentID;
                        //_parent.ParentID = _info.St_address;
                        _parent.Pa_name = _info.Pa_name;
                        _parent.Pa_sex  = _info.Pa_sex;
                        EFDbContext.SaveChanges();
                        return(RedirectToAction("Index"));
                        //}
                        //else
                        //{
                        //    return HttpNotFound();
                        //}
                    }
                }
                // TODO: Add update logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Пример #6
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            Student.Models.Parent _parent = new Student.Models.Parent();
            try
            {
                // TODO: Add delete logic here
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                using (TritonEntities EFDbContext = new TritonEntities())
                {
                    Student.Models.Parent _info = new Student.Models.Parent();
                    TryUpdateModel <Student.Models.Parent>(_info, collection);

                    //var studentData = from studenTable in EFDbContext.Students
                    //                  where studenTable.StudentID == id
                    //                  select studenTable;
                    //if (studentData.Any())
                    //{
                    _parent = _info;
                    EFDbContext.Parents.Remove(_parent);
                    EFDbContext.SaveChanges();

                    return(RedirectToAction("Index"));
                    //}
                    //else
                    //{
                    //    return HttpNotFound();
                    //}
                }
            }
            catch
            {
                return(View());
            }
        }