Beispiel #1
0
        public ActionResult Create(SubjectViewModel subjectViewModel)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    Subject subject = new Subject()
                    {
                        CreditHours = subjectViewModel.CreditHours,
                        Group = subjectViewModel.Group,
                        PrimaryBook = subjectViewModel.PrimaryBook,
                        ReferenceBook1 = subjectViewModel.ReferenceBook1,
                        ReferenceBook2 = subjectViewModel.ReferenceBook2,
                        SubjectName = subjectViewModel.SubjectName,
                        SubjectTeacher = subjectViewModel.SubjectTeacher,

                    };
                    db.Subjects.Add(subject);
                    db.SaveChanges();

                    return RedirectToAction("Index");
                }

                return View(subjectViewModel);
            }
            catch
            {
                return View();
            }
        }
Beispiel #2
0
 public ActionResult Edit(int id, SubjectViewModel subjectViewModel)
 {
     try
     {
         // TODO: Add update logic here
         if (ModelState.IsValid)
         {
             Subject subject = new Subject()
             {
                 SubjectId = id,
                 CreditHours = subjectViewModel.CreditHours,
                 Group = subjectViewModel.Group,
                 PrimaryBook = subjectViewModel.PrimaryBook,
                 ReferenceBook1 = subjectViewModel.ReferenceBook1,
                 ReferenceBook2 = subjectViewModel.ReferenceBook2,
                 SubjectName = subjectViewModel.SubjectName,
                 SubjectTeacher = subjectViewModel.SubjectTeacher,
             };
             if (subject == null)
             {
                 return new HttpNotFoundResult();
             }
             db.Entry(subject).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             return RedirectToAction("Index");
         }
         return View(subjectViewModel);
     }
     catch
     {
         return View();
     }
 }