Exemplo n.º 1
0
        public ActionResult tabla()
        {
            // Carga de Datos predeterminados.
            Workers w = new Models.Workers();

            // Definir los codigos de los empleados.
            w.code[0] = 01;
            w.code[1] = 02;
            w.code[2] = 03;
            w.code[3] = 04;
            w.code[4] = 05;

            // Definir los nombres de los empleados.
            w.name[0] = "Jeremy Zelaya";
            w.name[1] = "Susan Solano";
            w.name[2] = "Tamara Richards";
            w.name[3] = "Julian Rodriguez";
            w.name[4] = "Angeles Rostran";

            // Definir los roles de los empleados.
            w.role[0] = "IT";
            w.role[1] = "Proyect Manager";
            w.role[2] = "Equipment Maintenance";
            w.role[3] = "Production Supervisor";
            w.role[4] = "Accountant";

            // Definir los salarios de los empleados.
            w.salary[0] = 1500000;
            w.salary[1] = 2000000;
            w.salary[2] = 1200000;
            w.salary[3] = 1500000;
            w.salary[4] = 1750000;
            return(View(w));
        }
Exemplo n.º 2
0
        private Workers AddEdit(int?id, Models.Workers worker, string confirmPassword)
        {
            string query;

            if (id.HasValue)
            {
                //Düzenle
                query = "UPDATE Workers SET RoleId=@p1,Name=@p2,Surname=@p3,Gender=@p4,TcNo=@p5,DateOfBirth=@p6,Tel=@p7,Mail=@p8,UserName=@p9,Password=@p10 WHERE Id = " + id.Value + "";
            }
            else
            {
                //Ekleme
                query = "INSERT INTO Workers(RoleId,Name,Surname,Gender,TcNo,DateOfBirth,Tel,Mail,UserName,Password) VALUES (@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9,@p10)";
            }

            using (SqlConnection sqlconnection = new SqlConnection(_connection))
            {
                var pass = IsPasswordConfirm(worker.Password, confirmPassword);

                var name    = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(worker.Name);
                var surname = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(worker.Surname);

                if (pass)
                {
                    sqlconnection.Open();

                    SqlCommand sqlCommand = new SqlCommand(query, sqlconnection);

                    sqlCommand.Parameters.AddWithValue("@p1", worker.RoleId);
                    sqlCommand.Parameters.AddWithValue("@p2", name);
                    sqlCommand.Parameters.AddWithValue("@p3", surname);
                    sqlCommand.Parameters.AddWithValue("@p4", worker.Gender);
                    sqlCommand.Parameters.AddWithValue("@p5", worker.TcNo);
                    sqlCommand.Parameters.AddWithValue("@p6", worker.DateOfBirth);
                    sqlCommand.Parameters.AddWithValue("@p7", worker.Tel);
                    sqlCommand.Parameters.AddWithValue("@p8", worker.Mail);
                    sqlCommand.Parameters.AddWithValue("@p9", worker.UserName);
                    sqlCommand.Parameters.AddWithValue("@p10", worker.Password);

                    sqlCommand.ExecuteNonQuery();
                    sqlconnection.Close();
                }
            }
            return(worker);
        }
Exemplo n.º 3
0
        public IActionResult Add(Models.Workers worker, string confirmPassword)
        {
            AddEdit(null, worker, confirmPassword);

            return(RedirectToAction("Index"));
        }