public void EmployeeViewModelAddShouldReturnId() { EmployeeViewModel vm = new EmployeeViewModel(); vm.Title = "Mr"; vm.Firstname = "Phuc"; vm.Lastname = "Nguyen"; vm.Email = "*****@*****.**"; vm.Phoneno = "(555)555-5555"; vm.DepartmentId = 400; vm.Add(); Assert.IsTrue(vm.Id > 0); }
//A test for the Add method public void EmployeeViewModelAddShouldReturnId() { EmployeeViewModel vm = new EmployeeViewModel(); vm.Title = "Mr"; vm.Firstname = "Kiet"; vm.Lastname = "Ng"; vm.Email = "*****@*****.**"; vm.Phoneno = "(555)555-9999"; vm.DepartmentId = 400; vm.Add(); Assert.IsTrue(vm.Id > 0); }
public void EmployeeViewModelAddShouldReturnId() { EmployeeViewModel vm = new EmployeeViewModel(); vm.Title = "Mr."; vm.Firstname = "Chris"; vm.Lastname = "Pollock"; vm.Email = "*****@*****.**"; vm.Phoneno = "(555)555-5551"; vm.DepartmentId = 100; vm.Add(); Assert.IsTrue(vm.Id > 0); }
public void Employee_AddTest() { EmployeeViewModel vm = new EmployeeViewModel(); vm.Title = "Mrs"; vm.Firstname = "Sonia"; vm.Lastname = "Friesen"; vm.Phoneno = "123-345-222"; vm.Email = "*****@*****.**"; vm.DepartmentId = 200; vm.Add(); Assert.True(vm.Id > 0); }
public void Employee_AddTest() { EmployeeViewModel em = new EmployeeViewModel(); em.Firstname = "Jimin"; em.Lastname = "Park"; em.Phoneno = "(111)000-0000"; em.Title = "Ms."; em.DepartmentId = 100; em.Email = "*****@*****.**"; em.Add(); Assert.True(em.Id > 0); }
public IActionResult POST(EmployeeViewModel viewmodel) { try { viewmodel.Add(); return(viewmodel.Id > 1 ? Ok(new { msg = "Employee " + viewmodel.LastName + " added!" }) : Ok(new { msg = "Employee " + viewmodel.LastName + "not added!" })); } catch (Exception ex) { _logger.LogError("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod().Name + " " + ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError));//something wrong } }
public void ViewModelAdd() { EmployeeViewModel vm = new EmployeeViewModel(); vm.Title = "Mr."; vm.Firstname = "Jason"; vm.Lastname = "Goldenberg"; vm.Email = "*****@*****.**"; vm.Phoneno = "(555)555-5551"; vm.DepartmentId = 100; vm.DepartmentName = "myDepartment"; vm.IsTech = true; vm.Add(); Assert.True(vm.Id > 0); }
public void Employeet_AddTest() { EmployeeViewModel vm = new EmployeeViewModel { FirstName = "Jean-Luc", LastName = "Desjardins", PhoneNo = "(555)555-5551", Title = "Mr.", DepartmentId = 100, Email = "*****@*****.**" }; vm.Add(); Assert.True(vm.id > 0); }
public IActionResult Post(EmployeeViewModel viewmodel) { try { // Calls add function viewmodel.Add(); // Returns status message after employee add function return(viewmodel.Id > 1 ? Ok(new { msg = "Employee " + viewmodel.Lastname + " added!" }) : Ok(new { msg = "Employee " + viewmodel.Lastname + " not added!" })); } catch (Exception ex) { _logger.LogError("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod().Name + " " + ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } // try/catch }
//Add an employee information to the database. return a result to represent if the addition is successful public IHttpActionResult Post(EmployeeViewModel emp) { try { emp.Add(); if (emp.Id > 0) { return(Ok("Employee " + emp.Lastname + " added!")); } else { return(Ok("Employee " + emp.Lastname + " not added")); } } catch (Exception ex) { return(BadRequest("Retrieve failed - " + ex.Message)); } }
public IHttpActionResult Post(EmployeeViewModel emp) { try { emp.Add(); if (emp.Id > 0) { return(Ok("Employee " + emp.Lastname + " added!")); } else { return(Ok("Employee " + emp.Lastname + " not added!")); } } catch (Exception ex) { return(BadRequest("Creation failed - Contact Tech Support" + ex.Message)); } }
public IHttpActionResult Post(EmployeeViewModel emp) { try { //Use the EmployeeViewModel's add method to add a new employee to the database emp.Add(); if (emp.Id > 0) { return(Ok("Employee " + emp.Lastname + " added!")); } else { return(Ok("Employee " + emp.Lastname + " not added!")); } } catch (Exception ex) { return(BadRequest("Creation failed - Contact Tech Support")); } }
// 'POST' method that adds a employee to the database public IHttpActionResult Post(EmployeeViewModel emp) { try { // Calls the EmployeeViewModel Add() function to add the required // employee data emp.Add(); // If an employee has been successfully added then display message saying // the add was successful, otherwise display that it was unsuccessful if (emp.Id > 0) { return(Ok("Student " + emp.Lastname + " added!")); } else { return(Ok("Student " + emp.Lastname + " not added!")); } } catch (Exception ex) { return(BadRequest("Creating failed - Contact Tech Support")); } }
private void CRUDItemEmployee(object sender, RoutedEventArgs e) { PasswordEncode passwordEncode = new PasswordEncode(); var action = (e.Source as Button).Content.ToString(); Console.WriteLine("=================>>>>>>>>>>>>CRUD Click: " + $"{action}"); /*MessageBox.Show(keyword);*/ string _nameEmp = FullnameEmployeeCRUD.Text; string _emailEmp = EmailEmployeeCRUD.Text; /*float _pRoom = float.Parse(PriceRoomCRUD.Text);*/ string _passwordEmp = PasswordEmployeeCRUD.Text; string hashed = passwordEncode.EncodePasswordToBase64(_passwordEmp); /*TypeRoom _typeRoomId = (TypeRoom)RoomTypeCb.SelectedItem;*/ // gives you the required string var _typeRoleId = roleViewModel.FindRoleIdByName("ROLE_EMPLOYEE").Id; if (RoleTypeCb.SelectedItem != null) { _typeRoleId = (RoleTypeCb.SelectedItem as Role).Id; } else { _typeRoleId = roleViewModel.FindRoleIdByName("ROLE_EMPLOYEE").Id; } switch (action) { case "Add": /* _nameRoom = NameRoomCRUD.Text; * _noteRoom = NoteRoomCRUD.Text; * _priceRoom = float.Parse(PriceRoomCRUD.Text); * * *//*TypeRoom _typeRoomId = (TypeRoom)RoomTypeCb.SelectedItem;*//* // gives you the required string * _typeRoomId = (RoomTypeCb.SelectedItem as TypeRoom).Id;*/ messageError = "Information Add Employee not blank"; captionError = "Confirmation"; MessageBoxButton buttonAddEmp = MessageBoxButton.YesNo; MessageBoxImage iconAddEmp = MessageBoxImage.Question; if (_nameEmp.Length == 0 || _emailEmp.Length == 0 || _passwordEmp.Length == 0) { MessageBox.Show(messageError, captionError, buttonAddEmp, iconAddEmp); } else { int _idAdd = 0; Console.WriteLine("=================>>>>>>>>>>>>Name Employee add: " + $"{_nameEmp}"); Console.WriteLine("=================>>>>>>>>>>>>Email add: " + $"{_emailEmp}"); Console.WriteLine("=================>>>>>>>>>>>>password add: " + $"{_passwordEmp}"); Console.WriteLine("=================>>>>>>>>>>>>TypeRoleId Room add: " + $"{_typeRoleId}"); Employee employee = new Employee() { Id = _idAdd, Fullname = _nameEmp, Email = _emailEmp, RoleId = _typeRoleId, Password = hashed }; employeeViewModel.Add(employee); } break; case "Update": messageError = "Information Update Employee not blank"; captionError = "Confirmation"; MessageBoxButton buttonUpdateEmp = MessageBoxButton.YesNo; MessageBoxImage iconUpdateEmp = MessageBoxImage.Question; if (IdEmployeeCRUD.Text.Length == 0) { messageError = "Employee not exist"; MessageBox.Show(messageError, captionError, buttonUpdateEmp, iconUpdateEmp); return; } if (_nameEmp.Length == 0 || _emailEmp.Length == 0) { MessageBox.Show(messageError, captionError, buttonUpdateEmp, iconUpdateEmp); } else { int _idUpdate = int.Parse(IdEmployeeCRUD.Text); Console.WriteLine("==============>>>>>>>>>>>>> ID UPDATE ROOM: " + $"{_idUpdate}"); Console.WriteLine("=================>>>>>>>>>>>>Name Employee update: " + $"{_nameEmp}"); Console.WriteLine("=================>>>>>>>>>>>>Email update: " + $"{_emailEmp}"); Console.WriteLine("=================>>>>>>>>>>>>password update: " + $"{_passwordEmp}"); Console.WriteLine("=================>>>>>>>>>>>>TypeRoleId Room update: " + $"{_typeRoleId}"); if (_passwordEmp.Trim().Length == 0) { Console.WriteLine("password is blank"); Employee employeeUpdate = new Employee() { Id = _idUpdate, Fullname = _nameEmp, Email = _emailEmp, RoleId = _typeRoleId, }; employeeViewModel.UpdateNotPass(employeeUpdate); } else { Employee employeeUpdate = new Employee() { Id = _idUpdate, Fullname = _nameEmp, Email = _emailEmp, RoleId = _typeRoleId, Password = hashed }; employeeViewModel.Update(employeeUpdate); } } break; case "Delete": messageError = "Information Update Employee not blank"; captionError = "Confirmation"; MessageBoxButton buttonDeleteEmp = MessageBoxButton.YesNo; MessageBoxImage iconDeleteEmp = MessageBoxImage.Question; if (IdEmployeeCRUD.Text.Length == 0) { messageError = "Employee not exist delete"; MessageBox.Show(messageError, captionError, buttonDeleteEmp, iconDeleteEmp); return; } else { int _idDelete = (EmployeesGrid.SelectedItem as Employee).Id; Console.WriteLine("=================>>>>>>>>>>>>> id delete: " + $"{_idDelete}"); string message = "Are you sure?"; string caption = "Confirmation"; MessageBoxButton buttons = MessageBoxButton.YesNo; MessageBoxImage icon = MessageBoxImage.Question; if (MessageBox.Show(message, caption, buttons, icon) == MessageBoxResult.Yes) { employeeViewModel.UpdateIsDeleted(_idDelete); LoadContent(); } else { // Cancel code here } } break; } }