Пример #1
0
        [ValidateAntiForgeryToken] // this will validate the token generated by the form in server
        // to receive form value we have ModelBinder as a utitlity which will check where from these values are coming
        // Model
        // RouteValues
        // FormCollection
        // QueryString
        // File
        public ActionResult Create([Bind("Fname,Lname,Age,Ssn")] EmployeeViewModel employee, IFormCollection form)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    EmployeeLib.Employee emp = new Employee()
                    {
                        Fname     = employee.Fname,
                        Age       = employee.Age,
                        Deptid    = 1,
                        Lname     = employee.Lname,
                        Mname     = employee.Mname,
                        Salary    = employee.Salary,
                        Ssn       = employee.Ssn,
                        Startdate = employee.StartDate
                    };

                    _repository.AddEmployee(emp);

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(View());
                }
            }
            catch
            {
                return(View());
            }
        }
Пример #2
0
 public void TestInitialize()
 {
     repoEmployee.AddEmployee(new Employee(employeeID: 1, firstName: "John", lastName: "Doe"));
     repoEmployee.AddEmployee(new Employee(employeeID: 5, firstName: "Edgar", lastName: "Poe"));
     repoEmployee.AddEmployee(new Employee(employeeID: 3, firstName: "William", lastName: "Foe"));
 }