コード例 #1
0
 /// <summary>
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 public Employee SaveEmployee(Employee e)
 {
     var salesDal = new SalesErpdal();
     salesDal.Employees.Add(e);
     salesDal.SaveChanges();
     return e;
 }
コード例 #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        /// <param name="btnSubmit"></param>
        /// <returns></returns>
        public ActionResult SaveEmployee(Employee e, string btnSubmit)
        {
            switch (btnSubmit)
            {
                case "Save Employee":
                    if (ModelState.IsValid)
                    {
                        var empBal = new EmployeeBusinessLayer();
                        empBal.SaveEmployee(e);
                        return RedirectToAction("Index");
                    }
                    else
                    {
                        var vm = new CreateEmployeeViewModel
                        {
                            FirstName = e.FirstName,
                            LastName = e.LastName,
                            Salary = e.Salary.HasValue ? e.Salary.ToString() : ModelState["Salary"].Value.AttemptedValue
                        };

                        return View("CreateEmployee", vm); // Day 4 Change - Passing e here
                    }
                case "Cancel":
                    return RedirectToAction("Index");
            }
            return new EmptyResult();
        }