Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        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"));
        }
Exemplo n.º 4
0
        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 }
            });
        }
Exemplo n.º 5
0
 // 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"));
        }
Exemplo n.º 7
0
 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();
         }
     }
 }
Exemplo n.º 8
0
        public EmployeeDataModel GetEmployeeById(int employeeId)
        {
            tbl_Employee employee = employeeEntity.tbl_Employee.Where(p => p.employeeId == employeeId).FirstOrDefault();
            var          data     = entityMapper.DBModelMappingGet(employee);

            return(data);
        }
Exemplo n.º 9
0
 public static void CreateNewEmployee(tbl_Employee employee)
 {
     using (CompanyEntities dbContext = new CompanyEntities())
     {
         dbContext.tbl_Employee.Add(employee);
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 10
0
        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"));
        }
Exemplo n.º 11
0
 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));
 }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
 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));
 }
Exemplo n.º 14
0
 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));
 }
Exemplo n.º 15
0
 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));
 }
Exemplo n.º 16
0
 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());
     }
 }
Exemplo n.º 17
0
 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());
        }
Exemplo n.º 19
0
        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));
        }
Exemplo n.º 20
0
        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));
        }
Exemplo n.º 21
0
        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));
        }
Exemplo n.º 22
0
        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));
        }
Exemplo n.º 23
0
        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));
        }
Exemplo n.º 24
0
        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));
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
        //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"));
        }
Exemplo n.º 27
0
        // 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);
        }
Exemplo n.º 29
0
        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);
            }
        }
Exemplo n.º 30
0
        // 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));
        }