public string SaveUpdateEmployee(EmployeeModel model) { MSachinMachineTestEntities db = new MSachinMachineTestEntities(); if (model.EmployeeID != 0) { var empDet = db.tbl_Employee.Where(p => p.EmployeeID == model.EmployeeID).FirstOrDefault(); if (empDet != null) { empDet.EmployeeName = model.EmployeeName; empDet.City = model.City; } db.SaveChanges(); } else { var saveEmp = new tbl_Employee { EmployeeName = model.EmployeeName, City = model.City, }; db.tbl_Employee.Add(saveEmp); db.SaveChanges(); } return("Employee Updated Successfully"); }
private void txtSave_Click(object sender, EventArgs e) { var add = new tbl_Employee(); int id; id = Convert.ToInt32(txtId.Text); add.Hovaten = txtHoten.Text; add.Password = txtPassword.Text; add.Sodienthoai = Convert.ToInt32(txtSdt.Text); add.Username = txtUsername.Text; add.Diachi = txtDiachi.Text; add.Position = cbChucvu.SelectedItem.ToString(); if (id == 0) { db.tbl_Employee.Add(add); MessageBox.Show("Đã lưu!!!", "Thông báo", MessageBoxButtons.OK); load(); } else { tbl_Employee employee = db.tbl_Employee.Where(p => p.Id == id).Select(p => p).FirstOrDefault(); employee.Hovaten = txtHoten.Text; employee.Password = txtPassword.Text; employee.Sodienthoai = Convert.ToInt32(txtSdt.Text); employee.Username = txtUsername.Text; employee.Diachi = txtDiachi.Text; employee.Position = cbChucvu.SelectedItem.ToString(); db.SaveChanges(); MessageBox.Show("Đã lưu!!!", "Thông báo", MessageBoxButtons.OK); load(); } db.SaveChanges(); load(); }
public ActionResult Delete(tbl_Employee emp) { SqlHelper db = new SqlHelper(); db.DelateEmployee(emp); return(RedirectToAction("Index")); }
public ActionResult Save(tbl_Employee emp) { bool status = false; if (ModelState.IsValid) { using (MyDatabaseEntities dc = new MyDatabaseEntities()) { if (emp.EmployeeID > 0) { //Edit var v = dc.tbl_Employee.Where(a => a.EmployeeID == emp.EmployeeID).FirstOrDefault(); if (v != null) { v.FirstName = emp.FirstName; v.LastName = emp.LastName; v.EmailID = emp.EmailID; v.City = emp.City; v.Country = emp.Country; } } else { //Save dc.tbl_Employee.Add(emp); } dc.SaveChanges(); status = true; } } return(new JsonResult { Data = new { status = status } }); }
// GET: Employee/Details/5 public ActionResult Details(int?id) { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN") || Session["UserRole"].Equals("SUBADMIN")) { ViewBag.OnlineUser = Session["UserName"].ToString(); ViewBag.OnlineUserRole = Session["UserRole"].ToString(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tbl_Employee tbl_Employee = db.tbl_Employee.Find(id); if (tbl_Employee == null) { return(HttpNotFound()); } return(View(tbl_Employee)); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } }
public ActionResult Create(tbl_Employee emp) { SqlHelper db = new SqlHelper(); db.InsertEmployee(emp); return(RedirectToAction("Index")); }
private void btnSave_Click(object sender, EventArgs e) { if (txtMkcu.Text == "" || txtMkmoi.Text == "" || txtXnmk.Text == "") { MessageBox.Show("Không được để trống các trường!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (txtMkmoi.Text != txtXnmk.Text) { MessageBox.Show("Mật khẩu xác nhận không giống nhau!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { int id = Infor.Id; tbl_Employee _Employee = db.tbl_Employee.Where(p => p.Id == id).First(); if (txtMkcu.Text != _Employee.Password) { MessageBox.Show("Sai mật khẩu!!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { _Employee.Password = txtXnmk.Text; db.SaveChanges(); MessageBox.Show("Đã đổi mật khẩu!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.Close(); } } }
public EmployeeDataModel GetEmployeeById(int employeeId) { tbl_Employee employee = employeeEntity.tbl_Employee.Where(p => p.employeeId == employeeId).FirstOrDefault(); var data = entityMapper.DBModelMappingGet(employee); return(data); }
public static void CreateNewEmployee(tbl_Employee employee) { using (CompanyEntities dbContext = new CompanyEntities()) { dbContext.tbl_Employee.Add(employee); dbContext.SaveChanges(); } }
public ActionResult DeleteConfirmed(int id) { tbl_Employee tbl_Employee = db.tbl_Employee.Find(id); db.tbl_Employee.Remove(tbl_Employee); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "id,empno,name,dept,contact,email,status")] tbl_Employee tbl_Employee) { if (ModelState.IsValid) { db.Entry(tbl_Employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_Employee)); }
public bool Update(tbl_Employee employee) { var res = dbentity.tbl_Employee.Where(x => x.Id == employee.Id).FirstOrDefault(); res.Name = employee.Name; res.Address = employee.Address; res.Description = employee.Description; dbentity.SaveChanges(); return(true); }
public ActionResult Edit([Bind(Include = "Eid,Ename,ESalary,Edepartment,Eorganisation")] tbl_Employee tbl_Employee) { if (ModelState.IsValid) { db.Entry(tbl_Employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_Employee)); }
public ActionResult Edit([Bind(Include = "emp_Id,emp_Login,emp_Password,emp_CreateDate,emp_LastLogin,emp_IsRemove")] tbl_Employee tbl_Employee) { if (ModelState.IsValid) { db.Entry(tbl_Employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_Employee)); }
public ActionResult Edit([Bind(Include = "ID,Name,Address,Age,Status")] tbl_Employee tbl_Employee) { if (ModelState.IsValid) { db.Entry(tbl_Employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_Employee)); }
public ActionResult Create([Bind(Include = "EmployeeId,EmployeeCode,EmployeeName,EmployeeLastName,EmployeePhone,EmployeeAdress,EmployeePicUrl,StateId,EmployeeFName,EmployeeMCode,EmployeeBirthdate,EmployeeSex,EmployeeWork,EmployeeDateRegistered")] tbl_Employee tbl_Employee, HttpPostedFileBase pic) { try { Random rand = new Random(); int ra; if (ModelState.IsValid) { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN") || Session["UserRole"].Equals("SUBADMIN")) { ra = rand.Next(11111, 99999); while (db.tbl_Employee.FirstOrDefault(f => f.EmployeeId == ra) != null) { ra = rand.Next(1000000, 2000000); } if (pic != null) { var Fi1 = Path.GetExtension(pic.FileName); var Ri1 = Path.Combine(Server.MapPath("~/Documents/Pic/"), string.Format("{0}{1}", ra.ToString(), Fi1)); pic.SaveAs(Ri1); tbl_Employee.EmployeePicUrl = string.Format("Documents/Pic/{0}{1}", ra.ToString(), Fi1); } else { tbl_Employee.EmployeePicUrl = "no image yet"; } tbl_Employee.EmployeeId = ra; ViewBag.OnlineUser = Session["UserName"].ToString(); ViewBag.OnlineUserRole = Session["UserRole"].ToString(); db.tbl_Employee.Add(tbl_Employee); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } } ViewBag.StateId = new SelectList(db.tbl_State, "StateId", "StateName", tbl_Employee.StateId); ViewBag.Emp = db.tbl_Employee.ToList(); return(View(tbl_Employee)); } catch (Exception ex) { ModelState.AddModelError(ex.Message, ex.InnerException.ToString()); return(View()); } }
public ActionResult Edit([Bind(Include = "Eid,E_Name,E_Salary,E_Gender,E_DOB,Did")] tbl_Employee tbl_Employee) { if (ModelState.IsValid) { db.Entry(tbl_Employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Did = new SelectList(db.tbl_dept, "Did", "D_Name", tbl_Employee.Did); return(View(tbl_Employee)); }
public ActionResult NewEmployee(tbl_Employee employee) { employee.BrutSalary = CalculateBrutSalary(employee.NetSalary); CompanyService.CreateNewEmployee(employee); ViewBag.Message = "New employee " + employee.Name + " " + employee.Lastname + " record inserted successfully. " + "Brut salary of the employee is: " + employee.BrutSalary; ModelState.Clear(); return(View()); }
public ActionResult Create([Bind(Include = "Eid,Ename,ESalary,Edepartment,Eorganisation")] tbl_Employee tbl_Employee) { if (ModelState.IsValid) { db.tbl_Employee.Add(tbl_Employee); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_Employee)); }
public ActionResult EditEmp(int id) { tbl_Employee emp = db.tbl_Employee.Single(d => d.Id == id); ViewBag.DeptId = new SelectList(db.tbl_Deparment, "DeptId", "Name"); if (emp == null) { return(HttpNotFound()); } return(PartialView(emp)); }
public ActionResult Login(tbl_Employee obj) { var data = _employeeService.tbl_Employee_Get(obj); if (data != null) { Session["ten"] = data.EmployeeName; return(Json("OK", JsonRequestBehavior.AllowGet)); } return(Json("", JsonRequestBehavior.AllowGet)); }
public ActionResult Create([Bind(Include = "id,empno,name,dept,contact,email,status")] tbl_Employee tbl_Employee) { if (ModelState.IsValid) { db.tbl_Employee.Add(tbl_Employee); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_Employee)); }
public ActionResult Create([Bind(Include = "emp_Id,emp_Login,emp_Password,emp_CreateDate,emp_LastLogin,emp_IsRemove")] tbl_Employee tbl_Employee) { if (ModelState.IsValid) { db.tbl_Employee.Add(tbl_Employee); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_Employee)); }
public ActionResult Create([Bind(Include = "ID,Name,Address,Age,Status")] tbl_Employee tbl_Employee) { if (ModelState.IsValid) { db.tbl_Employee.Add(tbl_Employee); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_Employee)); }
public tbl_Employee tbl_Employee_Get(tbl_Employee obj) { var data = _unitOfWork.EmployeeRepository.Get( p => p.AccountEmployee == obj.AccountEmployee && p.C_Password == obj.C_Password); if (data != null) { return(data); } return(null); }
//public ActionResult DeleteEmp(int id = 0) //{ // tbl_Employee emp = db.tbl_Employee.Single(d => d.Id == id); // if (emp == null) // return HttpNotFound(); // return View(emp); //} //[HttpPost, ActionName("DeleteEmployee")] public ActionResult DeleteEmployeeConfirm(int id = 0) { //Lấy nhân viên tbl_Employee emp = db.tbl_Employee.Single(d => d.Id == id); if (emp == null) { return(HttpNotFound()); } db.Entry(emp).State = EntityState.Deleted; db.SaveChanges(); return(RedirectToAction("Home", "Employee")); }
// GET: Employee/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tbl_Employee tbl_Employee = db.tbl_Employee.Find(id); if (tbl_Employee == null) { return(HttpNotFound()); } return(View(tbl_Employee)); }
public bool Update(Employee item) { tbl_Employee emp = new tbl_Employee(); if (item != null) { emp.Id = item.Id; emp.Name = item.Name; emp.Address = item.Address; emp.Description = item.Description; repo.Update(emp); } return(true); }
public tbl_Employee timNhanVien(int?id) { tbl_Employee emp = new tbl_Employee(); try { emp = db.tbl_Employee.Single(t => t.Id == id); return(emp); } catch { return(null); } }
// GET: Employee/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tbl_Employee tbl_Employee = db.tbl_Employee.Find(id); if (tbl_Employee == null) { return(HttpNotFound()); } ViewBag.Did = new SelectList(db.tbl_dept, "Did", "D_Name", tbl_Employee.Did); return(View(tbl_Employee)); }