//Get Employee By Id public Employee GetById(string EmpId) { using (EmployeeManagementContext db = new EmployeeManagementContext()) { return(db.Employee.Find(EmpId)); } }
public void GetEmployees() { using (var context = new EmployeeManagementContext()) { List <Employee> employees = context.Employees.ToList <Employee>(); if (employees.Count > 1) { foreach (Employee emp in employees) { var count = dataGridView.Rows.Count - 1; dataGridView.Rows.Add(); dataGridView.Rows[count].Cells[0].Value = emp.EmployeeID; dataGridView.Rows[count].Cells[1].Value = emp.FullName; dataGridView.Rows[count].Cells[2].Value = emp.Address; dataGridView.Rows[count].Cells[3].Value = emp.Contact; dataGridView.Rows[count].Cells[4].Value = emp.Email; dataGridView.Rows[count].Cells[5].Value = emp.Designation; dataGridView.Rows[count].Cells[6].Value = emp.Department; dataGridView.Rows[count].Cells[7].Value = emp.DateOfJoin; dataGridView.Rows[count].Cells[8].Value = emp.WageRate; dataGridView.Rows[count].Cells[9].Value = emp.WorkedHour; count++; } } } }
// GET: Employee public ActionResult Index(String id) { staticName = id; using (EmployeeManagementContext db = new EmployeeManagementContext()) { List <Employee> employees = db.Employees.ToList(); List <Shift> shifts = db.Shifts.ToList(); Employee employee = db.Employees.Find(HomeController.userID); var shift = db.Shifts.Find(HomeController.userID); var employeeRecord = from e in employees where e.username == staticName join s in shifts on e.id equals s.employeeId into table1 from s in table1.ToList() select new Shift { Employee = employee, date = s.date, id = s.id, attendance = s.attendance, employeeId = s.employeeId }; userID = employee.id; if (employeeRecord == null) { return(HttpNotFound()); } staticName = id; ViewBag.name = staticName; ViewBag.id = userID; return(View(employeeRecord)); } }
private bool DepartmentExists(int id) { using (var context = new EmployeeManagementContext()) { return(context.Departments.Any(e => e.DeptId == id)); } }
public async Task <IActionResult> Create([Bind("Name,Surname,Address,Qualification,ContactNumber, DeptId")] Employee employee) { if (ModelState.IsValid) { using (var _context = new EmployeeManagementContext()) { _context.Add(employee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } using (var _context = new EmployeeManagementContext()) { var departments = await _context.Departments.Select(a => new SelectListItem { Value = a.DeptId.ToString(), Text = $"{a.DeptName}" }).ToListAsync(); ViewBag.Departments = departments; //ViewData["DeptId"] = new SelectList(_context.Departments, "DeptId", "DeptId", employee.DeptId); } return(View(employee)); }
private bool EmployeeExists(int id) { using (var _context = new EmployeeManagementContext()) { return(_context.Employees.Any(e => e.DeptId == id)); } }
private async void btnSave_Click(object sender, EventArgs e) { string id = txtIdNo.Text; string name = txtFullName.Text; string address = txtAddress.Text; string contactNo = txtContact.Text; string email = txtEmail.Text; string desigination = txtDesignation.Text; string department = comboBoxDepartment.Text; string dateOfJoin = dateTimePicker.Text; string wageRate = txtWage.Text; string hourWorked = txtWorkedHour.Text; using (EmployeeManagementContext context = new EmployeeManagementContext()) { Employee emp = new Employee(id, name, address, contactNo, email, desigination, department, dateOfJoin, wageRate, hourWorked); context.Employees.Add(emp); await context.SaveChangesAsync(); } //instance event args and value has been passed IdentityEventArgs args = new IdentityEventArgs(id, name, address, contactNo, email, desigination, department, dateOfJoin, wageRate, hourWorked); //Event has be raised with update arguments of delegate IdentityUpdated?.Invoke(this, args); this.Hide(); }
public async Task <IActionResult> Edit(int id, [Bind("DeptId,DeptName")] Department department) { if (id != department.DeptId) { return(NotFound()); } if (ModelState.IsValid) { try { using (var context = new EmployeeManagementContext()) { context.Update(department); await context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(department.DeptId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } //return View(author); return(RedirectToAction("Index")); }
public EmployeeValidator(EmployeeManagementContext dbContext) { RuleFor(emp => emp.FirstName).NotEmpty() .WithMessage("{PropertyName} should be not empty.") .Must(IsValid) .WithMessage("{PropertyName} should be all letters."); RuleFor(emp => emp.LastName).NotEmpty() .WithMessage("{PropertyName} should be not empty.") .Must(IsValid) .WithMessage("{PropertyName} should be all letters."); RuleFor(emp => emp.EmailId).NotEmpty() .WithMessage("{PropertyName} should be not empty.") .EmailAddress() .WithMessage("{PropertyName} should be in valid email format.");; RuleFor(emp => emp.DepartmentId).NotEmpty() .WithMessage("{PropertyName} should be not empty."); RuleFor(emp => emp.ManagerId).NotEmpty() .WithMessage("{PropertyName} should be not empty.") .Must(IsThereManagerNullAlready) .WithMessage("{PropertyName} cannot be null. Already there is a manager with null"); this.dbContext = dbContext; }
static public void PeopleSeed() { EmployeeManagementContext db = new EmployeeManagementContext(); Employee emp; Random rnd = new Random(); for (int i = 0; i < 1000; i++) { emp = new Employee(); emp.Name = "Name: " + i; int booo = rnd.Next(1); if (booo == 1) { emp.IsMale = true; } else { emp.IsMale = false; } //emp.PhoneNumber = rnd.Next(1231234, 3214321); emp.Age = rnd.Next(18, 50); emp.DateofBirth = DateTime.Now; emp.Email = "Something00" + i + "@infoSys.com"; emp.State = rnd.Next(1, 50); emp.State1 = db.States.First(p => p.StateID == emp.State); int edu = (rnd.Next(1, 7)); emp.Educations.Add(db.Educations.Single(p => p.EducationID == edu)); db.Employees.Add(emp); } db.SaveChanges(); }
public ActionResult EditDetails() { using (EmployeeManagementContext db = new EmployeeManagementContext()) { List <Employee> employees = db.Employees.ToList(); var employeeRecord = from e in employees where e.username == userID select new Employee { phoneNo = e.phoneNo, homeAddress = e.homeAddress, email = e.email, username = e.username, password = e.password }; if (employeeRecord == null) { return(HttpNotFound()); } ViewBag.id = userID; ViewBag.name = staticName; return(View(employeeRecord.First())); } }
//Get All Employees public List <Employee> GetAll() { using (EmployeeManagementContext db = new EmployeeManagementContext()) { return(db.Employee.ToList()); } }
public UnitOfWork(EmployeeManagementContext ctx) { _ctx = ctx; EmployeeLeaveAllocationRepository = new EmployeeLeaveAllocationRepository(_ctx); EmployeeLeaveRequestRepository = new EmployeeLeaveRequestRepository(_ctx); EmployeeLeaveTypeRepository = new EmployeeLeaveTypeRepository(_ctx); }
public void Update(Employee employee) { using (EmployeeManagementContext db = new EmployeeManagementContext()) { db.Employee.Update(employee); db.SaveChanges(); } }
// GET: Schedule public ActionResult Schedule() { using (EmployeeManagementContext db = new EmployeeManagementContext()) { List <Shift> shifts = db.Shifts.ToList(); //get all employee shifts var employeeShift = from s in shifts where s.Employee.id == userID select new Shift { id = s.id, Employee = s.Employee, employeeId = s.employeeId, date = s.date, attendance = s.attendance }; //get all employee attended shifts var pList = from s in shifts where s.Employee.id == userID && s.attendance == Shift.Attendance.Present select new Shift { attendance = s.attendance }; //get all employee missed shifts var aList = from s in shifts where s.Employee.id == userID && s.attendance == Shift.Attendance.Absent select new Shift { attendance = s.attendance }; //calculate the ratio of work attended to work absence ViewBag.total = employeeShift.Count(); ViewBag.pending = employeeShift.Count() - (pList.Count() + aList.Count()); ViewBag.present = pList.Count(); ViewBag.absent = aList.Count(); if (employeeShift.Count() != 0 && pList.Count() != 0) { ViewBag.totalPrcnt = (pList.Count() * 100) / (aList.Count() + pList.Count()) + "%"; ViewBag.bar = ViewBag.totalPrcnt; } else { ViewBag.totalPrcnt = "Not evaluable at this time"; ViewBag.bar = "0%"; } ViewBag.id = userID; ViewBag.name = staticName; return(View(employeeShift)); } }
public async Task <IActionResult> Index() { //var context = new EFCoreWebDemoContext(); using (var context = new EmployeeManagementContext()) { var model = await context.Employees.Include(a => a.Department).AsNoTracking().ToListAsync(); return(View(model)); } }
//Delete Record public void Delete(string EmpId) { using (EmployeeManagementContext db = new EmployeeManagementContext()) { Employee e = db.Employee.Find(EmpId); db.Employee.Remove(e); db.SaveChanges(); } }
public override string GetUserNameByEmail(string email) { using (EmployeeManagementContext dbContext = new EmployeeManagementContext()) { string username = (from u in dbContext.Users where string.Compare(email, u.Email) == 0 select u.Username).FirstOrDefault(); return(!string.IsNullOrEmpty(username) ? username : string.Empty); } }
public async Task <IActionResult> DeleteConfirmed(int id) { using (var _context = new EmployeeManagementContext()) { var employee = await _context.Employees.FindAsync(id); _context.Employees.Remove(employee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } }
public async Task <IActionResult> Create([Bind("DeptName")] Department department) { using (var context = new EmployeeManagementContext()) { if (ModelState.IsValid) { context.Add(department); await context.SaveChangesAsync(); } return(RedirectToAction("Index")); } }
public ActionResult Index([Bind(Include = "username,password")] Employee empInput) { using (EmployeeManagementContext db = new EmployeeManagementContext()) { // login setup List <Employee> employees = db.Employees.ToList(); if (empInput.username == null || empInput.password == null) { msg = "Username and Password is required!"; ViewBag.notice = msg; return(View()); } Employee emp = db.Employees .Where(e => e.username == empInput.username) .FirstOrDefault(); //Redirect to login page if user is not found in database if (emp == null) { msg = "Employee not found, input correct username"; ViewBag.notice = msg; return(View(emp)); } // Redirect to employee system if user privilege is user if (emp.username == empInput.username && emp.password == empInput.password && emp.privilege == Employee.Privilege.User) { msg = ""; userID = emp.id; return(RedirectToAction("Index", "Employee", new { id = emp.username })); } // Redirect to administrator system if user privilege is admin else if (emp.username == empInput.username && emp.password == empInput.password && emp.privilege == Employee.Privilege.Admin) { msg = ""; userID = emp.id; return(RedirectToAction("Index", "Administrator", new { id = emp.username })); } else { msg = "Authentification Failed. Make sure your UserName and Password is correct"; ViewBag.notice = msg; return(View(emp)); } ViewBag.notice = msg; return(View(emp)); } }
public async Task <IActionResult> Create() { using (var _context = new EmployeeManagementContext()) { var departments = await _context.Departments.Select(a => new SelectListItem { Value = a.DeptId.ToString(), Text = $"{a.DeptName}" }).ToListAsync(); ViewBag.Departments = departments; return(View()); } }
public EmployeeValidator(EmployeeManagementContext _dbContext) { dbContext = _dbContext; RuleFor(model => model.FirstName).NotEmpty() .WithMessage("Firs tName should be not empty."); RuleFor(model => model.LastName).NotEmpty() .WithMessage("Last Name should be not empty."); RuleFor(model => model.EmailId).NotEmpty() .WithMessage("Email should be not empty.") .EmailAddress() .WithMessage("{PropertyName} should be in valid email format."); RuleFor(emp => emp.ManagerId).NotEmpty() .WithMessage("ManagerId should not be empty.") .Must(IsNullManagerIdExisted) .WithMessage("ManagerId cannot be null"); }
public void Should_Be_Able_To_Retrieve_Employee_From_DB() { using (var context = new EmployeeManagementContext()) using (var repo = new EmployeeRepository(context)) using (var txn = context.Database.BeginTransaction()) { context.Set <EmployeeEntity>().AddRange(Data.EmployeeEntities); context.SaveChanges(); var employee = repo.GetEmployee(Data.User1Id); txn.Rollback(); Assert.IsNotNull(employee); } }
public void Should_Be_Able_To_Retrieve_All_Employees_From_DB() { using (var context = new EmployeeManagementContext()) using (var repo = new EmployeeRepository(context)) using (var txn = context.Database.BeginTransaction()) { context.Set <EmployeeEntity>().AddRange(Data.EmployeeEntities); context.SaveChanges(); var employees = repo.GetAllEmployees(); txn.Rollback(); Assert.AreEqual(2, employees.Count); } }
public ActionResult Registration(RegistrationView registrationView) { bool statusRegistration = false; string messageRegistration = string.Empty; if (ModelState.IsValid) { // Email Verification string userName = Membership.GetUserNameByEmail(registrationView.Email); if (!string.IsNullOrEmpty(userName)) { ModelState.AddModelError("Warning Email", "Sorry: Email already Exists"); return(View(registrationView)); } //Save User Data using (EmployeeManagementContext dbContext = new EmployeeManagementContext()) { var user = new User() { Username = registrationView.Username, FirstName = registrationView.FirstName, LastName = registrationView.LastName, Email = registrationView.Email, Password = registrationView.Password, IsActive = true, ActivationCode = Guid.NewGuid(), }; dbContext.Users.Add(user); dbContext.SaveChanges(); } //Verification Email //VerificationEmail(registrationView.Email, registrationView.ActivationCode.ToString()); messageRegistration = "Your account has been created successfully."; statusRegistration = true; } else { messageRegistration = "Something Wrong!"; } ViewBag.Message = messageRegistration; ViewBag.Status = statusRegistration; return(View(registrationView)); }
/// <summary> /// /// </summary> /// <param name="username"></param> /// <param name="userIsOnline"></param> /// <returns></returns> public override MembershipUser GetUser(string username, bool userIsOnline) { using (EmployeeManagementContext dbContext = new EmployeeManagementContext()) { var user = (from us in dbContext.Users where string.Compare(username, us.Username, StringComparison.OrdinalIgnoreCase) == 0 select us).FirstOrDefault(); if (user == null) { return(null); } var selectedUser = new CustomMembershipUser(user); return(selectedUser); } }
// GET: Author/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } using (var context = new EmployeeManagementContext()) { var department = await context.Departments.FindAsync(id); if (department == null) { return(NotFound()); } return(View(department)); } }
// GET: Author/Delete/5 public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } using (var context = new EmployeeManagementContext()) { var department = await context.Departments.FirstOrDefaultAsync(m => m.DeptId == id); if (department == null) { return(NotFound()); } return(View(department)); } }
public void Should_Be_Able_To_Get_Add_Employee_To_DB() { using (var context = new EmployeeManagementContext()) using (var repo = new EmployeeRepository(context)) using (var txn = context.Database.BeginTransaction()) { var employee = Data.EmployeeEntities[0]; repo.Create(employee); var dbEmployee = context.Set <EmployeeEntity>().Find(Data.User1Id); txn.Rollback(); Assert.IsNotNull(dbEmployee); } }