Ejemplo n.º 1
0
        //
        // GET: /Department/Create
        public ActionResult Create()
        {
            var faculties = _repo.Faculties.All;
            var department = new Department();

            var vm = new DepartmentInputModel(department, faculties);
            return View(vm);
        }
Ejemplo n.º 2
0
        public ActionResult Create(Department department)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    _repo.Departments.Add(department);
                    _repo.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int id, Department department)
        {
            try
            {
                // TODO: Add update logic here
                var item = _repo.Departments.All.Single(d => d.Id == id);
                item.Name = department.Name;
                item.Code = department.Code;
                item.FacultyId = department.FacultyId;

                _repo.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 4
0
 public DepartmentInputModel(Department department, IEnumerable faculties)
 {
     Department = department;
     Faculties = new SelectList(faculties, "Id", "Name", department.FacultyId);
 }