コード例 #1
0
 public ActionResult Create([Bind(Include = "FullName, Phone, Email, Position")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         employees.Add(employee);
         return(RedirectToAction("Index"));
     }
     return(View());
 }
コード例 #2
0
        public async Task <IActionResult> Create(Employee item)
        {
            if (item != null && ModelState.IsValid)
            {
                await EmployeeRepo.Add(item);

                return(RedirectToAction("Details", new { id = item.Id }));
            }

            ViewBag.FirmId = new SelectList(await FirmRepo.GetAll(), "Id", "Name", item.FirmId);
            return(View(item));
        }
コード例 #3
0
ファイル: EmployeesController.cs プロジェクト: kjakoby/SGRepo
        public ActionResult Add(AddEmployeeViewModel model)
        {
            if (ModelState.IsValid)
            {
                Employee employee = new Employee();
                employee.FirstName    = model.FirstName;
                employee.LastName     = model.LastName;
                employee.Phone        = model.Phone;
                employee.DepartmentId = model.DepartmentId;

                EmployeeRepo.Add(employee);

                return(RedirectToAction("Index"));
            }
            else
            {
                model.Departments = GetDepartmentSelectList();
                return(View(model));
            }
        }