Example #1
0
        [ValidateAntiForgeryToken] // captures data
        public ActionResult Add(ModuleViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (TRSContext context = new TRSContext())
                    {
                        Module module = new Module
                        {
                            ModuleTitle     = model.Module.Title,
                            ModuleId        = model.Module.ModuleId,
                            ModuleTrimester = model.Module.Trimester,
                            ModuleComment   = model.Module.Comment
                        };
                        context.Modules.Add(module);
                        context.SaveChanges();
                    }
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View());
                }
            }

            return(View());
        }
Example #2
0
 [ValidateAntiForgeryToken] // captures data
 public ActionResult Add(CourseViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             using (TRSContext context = new TRSContext())
             {
                 Course course = new Course
                 {
                     CourseId            = model.Course.CourseId,
                     CourseLength        = model.Course.Length,
                     CourseName          = model.Course.Name,
                     CourseQualification = model.Course.Qualification
                 };
                 context.Courses.Add(course);
                 context.SaveChanges();
             }
             return(RedirectToAction("Index"));
         }
         catch
         {
             return(View());
         }
     }
     return(View());
 }
Example #3
0
 // GET: Module/Details/5
 public ActionResult Details(int id)
 {
     using (TRSContext context = new TRSContext())
     {
         return(View(new ModuleViewModel
         {
             Module = context.Modules.Select(x => new ModuleDto
             {
                 Id = x.Id,
                 Title = x.ModuleTitle,
                 ModuleId = x.ModuleId,
                 Comment = x.ModuleComment,
                 Trimester = x.ModuleTrimester
             }).FirstOrDefault(x => x.Id == id)
         }));
     }
 }
Example #4
0
 public ActionResult Delete(int id, ModuleViewModel model)
 {
     try
     {
         using (TRSContext context = new TRSContext())
         {
             Module module = context.Modules.Find(id);
             context.Modules.Remove(module);
             context.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Example #5
0
 // GET: Module/Index
 public ActionResult Index()
 {
     using (TRSContext context = new TRSContext())
     {
         return(View(new ListViewModel
         {
             Modules = context.Modules.Select(x => new ModuleDto
             {
                 Id = x.Id,
                 Title = x.ModuleTitle,
                 ModuleId = x.ModuleId,
                 Comment = x.ModuleComment,
                 Trimester = x.ModuleTrimester
             }).ToList()
         }));
     }
 }
Example #6
0
 // GET: Course/Edit/5
 public ActionResult Edit(int id)
 {
     using (TRSContext context = new TRSContext())
     {
         return(View(new CourseViewModel
         {
             Course = context.Courses.Select(x => new CourseDto
             {
                 Id = x.Id,
                 CourseId = x.CourseId,
                 Length = x.CourseLength,
                 Name = x.CourseName,
                 Qualification = x.CourseQualification
             }).FirstOrDefault(x => x.Id == id)
         }));
     }
 }
Example #7
0
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         using (TRSContext context = new TRSContext())
         {
             Course course = context.Courses.Find(id);
             context.Courses.Remove(course);
             context.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Example #8
0
 // GET: Course
 public ActionResult Index()
 {
     using (TRSContext context = new TRSContext())
     {
         return(View(new ListViewModel
         {
             Courses = context.Courses.Select(x => new CourseDto
             {
                 Id = x.Id,
                 CourseId = x.CourseId,
                 Length = x.CourseLength,
                 Name = x.CourseName,
                 Qualification = x.CourseQualification
             }).ToList()
         }));
     }
 }
Example #9
0
 public ActionResult Edit(int id, ModuleViewModel model)
 {
     try
     {
         using (TRSContext context = new TRSContext())
         {
             var module = context.Modules.Find(id);
             if (module != null)
             {
                 module.ModuleTitle     = model.Module.Title;
                 module.ModuleTrimester = model.Module.Trimester;
                 module.ModuleComment   = model.Module.Comment;
             }
             context.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Example #10
0
 public ActionResult Edit(int id, CourseViewModel model)
 {
     try
     {
         using (TRSContext context = new TRSContext())
         {
             var course = context.Courses.Find(id);
             if (course != null)
             {
                 course.CourseLength        = model.Course.Length;
                 course.CourseName          = model.Course.Name;
                 course.CourseQualification = model.Course.Qualification;
             }
             context.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }