Esempio n. 1
0
        public ActionResult Add(EmployeeAddViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var empl = new EmployeeAddViewModel
                {
                    Name = model.Name,
                    SecondName = model.SecondName,
                    Sex = model.Sex,
                    Years = model.Years,
                    DepartmentId = model.DepartmentId,
                    DepartmentList = db.Departments,
                    ProgrammingLanguageId = model.ProgrammingLanguageId,
                    ProgrammingLanguageList = db.ProgrammingLanguages
                };

                return View(empl);
            }
            var employee = new Employee();
            employee.Name = model.Name;
            employee.SecondName = model.SecondName;
            employee.Sex = model.Sex;
            employee.Years = model.Years;
            employee.DepartmentId = model.DepartmentId;
            employee.ProgrammingLanguageId = model.ProgrammingLanguageId;
            db.Employees.Add(employee);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
Esempio n. 2
0
        public ActionResult Add()
        {
            var model = new EmployeeAddViewModel
            {
                DepartmentList = db.Departments,
                ProgrammingLanguageList = db.ProgrammingLanguages
            };

            return View(model);
        }