예제 #1
0
        public ActionResult Create([Bind(Include = "empid,empname,email,phoneno")] employee employee)
        {
            if (ModelState.IsValid)
            {
                db.employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
예제 #2
0
 public bool DeleteEmployee(int id)
 {
     using (var context = new empdbEntities())
     {
         var emp = new Employee()
         {
             Id = id
         };
         context.Entry(emp).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
         return(false);
     }
 }
예제 #3
0
 public int AddEmployee(EmployeeModels model)
 {
     using (var context = new empdbEntities())
     {
         Employee emp = new Employee()
         {
             FirstName = model.FirstName,
             LastName  = model.LastName,
             Email     = model.Email,
             Code      = model.Code
         };
         context.Employee.Add(emp);
         context.SaveChanges();
         return(emp.Id);
     }
 }
예제 #4
0
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         employee emp = new employee();
         emp.empname = collection["empname"];
         emp.email   = collection["email"];
         emp.phoneno = collection["phoneno"];
         empdbEntities userRegistrationEntities = new empdbEntities();
         userRegistrationEntities.employees.Add(emp);
         userRegistrationEntities.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
예제 #5
0
 public bool UpdateEmployee(int id, EmployeeModels models)
 {
     using (var context = new empdbEntities())
     {
         var employee = new Employee();
         if (employee != null)
         {
             employee.FirstName = models.FirstName;
             employee.LastName  = models.LastName;
             employee.Email     = models.Email;
             employee.Code      = models.Code;
             employee.Addressid = models.Addressid;
         }
         context.Entry(employee).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
         return(true);
     }
 }