public IActionResult PutDepartmentEmployee( string departmentNumber, int employeeNumber, [FromBody] DepartmentEmployeeModel department ) { DepartmentEmployee departmentToUpdate = new DepartmentEmployee { EmployeeNumber = employeeNumber, DepartmentNumber = departmentNumber, FromDate = department.FromDate, ToDate = department.ToDate }; _departmentEmployeeService.UpdateDepartmentEmployee(departmentToUpdate); DepartmentEmployeeModel updatedDepartment = new DepartmentEmployeeModel { EmployeeNumber = departmentToUpdate.EmployeeNumber, DepartmentNumber = departmentToUpdate.DepartmentNumber, FromDate = departmentToUpdate.FromDate, ToDate = departmentToUpdate.ToDate }; return(Ok(updatedDepartment)); }
public async Task <IActionResult> Edit(int id, [Bind("departmentEmployeeId,description,departmentId,employeeId")] DepartmentEmployee departmentEmployee) { if (id != departmentEmployee.departmentEmployeeId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(departmentEmployee); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentEmployeeExists(departmentEmployee.departmentEmployeeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["departmentId"] = new SelectList(_context.Department, "departmentId", "name", departmentEmployee.departmentId); ViewData["employeeId"] = new SelectList(_context.Employee, "employeeId", "fullName", departmentEmployee.employeeId); return(View(departmentEmployee)); }
public async Task <IActionResult> PostDepartmentEmployee(DepartmentEmployee departmentEmployee) { _context.DepartmentEmployee.Add(departmentEmployee); await _context.SaveChangesAsync(); return(CreatedAtAction("GetDepartmentEmployee", new { id = departmentEmployee.departmentEmployeeId }, departmentEmployee)); }
public static DepartmentEmployeeRecord Merge(Employee employee, DepartmentEmployee departmentEmployee) { var recordToUpdate = From(departmentEmployee); recordToUpdate.Email = employee.Email; recordToUpdate.FirstName = employee.FirstName; recordToUpdate.LastName = employee.LastName; return(recordToUpdate); }
public ActionResult Index(DepartmentEmployee demp) { DBfirstDemoEntities con = new DBfirstDemoEntities(); ViewBag.Departments = new SelectList(con.Departments, "Id", "Name"); demp.dep1 = con.Departments.ToList(); demp.emp1 = con.Employees.ToList(); return(View(demp)); }
// GET: DepartmentEmployee public ActionResult Index() { DepartmentController departmentController = new DepartmentController(); EmployeeController empController = new EmployeeController(); DropDownDepartmentController ddController = new DropDownDepartmentController(); DepartmentEmployee DEview = new DepartmentEmployee(); DEview.DEDepartmentList = departmentController.GetDepartments(); DEview.DEEmployeeList = empController.GetEmployees(); DEview.DepartmentListView = ddController.GetDropdownDepartments(); return(View(DEview)); }
public static DepartmentEmployeeRecord From(DepartmentEmployee employee) => new DepartmentEmployeeRecord { Id = employee.Id, PartitionKey = employee.Department.ToLowerInvariant(), Department = employee.Department, Email = employee.Email, EmployeeId = employee.Id, FirstName = employee.FirstName, LastName = employee.LastName, ETag = employee.Version };
public ActionResult CreateEmployee(HttpPostedFileBase EmployeeAvatarFile, HttpPostedFileBase EmployeeCoverPictureFile, Employee e, int DepartmentId) { try { var pass = Unti.Utility.getHashedMD5("1234"); string avatarFile = Path.Combine(Server.MapPath("~/Content/images/avatar/"), Path.GetFileName(EmployeeAvatarFile.FileName)); EmployeeAvatarFile.SaveAs(avatarFile); var avatar = EmployeeAvatarFile.FileName; string coverPictureFile = Path.Combine(Server.MapPath("~/Content/images/coverPicture/"), Path.GetFileName(EmployeeCoverPictureFile.FileName)); EmployeeCoverPictureFile.SaveAs(coverPictureFile); var coverPicture = EmployeeCoverPictureFile.FileName; var lstEmployee = db.Employees.ToList(); foreach (var item in lstEmployee) { if (item.EmployeeFullname.Equals(e.EmployeeFullname) || item.EmployeeIdCard.Equals(e.EmployeeIdCard) || item.EmployeePhone == e.EmployeePhone || item.EmployeeEmail.Equals(e.EmployeeEmail) || item.EmployeeAvatar.Equals(avatar) || item.EmployeeCoverPicture.Equals(coverPicture)) { TempData["error"] = "Thêm Không thành công"; return(RedirectToAction("Index")); } else { Employee em = new Employee(); em.EmployeeFullname = e.EmployeeFullname; em.EmployeeBirthday = e.EmployeeBirthday; em.EmployeeIdCard = e.EmployeeIdCard; em.EmployeePhone = e.EmployeePhone; em.EmployeeAddress = e.EmployeeAddress; em.EmployeeEmail = e.EmployeeEmail; em.EmployeePassword = pass; em.EmployeeAvatar = avatar; em.EmployeeCoverPicture = coverPicture; em.EmployeeGender = e.EmployeeGender; em.EmployeeStatus = e.EmployeeStatus; db.Employees.Add(em); db.SaveChanges(); DepartmentEmployee departmentEm = new DepartmentEmployee(); departmentEm.DepartmentId = DepartmentId; departmentEm.EmployeeId = em.EmployeeId; departmentEm.DepartmentEmployeeStatus = 1; db.DepartmentEmployees.Add(departmentEm); db.SaveChanges(); TempData["error"] = "Thêm mới thành công"; return(RedirectToAction("Index")); } } return(RedirectToAction("Index")); } catch (Exception ex) { throw; } }
public async Task <IActionResult> Create([Bind("departmentEmployeeId,description,departmentId,employeeId")] DepartmentEmployee departmentEmployee) { if (ModelState.IsValid) { _context.Add(departmentEmployee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["departmentId"] = new SelectList(_context.Department, "departmentId", "name", departmentEmployee.departmentId); ViewData["employeeId"] = new SelectList(_context.Employee, "employeeId", "fullName", departmentEmployee.employeeId); return(View(departmentEmployee)); }
public int DeleteDepartmentEmployee(int employeeNumber, string departmentNumber) { DepartmentEmployee deptEmployee = GetOneDepartmentEmployee(employeeNumber, departmentNumber); if (deptEmployee == null) { return(-1); } _departmentEmployeeRepository.Remove(deptEmployee); _departmentEmployeeRepository.SaveChanges(); return(1); }
public async Task <IActionResult> PutDepartmentEmployee(DepartmentEmployee departmentEmployee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Entry(departmentEmployee).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
public void InsertDepartmentEmployee(DepartmentEmployee employee) { try { _departmentEmployeeRepository.Insert(employee); } catch (DbUpdateException dbException) { if (dbException.InnerException != null) { GenericServiceException.ConstructGenericException(dbException); } else { throw dbException; } } }
public ActionResult Index(DepartmentEmployee demp, FormCollection form) { DBfirstDemoEntities con = new DBfirstDemoEntities(); ViewBag.Departments = new SelectList(con.Departments, "Id", "Name"); var mymodel = new DepartmentEmployee(); mymodel.dep1 = con.Departments.ToList(); mymodel.emp1 = con.Employees.ToList(); mymodel.ind1 = int.Parse(form["selectedDepartment"]); //var deptlist = con.Departments; //List<DepartmentEmployee> empnames1 = new List<DepartmentEmployee>(); //var emplist = con.Employees; return(View(mymodel)); }
public void Update(EmployeeVM employeeVM) { using (var unitOf = new UnitOfWork()) { var employee = unitOf.employeeRepository.GetByIdDetached(employeeVM.EmployeeId); if (employee == null) { throw new Exception("Employee not found id DB"); } var depEmpl = unitOf.departmentEmployeeRepository.GetByEmployee(employee); var newDep = unitOf.departmentRepository.GetByName(employeeVM.DepartmentName); employee = AutomapHelper.MergeInto <Employee>(VMtoEmployeemap, employeeVM); unitOf.employeeRepository.Update(employee); if (depEmpl != null && newDep != null && depEmpl.departmentId != newDep.departmentId) { unitOf.departmentEmployeeRepository.Delete(depEmpl); DepartmentEmployee departmentEmployee = AutomapHelper.MergeInto <DepartmentEmployee>(ToDepEmpl, employee, newDep); departmentEmployee.department = newDep; departmentEmployee.employee = employee; unitOf.departmentEmployeeRepository.Create(departmentEmployee); } else if (depEmpl == null) { DepartmentEmployee departmentEmployee = AutomapHelper.MergeInto <DepartmentEmployee>(ToDepEmpl, employee, newDep); departmentEmployee.department = newDep; departmentEmployee.employee = employee; unitOf.departmentEmployeeRepository.Create(departmentEmployee); } unitOf.Save(); } }
public void Add(EmployeeVM employeeVM) { Employee employee = new Employee() { tasks = new List <Model.EmplTask>() }; if (string.IsNullOrEmpty(employeeVM.DepartmentName)) { return; } else { using (var unitOf = new UnitOfWork()) { Department dep = unitOf.departmentRepository.GetByName(employeeVM.DepartmentName); if (dep != null) { DepartmentEmployee departmentEmployee = new DepartmentEmployee() { employee = employee, employeeId = employee.employeeId, department = dep, departmentId = dep.departmentId }; unitOf.departmentEmployeeRepository.Create(departmentEmployee); employee.firstName = employeeVM.FirstName; employee.lastName = employeeVM.LastName; unitOf.employeeRepository.Create(employee); unitOf.Save(); } } } }
public void UpdateEmployeeDepartment(EmployeeDepartmentViewModel empDep) { var selectEmployee = (from dept in _db.DepartmentEmployee where dept.EmployeeID == empDep.EmployeeId select dept).FirstOrDefault(); if (selectEmployee == null) { var assignDepartmentToEmployee = new DepartmentEmployee { EmployeeID = empDep.EmployeeId, DepartmentID = empDep.DepartmentID }; _db.DepartmentEmployee.Add(assignDepartmentToEmployee); } else { selectEmployee.DepartmentID = empDep.DepartmentID; _db.DepartmentEmployee.Update(selectEmployee); } _db.SaveChanges(); }
public ActionResult updateEmployee(HttpPostedFileBase EmployeeAvatarFile, HttpPostedFileBase EmployeeCoverPictureFile, Employee e, int DepartmentId, int DepartmentIdOld) { try { if (EmployeeAvatarFile == null && EmployeeCoverPictureFile == null) { Employee em = db.Employees.Find(e.EmployeeId); em.EmployeeEmail = e.EmployeeEmail; em.EmployeeAddress = e.EmployeeAddress; em.EmployeeAvatar = em.EmployeeAvatar; em.EmployeeBirthday = e.EmployeeBirthday; em.EmployeeCoverPicture = em.EmployeeCoverPicture; em.EmployeeFullname = e.EmployeeFullname; em.EmployeeGender = e.EmployeeGender; em.EmployeeIdCard = e.EmployeeIdCard; em.EmployeePassword = em.EmployeePassword; em.EmployeePhone = e.EmployeePhone; em.EmployeeStatus = e.EmployeeStatus; db.Entry(em).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); DepartmentEmployee de = db.DepartmentEmployees.SingleOrDefault(x => x.EmployeeId == em.EmployeeId && x.DepartmentId == DepartmentIdOld); de.DepartmentId = DepartmentId; de.EmployeeId = em.EmployeeId; de.DepartmentEmployeeStatus = 1; db.Entry(de).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); TempData["error"] = "cập nhật thành công"; } else { if (EmployeeCoverPictureFile == null) { string avatarFile = Path.Combine(Server.MapPath("~/Content/images/avatar/"), Path.GetFileName(EmployeeAvatarFile.FileName)); EmployeeAvatarFile.SaveAs(avatarFile); var avatar = EmployeeAvatarFile.FileName; Employee em = db.Employees.Find(e.EmployeeId); em.EmployeeEmail = e.EmployeeEmail; em.EmployeeAddress = e.EmployeeAddress; em.EmployeeAvatar = avatar; em.EmployeeBirthday = e.EmployeeBirthday; em.EmployeeCoverPicture = em.EmployeeCoverPicture; em.EmployeeFullname = e.EmployeeFullname; em.EmployeeGender = e.EmployeeGender; em.EmployeeIdCard = e.EmployeeIdCard; em.EmployeePassword = em.EmployeePassword; em.EmployeePhone = e.EmployeePhone; em.EmployeeStatus = e.EmployeeStatus; db.Entry(em).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); DepartmentEmployee de = db.DepartmentEmployees.SingleOrDefault(x => x.EmployeeId == em.EmployeeId && x.DepartmentId == DepartmentIdOld); de.DepartmentId = DepartmentId; de.EmployeeId = em.EmployeeId; de.DepartmentEmployeeStatus = 1; db.Entry(de).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); TempData["error"] = "cập nhật thành công"; } else if (EmployeeAvatarFile == null) { string coverPictureFile = Path.Combine(Server.MapPath("~/Content/images/coverPicture/"), Path.GetFileName(EmployeeCoverPictureFile.FileName)); EmployeeCoverPictureFile.SaveAs(coverPictureFile); var coverPicture = EmployeeCoverPictureFile.FileName; Employee em = db.Employees.Find(e.EmployeeId); em.EmployeeEmail = e.EmployeeEmail; em.EmployeeAddress = e.EmployeeAddress; em.EmployeeAvatar = em.EmployeeAvatar; em.EmployeeBirthday = e.EmployeeBirthday; em.EmployeeCoverPicture = coverPicture; em.EmployeeFullname = e.EmployeeFullname; em.EmployeeGender = e.EmployeeGender; em.EmployeeIdCard = e.EmployeeIdCard; em.EmployeePassword = em.EmployeePassword; em.EmployeePhone = e.EmployeePhone; em.EmployeeStatus = e.EmployeeStatus; db.Entry(em).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); DepartmentEmployee de = db.DepartmentEmployees.SingleOrDefault(x => x.EmployeeId == em.EmployeeId && x.DepartmentId == DepartmentIdOld); de.DepartmentId = DepartmentId; de.EmployeeId = em.EmployeeId; de.DepartmentEmployeeStatus = 1; db.Entry(de).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); TempData["error"] = "cập nhật thành công"; } else { string avatarFile = Path.Combine(Server.MapPath("~/Content/images/avatar/"), Path.GetFileName(EmployeeAvatarFile.FileName)); EmployeeAvatarFile.SaveAs(avatarFile); var avatar = EmployeeAvatarFile.FileName; string coverPictureFile = Path.Combine(Server.MapPath("~/Content/images/coverPicture/"), Path.GetFileName(EmployeeCoverPictureFile.FileName)); EmployeeCoverPictureFile.SaveAs(coverPictureFile); var coverPicture = EmployeeCoverPictureFile.FileName; Employee em = db.Employees.Find(e.EmployeeId); em.EmployeeEmail = e.EmployeeEmail; em.EmployeeAddress = e.EmployeeAddress; em.EmployeeAvatar = avatar; em.EmployeeBirthday = e.EmployeeBirthday; em.EmployeeCoverPicture = coverPicture; em.EmployeeFullname = e.EmployeeFullname; em.EmployeeGender = e.EmployeeGender; em.EmployeeIdCard = e.EmployeeIdCard; em.EmployeePassword = em.EmployeePassword; em.EmployeePhone = e.EmployeePhone; em.EmployeeStatus = e.EmployeeStatus; db.Entry(em).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); DepartmentEmployee de = db.DepartmentEmployees.SingleOrDefault(x => x.EmployeeId == em.EmployeeId && x.DepartmentId == DepartmentIdOld); de.DepartmentId = DepartmentId; de.EmployeeId = em.EmployeeId; de.DepartmentEmployeeStatus = 1; db.Entry(de).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); TempData["error"] = "cập nhật thành công"; } } return(RedirectToAction("Index")); } catch (Exception) { TempData["error"] = "cập nhật không thành công"; return(RedirectToAction("Index")); throw; } }
public void Update(DepartmentEmployee entity) { throw new NotImplementedException(); }
public void Delete(DepartmentEmployee entity) { departmentEmployeeRepository.Delete(entity); }
public DepartmentEmployeeVM(DepartmentEmployee deptEmployee) { _deptEmployee = deptEmployee; InitializeViewModel(); }
public void UpdateDepartmentEmployee(DepartmentEmployee employee) { _departmentEmployeeRepository.Update(employee); }
public void Insert(DepartmentEmployee entity) { departmentEmployeeRepository.Insert(entity); }