Пример #1
0
        public ActionResult Edit(int id)
        {
            EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
            Employee employee = employeeBusinessLayer.Employees.Single(emp => emp.EmployeeId == id);

            return(View(employee));
        }
        public void AddEmployee(Employee employee)
        {
            string connection = "server=.; database=sample2MVC; integrated security=SSPI";

               using(SqlConnection conn = new SqlConnection(connection))
               {

               SqlCommand cmd = new SqlCommand("spAddEmployee", conn);
               cmd.CommandType = CommandType.StoredProcedure;

               SqlParameter paramName = new SqlParameter();
               paramName.ParameterName = "@Name";
               paramName.Value = employee.Name; //mora proči kroz model
               cmd.Parameters.Add(paramName);

               SqlParameter paramGender = new SqlParameter();
               paramGender.ParameterName = "@Gender";
               paramGender.Value = employee.Gender;
               cmd.Parameters.Add(paramGender);

               SqlParameter paramCity = new SqlParameter();
               paramCity.ParameterName = "@City";
               paramCity.Value = employee.City;
               cmd.Parameters.Add(paramCity);

               SqlParameter paramDate = new SqlParameter();
               paramDate.ParameterName = "@DateOfBirth";
               paramDate.Value = employee.DateOfBirth;
               cmd.Parameters.Add(paramDate);

               conn.Open();
               cmd.ExecuteNonQuery();

               }
        }
        public void AddEmployee(Employee employee)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand("spAddEmployee",con);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter paramName = new SqlParameter();
                paramName.ParameterName = "@Name";
                paramName.Value = employee.Name;
                cmd.Parameters.Add(paramName);

                SqlParameter paramGender = new SqlParameter();
                paramGender.ParameterName = "@Gender";
                paramGender.Value = employee.Gender;
                cmd.Parameters.Add(paramGender);

                SqlParameter paramCity = new SqlParameter();
                paramCity.ParameterName = "@City";
                paramCity.Value = employee.City;
                cmd.Parameters.Add(paramCity);

                SqlParameter paramDateOfBirth = new SqlParameter();
                paramDateOfBirth.ParameterName = "@DateOfBirth";
                paramDateOfBirth.Value = employee.DateOfBirth;
                cmd.Parameters.Add(paramDateOfBirth);

                con.Open();
                cmd.ExecuteNonQuery();
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            Person person = new Employee();
            person.LastName = "Cattoor";
            person.FirstName = "Robby";

            IPersonFactory factory = new PersonFactory();
            factory.Create(person);
        }
     public List<Employee> GetEmployees()
 {
     List<Employee><employee> employees = new List<Employee><employee>();
     Employee emp = new Employee();
     emp.FirstName = "johnson";
     emp.LastName = " fernandes";
     emp.Salary = 14000;
     employees.Add(emp);
 }
 public ActionResult Edit(Employee employee)
 {
     if (ModelState.IsValid)
     {
         employeeBusinessLayer.SaveEmployee(employee);
         return RedirectToAction("Index");
     }
     return View();
 }
Пример #7
0
 public ActionResult Edit(Employee employee)
 {
     if (ModelState.IsValid)
     {
         EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
         employeeBusinessLayer.SaveEmployee(employee);
         return(RedirectToAction("Index1"));
     }
     return(View(employee));
 }
        public ActionResult Create_Post()
        {
            if (ModelState.IsValid)
            {
                Employee employee = new Employee();
                UpdateModel<Employee>(employee);
                EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
                employeeBusinessLayer.AddEmployee(employee);

                return RedirectToAction("Index");
            }
            return View();
        }
        public ActionResult Create(FormCollection fc)
        {
            Employee employee = new Employee();

            employee.Name = fc["Name"];
            employee.Gender = fc["Gender"];
            employee.City = fc["City"];
            employee.DateOfBirth = Convert.ToDateTime(fc["DateOfBirth"]);

            EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();

            employeeBusinessLayer.AddEmployee(employee);
            return RedirectToAction("Index");
        }
Пример #10
0
        public ActionResult Create_Post()
        {
            if (ModelState.IsValid)
            {
                Employee employee = new Employee();

                UpdateModel(employee);
                EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
                employeeBusinessLayer.AddEmployee(employee);

                return(RedirectToAction("Index1"));
            }

            return(View());
        }
Пример #11
0
        public ActionResult Create_Post()
        {
            //Model Binders

            if(ModelState.IsValid)
            //ako je model prošao validaciju ako to samo ako je u View @Html.ValidationSummary(true)
            {
                Employee employee = new Employee(); //sva propery su null u ovom trenutkku
                UpdateModel(employee); //no sada sve što je stavljeno u formu će se bindat s view formom
                EmployeeBusinesLayer EmployeBuss = new EmployeeBusinesLayer();
                EmployeBuss.AddEmployee(employee);

                return RedirectToAction("Index");
            }

            ViewBag.greska = "Nisi dobro ispunio obrazac";
            return View();
        }
        public bool AddEmployee(Employee employee)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                SqlCommand sqlCommand = new SqlCommand("spAddEmployee", sqlConnection)
                {
                    CommandType = CommandType.StoredProcedure
                };

                sqlCommand.Parameters.AddRange(new SqlParameter[]
                {
                    new SqlParameter("@Name", employee.Name),
                    new SqlParameter("@City", employee.City),
                    new SqlParameter("@Gender", employee.Gender),
                    new SqlParameter("@DateOfBirth", employee.DateOfBirth)
                });

                sqlConnection.Open();
                return sqlCommand.ExecuteNonQuery() != 0;
            }
        }
 public string DeleteEmployee(Employee employee)
 {
     //add code for employee deletion
     return "Employee has been deleted";
 }
        public void SaveEmployee(Employee employee)
        {
            string connection = "server=.; database=sample2MVC; integrated security=SSPI";

               using (SqlConnection conn = new SqlConnection(connection))
               {

               SqlCommand com = new SqlCommand("spSaveEmployee", conn);
               com.CommandType = CommandType.StoredProcedure;

               SqlParameter idEmp = new SqlParameter();
               idEmp.ParameterName = "@Id";
               idEmp.Value = employee.ID;
               com.Parameters.Add(idEmp);

               SqlParameter Name = new SqlParameter();
               Name.ParameterName = "@Name";
               Name.Value = employee.Name;
               com.Parameters.Add(Name);

               SqlParameter Gender = new SqlParameter();
               Gender.ParameterName = "@Gender";
               Gender.Value = employee.Gender;
               com.Parameters.Add(Gender);

               SqlParameter DateBirth = new SqlParameter();
               DateBirth.ParameterName = "@DateOfBirth";
               DateBirth.Value = employee.DateOfBirth;
               com.Parameters.Add(DateBirth);

               SqlParameter CityP = new SqlParameter();
               CityP.ParameterName = "@City";
               CityP.Value = employee.City;
               com.Parameters.Add(CityP);

               conn.Open();
               com.ExecuteNonQuery();

               }
        }
Пример #15
0
 internal void AddEmployee(Employee emp)
 {
     employees.Add(emp);
 }