示例#1
0
        // GET: Emp1Controller/Edit/5
        public ActionResult Edit(int id)
        {
            Emp1      emp1  = new Emp1();
            DataTable table = new DataTable();

            using (SqlConnection connection = new SqlConnection(connstring))
            {
                connection.Open();
                var            sql3    = "select * from Emp1 where Empid = @Empid";
                SqlDataAdapter adapter = new SqlDataAdapter(sql3, connection);
                adapter.SelectCommand.Parameters.AddWithValue("@Empid", id);
                adapter.Fill(table);
            }
            if (table.Rows.Count == 1)
            {
                emp1.Empid   = Convert.ToInt32(table.Rows[0][0].ToString());
                emp1.Empname = table.Rows[0][1].ToString();
                emp1.gender  = table.Rows[0][2].ToString();
                return(View(emp1));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
示例#2
0
        public ActionResult Create()
        {
            ViewBag.StateList = db.States;
            var model = new Emp1();

            return(View(model));;
        }
示例#3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Emp1 product = db.AEmployees.Find(id);

            db.AEmployees.Remove(product);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Emp1 emp1 = db.Emp1.Find(id);

            db.Emp1.Remove(emp1);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#5
0
 public ActionResult Edit([Bind(Include = "Id,Name,Email,Phone,MaritalStatus,State,City")] Emp1 employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
 public ActionResult Edit([Bind(Include = "Empid,Name,Salary")] Emp1 emp1)
 {
     if (ModelState.IsValid)
     {
         db.Entry(emp1).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(emp1));
 }
示例#7
0
 public ActionResult Create([Bind(Include = "Id,Name,Email,Phone,MaritalStatus,State,City")] Emp1 emp)
 {
     if (ModelState.IsValid)
     {
         db.AEmployees.Add(emp);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StateList = db.States;
     return(View(emp));
 }
        public ActionResult Create([Bind(Include = "Empid,Name,Salary")] Emp1 emp1)
        {
            if (ModelState.IsValid)
            {
                db.Emp1.Add(emp1);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(emp1));
        }
示例#9
0
 public ActionResult Create(Emp1 emp1)
 {
     using (SqlConnection connection = new SqlConnection(connstring))
     {
         connection.Open();
         var        sql2    = "insert into Emp1(Empname,gender)values(@empname,@gender)";
         SqlCommand command = new SqlCommand(sql2, connection);
         command.Parameters.AddWithValue("@empname", emp1.Empname);
         command.Parameters.AddWithValue("@gender", emp1.gender);
         command.ExecuteNonQuery();
     }
     return(RedirectToAction("Index"));
 }
示例#10
0
        // GET: Products/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Emp1 employee = db.AEmployees.Find(id);

            if (employee == null)
            {
                return(HttpNotFound());
            }
            return(View(employee));
        }
示例#11
0
        // GET: Emp1/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Emp1 emp1 = db.Emp1.Find(id);

            if (emp1 == null)
            {
                return(HttpNotFound());
            }
            return(View(emp1));
        }
示例#12
0
 public ActionResult Edit(Emp1 emp1)
 {
     using (SqlConnection connection = new SqlConnection(connstring))
     {
         connection.Open();
         var        sql2    = "Update Emp1 set Empname=@empname,gender = @gender where Empid = @empid";
         SqlCommand command = new SqlCommand(sql2, connection);
         command.Parameters.AddWithValue("@empid", emp1.Empid);
         command.Parameters.AddWithValue("@empname", emp1.Empname);
         command.Parameters.AddWithValue("@gender", emp1.gender);
         command.ExecuteNonQuery();
     }
     return(RedirectToAction("Index"));
 }
示例#13
0
        static void Main(string[] args)
        {
            using (var EmpObj = new EmployeeEntities())
            {
                var emp = new Emp1();
                //emp.Empid = 1;
                //emp.Name = "Emp1";
                //emp.Salary = 10000;
                //EmpObj.Emp1.Add(emp);
                //emp = new Emp1();
                //emp.Empid = 2;
                //emp.Name = "Emp2";
                //emp.Salary = 15000;
                //EmpObj.Emp1.Add(emp);
                //emp = new Emp1();
                //emp.Empid = 3;
                //emp.Name = "Emp3";
                //emp.Salary = 20000;
                //EmpObj.Emp1.Add(emp);

                //for (int i = 4; i < 8; i++)
                //{
                //    emp = new Emp1();
                //    emp.Empid = i;
                //    emp.Name = "Emp" + i;
                //    emp.Salary = 20000;
                //    EmpObj.Emp1.Add(emp);
                //    EmpObj.SaveChanges();
                //}
                //Emp1 emp1Obj = EmpObj.Emp1.First(i => i.Empid == 2);
                //emp1Obj.Name = "Emp2";
                //emp1Obj.Salary = 30000;
                //EmpObj.SaveChanges();

                //Emp1 emp1Obj = EmpObj.Emp1.First(i => i.Empid == 2);
                //EmpObj.Emp1.Remove(emp1Obj);
                //EmpObj.SaveChanges();
                //Console.WriteLine("Record Removed.");
                var EmpObj1 = EmpObj.Emp1;
                foreach (var item in EmpObj1)
                {
                    Console.WriteLine("ID: {0}", item.Empid);
                    Console.WriteLine("Name: {0}", item.Name);
                    Console.WriteLine("Salary: {0}", item.Salary);
                }
            }
            Console.Read();
        }
示例#14
0
        static void Main(string[] args)
        {
            using (var EmpObj = new EmployeeEntities())
            {
                //var emp = new Emp1();
                //emp.EmpID = 1;
                //emp.Name = "Mary";
                //emp.Salary = 10000;
                //EmpObj.Emp1.Add(emp);


                //emp = new Emp1();
                //emp.EmpID = 2;
                //emp.Name = "John";
                //emp.Salary = 20000;
                //EmpObj.Emp1.Add(emp);

                //emp = new Emp1();
                //emp.EmpID = 3;
                //emp.Name = "Mike";
                //emp.Salary = 15000;
                //EmpObj.Emp1.Add(emp);

                //Emp1 Emp1Obj = EmpObj.Emp1.First(i => i.EmpID == 2);
                //Emp1Obj.Name = "Moana";
                //Emp1Obj.Salary = 20000;

                Emp1 Emp2Obj = EmpObj.Emp1.First(i => i.EmpID == 2);
                EmpObj.Emp1.Remove(Emp2Obj);

                EmpObj.SaveChanges();

                Console.WriteLine("Records insterted");
            }
            Console.ReadLine();
        }