public ActionResult Edit_get(int id)
        {
            EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
            NewEmployees          employee = employeeBusinessLayer.Employees.Single(emp => emp.ID == id);

            return(View(employee));
        }
        public ActionResult Create_Post()
        {
            /*
             * FormCollection formCollection
             * if (ModelState.IsValid)
             * {
             *  foreach (string key in formCollection.AllKeys)
             *  {
             *      Response.Write("Key " + key + " ");
             *      Response.Write("Value = " + formCollection[key]);
             *      Response.Write("<br/>");
             *
             *  }
             * }*/

            if (ModelState.IsValid)
            {
                EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
                NewEmployees          employees             = new NewEmployees();
                UpdateModel <NewEmployees>(employees);
                //Instead of giving value to each property of employee "UpdateModel" is used

                /*employee.Name=formCollection["Name"];
                 * employee.Gender=formCollection["Gender"];
                 * employee.DateOfBirth= Convert.ToDateTime(formCollection["DateOfBirth"]);
                 * employee.City=formCollection["City"];
                 */
                employeeBusinessLayer.AddEmmployee(employees);

                return(RedirectToAction("Index"));
            }
            return(View());
        }
        public ActionResult Edit_Post(int id)
        {
            //to preventing unwanted updates we do modelbinding using include properties or exclude properties
            EmployeeBusinessLayer employeeBusinessLayer =
                new EmployeeBusinessLayer();
            NewEmployees employee = employeeBusinessLayer.Employees.Single(emp => emp.ID == id);

            UpdateModel(employee, new string[] { "ID", "Gender", "City", "DateOfBirth" });

            if (ModelState.IsValid)
            {
                employeeBusinessLayer.SaveEmmployee(employee);

                return(RedirectToAction("Index"));
            }
            return(View(employee));
        }
Ejemplo n.º 4
0
        private void GetAllEmployees()
        {
            int id = 1;

            newEmployees = new List <newEmployeeParams>();
            // Every time a new employee is displayed
            foreach (var newEmployee in dataEmployee.GiveAllEmployees())
            {
                employeeParams           = new newEmployeeParams();
                employeeParams.Id        = id;
                employeeParams.FirstName = newEmployee.FirstName;
                employeeParams.LastName  = newEmployee.LastName;
                employeeParams.JobTitle  = newEmployee.JobTitle;
                employeeParams.Email     = newEmployee.Email;
                employeeParams.Gender    = newEmployee.Gender;
                employeeParams.Age       = CalculateAge(employeeParams.BirthDate);
                NewEmployees.Add(employeeParams);
                id++;
            }

            Console.WriteLine(NewEmployees.Count);
        }