public void Get_Employees_ValidCall() { using (AutoMock mock = AutoMock.GetLoose()) { // setup mocked environment mock.Mock <IEmployeeDataAccess>() .Setup(x => x.LoadEmployees("SELECT * FROM Employee")) .Returns(GetSampleEmployees()); // create the actual class to run the employee get method EmployeeProcessor cls = mock.Create <EmployeeProcessor>(); // get sample expected data var expected = GetSampleEmployees(); // run the get employees method which will instead return dummy data var actual = cls.GetEmployees(); // do asserts Assert.True(actual != null); Assert.Equal(expected.Count, actual.Count); for (int i = 0; i < expected.Count; i++) { Assert.Equal(expected[i].Id, actual[i].Id); Assert.Equal(expected[i].FirstName, actual[i].FirstName); Assert.Equal(expected[i].LastName, actual[i].LastName); Assert.Equal(expected[i].Occupation, actual[i].Occupation); } } }
public void Create_Employee_Fails_With_Bad_Inputs(string guidAsString, string firstName, string lastName, string occupation) { EmployeeProcessor employeeProcessor = new EmployeeProcessor(null); Assert.Throws <ArgumentException>(() => employeeProcessor.CreateEmployee(Guid.Parse(guidAsString), firstName, lastName, occupation)); }
public ActionResult ViewEmployees(string searchString) { //Check if user is logged in then redirect him to gome page if (Session["Email"] == null) { return(RedirectToAction("SignIn", "User")); } else { //Load all employees fro data base then add filter to filter them var data = EmployeeProcessor.LoadEmployees(); List <EmployeeModel> employees = new List <EmployeeModel>(); foreach (var row in data) { employees.Add(new EmployeeModel { EmployyeId = row.EmpID, EmployeeName = row.EmpName, EmployeeContacts = row.EmpContacts, EmployeeAge = row.EmpAge, EmployeeDeaprtment = row.DepName, }); } if (!String.IsNullOrEmpty(searchString)) { employees = employees.Where(e => e.EmployeeName.Contains(searchString)).ToList(); } return(View(employees)); } }
public IViewComponentResult Invoke() { int id = HttpContext.GetCurrentEmployeeModel().Id; var data = RequestProcessor.LoadMyRequests(id); List <RequestModel> requests = new List <RequestModel>(); foreach (var row in data) { EmployeeDataModel?AcceptedByEmployee = EmployeeProcessor.GetUserById(row.employee_id_acceptedby); string nameAccept = " "; if (AcceptedByEmployee != null) { nameAccept = AcceptedByEmployee.Firstname + " " + AcceptedByEmployee.Lastname; } string dateStart = row.datetimestart.ToShortDateString(); string dateEnd = row.datetimeend.ToShortDateString(); string TimeStart = row.datetimestart.ToShortTimeString(); string TimeEnd = row.datetimeend.ToShortTimeString(); requests.Add(new RequestModel { RequestId = row.id, EmployeeAcceptedbyName = nameAccept, stringDateStart = dateStart, Status = row.status.ToEnum <RequestStatus>(), Type = row.request_type.ToEnum <RequestType>() }); } return(View(requests)); }
private void ProcessEmployees(EmployeeProcessor process) //method that takes a delegate as a param { foreach (var employee in Employees) { process(employee); //process a single employee based on delegate } }
public IActionResult RegisterEmployee(EmployeeCreateModel employee) { if (ModelState.IsValid) { string salt = PasswordHashingLogic.GenerateSalt(); string PasswordHash = PasswordHashingLogic.GeneratePasswordHash(employee.Password, salt); string uniqueFileName = null; if (employee.ProfilePicture != null) { string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "img", "ProfilePictures"); uniqueFileName = Guid.NewGuid().ToString() + "_" + employee.ProfilePicture.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); employee.ProfilePicture.CopyTo(new FileStream(filePath, FileMode.Create)); } EmployeeProcessor.CreateEmployee( employee.Firstname, employee.Prefix, employee.Lastname, employee.City, employee.Postalcode, employee.Address, uniqueFileName, employee.Email, employee.Phone, salt, PasswordHash, employee.Profession, employee.Role.ToString() ); return(RedirectToAction("ViewEmployees", "Employee")); } return(View()); }
public IActionResult ViewEmployees() { var data = EmployeeProcessor.LoadEmployees(); List <EmployeeModel> employees = new List <EmployeeModel>(); foreach (var row in data) { employees.Add(new EmployeeModel { Id = row.ID, Firstname = row.Firstname, Prefix = row.Lastnameprefix, Lastname = row.Lastname, City = row.City, Postalcode = row.PostalCode, Address = row.Address, ProfilePicturePath = row.ProfilePicturePath, Email = row.Email, Phone = row.Phone, Profession = row.Profession, Role = row.Role.ToEnum <EmployeeRole>() }); } return(View(employees)); }
public IActionResult LoginEmployee(LoginEmployeeModel login) { if (ModelState.IsValid) { EmployeeDataModel employeeData = EmployeeProcessor.GetUserByEmail(login.Email); if (employeeData != null) { if (PasswordHashingLogic.ValidateUser(login.Password, employeeData.Salt, employeeData.PasswordHash)) { var employeeClaims = new List <Claim>() { new Claim(ClaimTypes.Email, employeeData.Email), new Claim(ClaimTypes.Role, employeeData.Role) }; var employeeIdentity = new ClaimsIdentity(employeeClaims, "Employee Identity"); var employeePrincipal = new ClaimsPrincipal(new[] { employeeIdentity }); HttpContext.SignInAsync(employeePrincipal); return(RedirectToAction("Dashboard", "Home")); } } else { ModelState.AddModelError("incorrectLogin", "The provided email and password do not match."); } } return(View()); }
// Do something for all employees. private void ProcessEmployees(EmployeeProcessor process) { foreach (Employee employee in Employees) { process(employee); } }
// Mapp Employees public static List <EmployeeVM> MappEmployeeToVM(List <DataLibrary.Models.EmployeesModel> input) { var output = new List <EmployeeVM>(); foreach (var item in input) { var model = new EmployeeVM(); model.FirstName = item.FirstName; model.LastName = item.LastName; model.Id = item.Id; model.ManagerId = item.ManagerId; if (model.ManagerId > 0) { var manager = EmployeeProcessor.GetManager((int)model.ManagerId); var sb = new StringBuilder(); sb.Append(manager.FirstName); sb.Append(" "); sb.Append(manager.LastName); model.DisplayName = sb.ToString(); } model.IsManager = item.IsManager; model.IsCEO = item.IsCEO; model.Salary = item.Salary; model = LogicClass.setRole(model); output.Add(model); } return(output); }
public ActionResult ViewEmployees( ) { ViewBag.Message = "Employees List"; var data = EmployeeProcessor.LoadEmployees(); return(View(data)); }
public IActionResult UpdateEmployee(EmployeeModel model) { if (ModelState.IsValid) { EmployeeProcessor.UpdateEmployee(model.City, model.Postalcode, model.Address, model.Email, model.Phone, model.Profession, model.Password, model.Id); } return(RedirectToAction("Dashboard", "Home")); }
public ActionResult SignUp(EmployeeModel model) { if (ModelState.IsValid) { int recordsCreated = EmployeeProcessor.CreateEmployee(model.employeeID, model.firstName, model.lastName, model.emailAddress); return(RedirectToAction("Index")); } return(View()); }
public ActionResult SignUp(EmployeeModel model) { if (ModelState.IsValid) { EmployeeProcessor.CreateEmployee(model.EmployeeId, model.FirstName, model.LastName, model.EmailAddress); return(RedirectToAction("ViewEmployees")); } return(View()); }
public void GenerateEmploeeId_ShouldCalculate(string firstName, string secondName, string expectedStart) { //Arrange EmployeeProcessor employeeProcessor = new EmployeeProcessor(); //Act string actualStart = employeeProcessor.GenerateEmployeeID(firstName, secondName).Substring(0, expectedStart.Length); //Assert Assert.Equal(expectedStart, actualStart); }
private async void GetEmployee() { // ObservableCollection<EmployeeModel> employees = null; var employeeGroup = await EmployeeProcessor.LoadEmployee(); foreach (EmployeeModel employee in employeeGroup) { EmployeeList.Add(employee); } }
private void generateEmployeeIdButton_Click(object sender, EventArgs e) { string firstName = firstNameText.Text; string lastName = lastNameText.Text; EmployeeProcessor processor = new EmployeeProcessor(); string employeeId = processor.GenerateEmployeeId(firstName, lastName); employeeIdText.Text = employeeId; }
public IActionResult DetailsIncident(int id) { int count = 0; var incidentData = IncidentProcessor.LoadIncidentById(id); var incidentEmployeeData = IncidentEmployeeProcessor.LoadEmployeesByIncidentId(id); var incidentStepData = IncidentStepProcessor.LoadStepsByIncidentId(id); List <IncidentStepModel> steps = new List <IncidentStepModel>(); List <EmployeeModel> employees = new List <EmployeeModel>(); foreach (var step in incidentStepData) { count++; steps.Add(new IncidentStepModel { title = step.title, context = step.context, datetimeEnd = step.datetimeEnd, datetimeStart = step.datetimeStart, employee_id_createdby = step.employee_id_createdby, employee_id_endedby = step.employee_id_endedby, id = step.id, incident_id = step.incident_id, status = step.status, stepnumber = count } ); } foreach (var employee in incidentEmployeeData) { var data = EmployeeProcessor.GetUserById(employee.Employee_Id); employees.Add(new EmployeeModel { Firstname = data.Firstname, Lastname = data.Lastname, ProfilePicturePath = data.ProfilePicturePath, Id = data.ID } ); } IncidentDetailsViewModel incidentDetails = new IncidentDetailsViewModel { id = id, Context = incidentData.Context, Customer = incidentData.Customer, CustomerEmail = incidentData.CustomerEmail, Title = incidentData.Title, Status = incidentData.Status, steps = steps, employees = employees }; ViewData["webroot"] = _env.WebRootPath; return(View(incidentDetails)); }
// GET: Employee public ActionResult Index(string message) { if (message != null) { ViewData["ErrorMessage"] = message; } var tempList = EmployeeProcessor.LoadEmployees(); var output = mapping.MappEmployeeToVM(tempList); return(View(output.OrderBy(x => x.Role == "Employee").ThenBy(x => x.Role == "Manager").ThenBy(x => x.Role == "CEO"))); }
public async Task <List <Employee> > List() { _employees = new List <Employee>(); // _employees var apiEmployee = await EmployeeProcessor.LoadEmployees(); _employees = ConvertApiListToDomain(apiEmployee); return(_employees); }
public ActionResult Delete(int id) { if (EmployeeProcessor.GetEmployeeNumForManager(id) == 0) { EmployeeProcessor.DeleteEmployee(id); return(RedirectToAction("Index")); } string message = "You can't delete a manager that still is managing employees"; return(RedirectToAction("Index", new { message = message })); }
public void GenerateEmployeeId_ShouldCalculate(string firstName, string lastName, string expectedStart) { //Arange //Act EmployeeProcessor processor = new EmployeeProcessor(); string actualStart = processor.GenereteEmployeeId(firstName, lastName).Substring(0, expectedStart.Length); //Asert Assert.Equal(expectedStart, actualStart); }
public ActionResult SignUp(EmployeeModel model) { if (ModelState.IsValid) { int recordsCreated = EmployeeProcessor.CreateEmployee(model.EmployeeId, model.FirstName, model.LastName, model.EmailAddress); return(RedirectToAction("Index", "Home")); } ViewBag.Message = "Employee Sign Up"; return(View()); }
public void Create_Employee_Passes_With_Good_Inputs(string guidAsString, string firstName, string lastName, string occupation) { EmployeeProcessor employeeProcessor = new EmployeeProcessor(null); Employee expected = new Employee(Guid.Parse(guidAsString), firstName, lastName, occupation); Employee actual = employeeProcessor.CreateEmployee(Guid.Parse(guidAsString), firstName, lastName, occupation); Assert.NotNull(actual); Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.FirstName, actual.FirstName); Assert.Equal(expected.LastName, actual.LastName); Assert.Equal(expected.Occupation, actual.Occupation); }
public async Task <Employee> GetById(int id) { if (_employees == null) { var apiEmployee = await EmployeeProcessor.LoadEmployees(); _employees = ConvertApiListToDomain(apiEmployee); } var employee = _employees.Find(emp => emp.Id == id); // Employee return(employee); }
public ActionResult Signup(Employee model) { if (ModelState.IsValid) { int records = EmployeeProcessor.CreateEmployee( model.EmployeeId, model.FirstName, model.LastName, model.Email_Id, Crypto.Hash(model.Password)); return(RedirectToAction("Index")); } return(View()); }
public static int CheckManager(EmployeeVM model) { if (model.SelectedManager != null) { int managerId = int.Parse(model.SelectedManager); var ceo = EmployeeProcessor.CheckForCEO(); if (ceo.Id == managerId && model.IsManager == false) { return(0); } return(managerId); } return(-1); }
public static EmployeeModel GetCurrentEmployeeModel(this HttpContext httpContext) { Claim email = httpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email); if (email == null) { return(null); } EmployeeDataModel dataModel = EmployeeProcessor.GetUserByEmail(email.Value); EmployeeModel employeeModel = new EmployeeModel(); employeeModel.MapDataModel(dataModel); return(employeeModel); }
public ActionResult AddEmployee(string currentCEO) { ViewBag.Message = "Add a Employee"; if (currentCEO != null) { ViewData["ErrorMessage"] = currentCEO; } var model = new EmployeeVM(); model.ManagerList = mapping.MappEmployeeToVM(EmployeeProcessor.GetManagers()); model = LogicClass.setDisplayName(model); return(View(model)); }
//[InlineData("Wi", "Smith", "Wi**Smit")] //[InlineData("Wi", "Sm", "Wi**Sm**")] public void GenerateEmployeeId_ShouldWork(string firstName, string lastName, string expectId) { //arrange EmployeeProcessor processor = new EmployeeProcessor(); //string firstName = "Will"; //string lastName = "Smith"; //string expectId = "WillSmit"; //act string employeeId = processor.GenerateEmployeeId(firstName, lastName); string actualEmployeeId = employeeId.Substring(0, expectId.Length); //assert Assert.Equal(expectId, actualEmployeeId); }