public async Task Should_delete_company() { // given CompanyUpdateModel companyUpdateModel = new CompanyUpdateModel(name: "Apple"); string request = JsonConvert.SerializeObject(companyUpdateModel); StringContent requestBody = new StringContent(request, Encoding.UTF8, "application/json"); await client.PostAsync("companies", requestBody); EmployeeUpdateModel employeeUpdateModel = new EmployeeUpdateModel(name: "Steve", salary: 100); string request2 = JsonConvert.SerializeObject(employeeUpdateModel); StringContent requestBody2 = new StringContent(request2, Encoding.UTF8, "application/json"); await client.PostAsync("companies/Apple/employees", requestBody2); // when await client.DeleteAsync("companies/Apple"); var response = await client.GetAsync("companies"); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); List <Company> actualEmployees = JsonConvert.DeserializeObject <List <Company> >(responseString); // then Assert.Equal(new List <Company>(), actualEmployees); }
public async Task Should_Change_Specified_Employee_In_Specified_Company_When_Patch_UpdateEmployee() { // given await testClient.DeleteAsync("companies/clear"); Company company1 = new Company("0", "Baymax"); Employee newEmployee = new Employee("0", "Jim", 10000); company1.Employees["0"] = newEmployee; string request1 = JsonConvert.SerializeObject(company1); StringContent requestBody1 = new StringContent(request1, Encoding.UTF8, "application/json"); await testClient.PostAsync("/companies", requestBody1); // when var employeeUpdateModel = new EmployeeUpdateModel("Jim", 12000); string request = JsonConvert.SerializeObject(employeeUpdateModel); StringContent requestBody = new StringContent(request, Encoding.UTF8, "application/json"); await testClient.PatchAsync("/companies/0/employees/0", requestBody); // then var getResponse = await testClient.GetAsync("companies/0"); var getResponseString = await getResponse.Content.ReadAsStringAsync(); var actualCompany = JsonConvert.DeserializeObject <Company>(getResponseString); var expectedEmployee = new Employee("0", "Jim", 12000); Assert.Equal(expectedEmployee, actualCompany.Employees["0"]); }
public async Task Should_Update_Employee_Info_When_Put() { // given var company = new UpdateModel("testcompany"); string request = JsonConvert.SerializeObject(company); var employee1 = new Employee("employeename1", 10000); string postRequest1 = JsonConvert.SerializeObject(employee1); StringContent postRequestBody1 = new StringContent(postRequest1, Encoding.UTF8, "application/json"); var employeeUpdateModel = new EmployeeUpdateModel("employeeputname", 5000); string putRequest = JsonConvert.SerializeObject(employeeUpdateModel); StringContent requestBody = new StringContent(request, Encoding.UTF8, "application/json"); StringContent putRequestBody = new StringContent(putRequest, Encoding.UTF8, "application/json"); // when await client.PostAsync("company", requestBody); await client.PostAsync("company/1", postRequestBody1); await client.PutAsync("company/1/employees/1", putRequestBody); var getResponse = await client.GetAsync("company/1/employees/1"); getResponse.EnsureSuccessStatusCode(); var responseString = await getResponse.Content.ReadAsStringAsync(); Employee actualEmployee = JsonConvert.DeserializeObject <Employee>(responseString); // then Assert.Equal(5000, actualEmployee.Salary); }
public async Task Should_change_employee_information() { // given CompanyUpdateModel companyUpdateModel = new CompanyUpdateModel(name: "Apple"); string request = JsonConvert.SerializeObject(companyUpdateModel); StringContent requestBody = new StringContent(request, Encoding.UTF8, "application/json"); await client.PostAsync("companies", requestBody); EmployeeUpdateModel employeeUpdateModel = new EmployeeUpdateModel(name: "Steve", salary: 100); string request2 = JsonConvert.SerializeObject(employeeUpdateModel); StringContent requestBody2 = new StringContent(request2, Encoding.UTF8, "application/json"); await client.PostAsync("companies/Apple/employees", requestBody2); // when EmployeeUpdateModel employeeUpdateModel3 = new EmployeeUpdateModel(name: "Jobs", salary: 200); string request3 = JsonConvert.SerializeObject(employeeUpdateModel3); StringContent requestBody3 = new StringContent(request3, Encoding.UTF8, "application/json"); var response = await client.PatchAsync("companies/Apple/employees/Steve", requestBody3); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); Employee actualEmployees = JsonConvert.DeserializeObject <Employee>(responseString); // then Assert.Equal(new Employee(name: "Jobs", salary: 200), actualEmployees); }
public IActionResult Put(uint empID, [FromBody] EmployeeUpdateModel emp) { db.OpenConnection(); try { string sqlStatementDesc = "UPDATE employee SET pin_number = @pinNumber, admin = @admin, first_name = @firstName, last_name = @lastName, email = @email, addr1 = @addr1, addr2 = @addr2, city = @city, state = @state, zip = @zip, phone = @phone WHERE emp_id = @empID"; MySqlCommand cmd = new MySqlCommand(sqlStatementDesc, db.Connection()); cmd.Parameters.Add(new MySqlParameter("pinNumber", emp.PinNumber)); cmd.Parameters.Add(new MySqlParameter("admin", emp.IsAdmin)); cmd.Parameters.Add(new MySqlParameter("firstName", emp.FirstName)); cmd.Parameters.Add(new MySqlParameter("lastName", emp.LastName)); cmd.Parameters.Add(new MySqlParameter("email", emp.Email)); cmd.Parameters.Add(new MySqlParameter("addr1", emp.Address1)); cmd.Parameters.Add(new MySqlParameter("addr2", emp.Address2)); cmd.Parameters.Add(new MySqlParameter("city", emp.City)); cmd.Parameters.Add(new MySqlParameter("state", emp.State)); cmd.Parameters.Add(new MySqlParameter("zip", emp.ZipCode)); cmd.Parameters.Add(new MySqlParameter("phone", emp.PhoneNumber)); cmd.Parameters.Add(new MySqlParameter("empID", empID)); MySqlDataReader reader = cmd.ExecuteReader(); reader.Read(); reader.Close(); } catch (Exception ex) { throw ex; } db.CloseConnnection(); Console.WriteLine("\nConnection closed."); return(Ok()); }
public async Task <IHttpActionResult> ApproveEmployee(int clientId, [FromBody] EmployeeUpdateModel model) { var userId = GetUserId(); var employee = await _employeeManager.ApproveEmployeeAsync(model, clientId, userId); return(Ok(employee)); }
public async Task <ActionResult> UpdateEmployee(EmployeeUpdateModel model) { if (ModelState.IsValid) { var user = await EmployeeManager.Users.FirstOrDefaultAsync(u => u.UserName == model.Username); user.FirstName = model.FirstName; user.LastName = model.LastName; user.PayRate = model.Payrate; user.OverTimeRate = model.OvertimeRate; user.TaxRate = model.TaxRate; user.PayMethod = model.PayMethod; user.PhoneNumber = model.Phone; user.Address = model.Address; var result = await EmployeeManager.UpdateAsync(user); if (result.Succeeded) { return(RedirectToAction("Index", "Admin", new { message = "Employee updated successfully." })); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
private void SetEmployeeValues(Employee employee, EmployeeUpdateModel modelItem) { employee.FirstName = modelItem.Firstname; employee.LastName = modelItem.Lastname; employee.DateOfBirth = modelItem.DateOfBirth; employee.JobTitle = modelItem.JobTitle; }
public async Task <IActionResult> Put(Guid id, EmployeeUpdateModel model) { var updatedEmployee = await _employeeService.UpdateAsync(id, model); var response = new Response(updatedEmployee); return(Ok(response)); }
public Employee UpdateEmployee(string companyId, string employeeId, EmployeeUpdateModel employeeUpdateModel) { var company = companies.GetCompanyByID(companyId); var employee = company.GetEmployeeById(employeeId); employee.Name = employeeUpdateModel.Name; employee.Salary = employeeUpdateModel.Salary; return(employee); }
public IActionResult Put([FromBody] EmployeeUpdateModel model) { var response = _commandBus.Execute <EmployeeCreateCommand, EmployeeCreateResponse>(new EmployeeCreateCommand { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email }); return(response.Succeeded ? Json("ok") : Json("error")); }
public async Task <Employee> UpdateEmployee(int id, EmployeeUpdateModel model) { var employee = await this.dbContext .Employees .Include(x => x.Garage) .FirstOrDefaultAsync(x => x.Id == id); employee.Name = model.Name; await this.dbContext.SaveChangesAsync(); return(employee); }
public async void Should_Delete_Employees_Before_Deleting_Company() { // given Company company = new Company("company_name_1"); string request = JsonConvert.SerializeObject(company); StringContent requestBody = new StringContent(request, Encoding.UTF8, "application/json"); Employee employee_1 = new Employee("Tom", 5000); string employeeRequest_1 = JsonConvert.SerializeObject(employee_1); StringContent employeeRequestBody_1 = new StringContent(employeeRequest_1, Encoding.UTF8, "application/json"); Employee employee_2 = new Employee("Jerry", 3000); string employeeRequest_2 = JsonConvert.SerializeObject(employee_2); StringContent employeeRequestBody_2 = new StringContent(employeeRequest_2, Encoding.UTF8, "application/json"); // when await client.PostAsync("company/companies", requestBody); string companyId = "company_1"; string employeeId = "employee_2"; EmployeeUpdateModel updateModel = new EmployeeUpdateModel("Fred", 10000); string updateRequest = JsonConvert.SerializeObject(updateModel); StringContent updateRequestBody = new StringContent(updateRequest, Encoding.UTF8, "application/json"); await client.PostAsync($"company/companies/{companyId}/employees", employeeRequestBody_1); await client.PostAsync($"company/companies/{companyId}/employees", employeeRequestBody_2); await client.DeleteAsync($"company/companies/{companyId}/employees"); var response = await client.GetAsync($"company/companies/{companyId}/employees"); // then response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); List <Employee> actualEmployees = JsonConvert.DeserializeObject <List <Employee> >(responseString); List <Employee> expectedEmployees = new List <Employee>(); Assert.Equal(expectedEmployees, actualEmployees); await client.DeleteAsync($"company/companies/{companyId}"); response = await client.GetAsync($"company/companies"); response.EnsureSuccessStatusCode(); responseString = await response.Content.ReadAsStringAsync(); List <Company> actualCompanies = JsonConvert.DeserializeObject <List <Company> >(responseString); List <Company> expectedCompanies = new List <Company>(); Assert.Equal(expectedCompanies, actualCompanies); }
public async Task <ActionResult <Employee> > AddEmployee(string companyName, EmployeeUpdateModel employeeUpdateModel) { var company = companies.FirstOrDefault(c => c.Name == companyName); if (company == null) { return(NotFound()); } var employee = new Employee(employeeUpdateModel.Name, employeeUpdateModel.Salary); company.Employees.Add(employee); return(Ok(employee)); }
public IActionResult Update(int employeeId, [FromBody] EmployeeUpdateModel model) { var employee = _mapper.Map <Employee>(model); try { _employeeService.Update(employee, employeeId); return(Ok()); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public ActionResult Post(EmployeeUpdateModel employeeModel) { if (ModelState.IsValid) { var employee = _empoyeeRepository.Get(employeeModel.Id); if (employee != null) { employee.FirstName = employeeModel.FirstName; employee.LastName = employeeModel.LastName; _empoyeeRepository.Update(employee); return(Ok()); } } return(BadRequest()); }
public static Employee EmployeMapWithEmployeeUpdateModel(EmployeeUpdateModel model) { Employee employee = new Employee(); employee.Id = model.id; employee.FirstName = model.firstName; employee.LastName = model.lastName; employee.UserId = model.userId; employee.EmailId = model.email; employee.DepartmentId = model.departmentId; employee.Gender = model.gender; employee.CityId = model.cityId; employee.CountryId = model.countryId; return(employee); }
public async Task <int> Execute(EmployeeUpdateModel employeeModel) { _logger.Information("Updating Employee"); try { var employee = _mapper.Map <Employee>(employeeModel); return(await _unitOfWork.Employees.UpdateAsync(employee)); } catch (Exception ex) { _logger.Error(ex, ex.Message, null); throw; } }
public async Task <ActionResult> Edit(EmployeeUpdateModel employee) { if (ModelState.IsValid) { bool isUpdated = await UserBAL.updateEmployee(employee); if (isUpdated) { ViewBag.Updated = "true"; } } ViewBag.DepartmentId = new SelectList(await DepartmentBAL.getDepartment(), "Id", "DepartmentName"); ViewBag.CountryId = new SelectList(entity.Countries, "Id", "CountryName"); ViewBag.CityId = new SelectList(entity.Cities, "Id", "CityName"); return(View(employee)); }
public async Task <EmployeeUpdateModel> UpdateAsync(EmployeeUpdateModel model, int clientId, int userId) { if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanAddEmployee)) { throw new Exception("User has not permission to perform this operation"); } if (model == null) { throw new ArgumentNullException(); } //check the employee shift extis or not var updateEmployeeShift = await _shiftHistroyManager.GetByEmployeeIdAsync(model.Id, clientId, userId); //This is used for update employee shift if (updateEmployeeShift == null || (updateEmployeeShift != null && updateEmployeeShift.ShiftId != model.ShiftId)) { if (updateEmployeeShift != null) { updateEmployeeShift.EndDate = DateTime.UtcNow; await _shiftHistroyManager.UpdateAsync(updateEmployeeShift, clientId, userId); } //then afte update employee new shift timing var addNewEmployeeShift = new ShiftHistoryModel(); addNewEmployeeShift.EmployeeId = model.Id; addNewEmployeeShift.ShiftId = model.ShiftId; addNewEmployeeShift.StartDate = DateTime.UtcNow; await _shiftHistroyManager.AddAsync(addNewEmployeeShift, clientId, userId); } var existingDataModel = await _employeeRepository.GetAsync(model.Id); if (existingDataModel == null) { throw new Exception("Employee does not exist which you trying to update"); } var employee = _employeeUpdateMapper.ConvertToDataModel(model); employee.UpdatedOn = DateTime.UtcNow; employee = await _employeeRepository.UpdateAsync(employee); return(_employeeUpdateMapper.ConvertToModel(employee)); }
public static EmployeeUpdateModel EmployeModelMapWithEmployeeUpdateModel(sp_GetEmployeeById_Result emp) { EmployeeUpdateModel employee = new EmployeeUpdateModel() { id = emp.Id, userId = emp.UserId, firstName = emp.FirstName, lastName = emp.LastName, email = emp.EmailId, departmentId = (long)emp.DepartmentId, gender = emp.Gender, cityId = (int)emp.CityId, countryId = (int)emp.CountryId }; return(employee); }
public IActionResult Post([FromBody] EmployeeUpdateModel emp) { // first, check if employee ID already exists /*if (DoesEmployeeExist(tester.EmpID)) * { * return StatusCode(400, "Employee ID already exists."); * }*/ try { db.OpenConnection(); string sqlStatementDesc = "SET SQL_MODE = '';" + "INSERT INTO employee (pin_number, admin, first_name, last_name, email, addr1, addr2, city, state, zip, phone) " + "VALUES (@pinNumber, @admin, @firstName, @lastName, @email, @addr1, @addr2, @city, @state, @zip, @phone)"; MySqlCommand cmd = new MySqlCommand(sqlStatementDesc, db.Connection()); cmd.Parameters.Add(new MySqlParameter("pinNumber", emp.PinNumber)); cmd.Parameters.Add(new MySqlParameter("admin", emp.IsAdmin)); cmd.Parameters.Add(new MySqlParameter("firstName", emp.FirstName)); cmd.Parameters.Add(new MySqlParameter("lastName", emp.LastName)); cmd.Parameters.Add(new MySqlParameter("email", emp.Email)); cmd.Parameters.Add(new MySqlParameter("addr1", emp.Address1)); cmd.Parameters.Add(new MySqlParameter("addr2", emp.Address2)); cmd.Parameters.Add(new MySqlParameter("city", emp.City)); cmd.Parameters.Add(new MySqlParameter("state", emp.State)); cmd.Parameters.Add(new MySqlParameter("zip", emp.ZipCode)); cmd.Parameters.Add(new MySqlParameter("phone", emp.PhoneNumber)); MySqlDataReader reader = cmd.ExecuteReader(); reader.Read(); reader.Close(); } catch (Exception ex) { return(Content(ex.Message)); } db.CloseConnnection(); Console.WriteLine("\nConnection closed."); return(Ok()); }
public ActionResult CreateEmployee(string username) { if (username == null) { EmployeeRegisterViewModel model = new EmployeeRegisterViewModel { LoggedUser = CurrentUser, //BaseViewModel LoggedCompany = CurrentCompany, //BaseViewModel LogoUrl = CurrentLogoUrl, //BaseViewModel HireDate = DateTime.Today }; return(View(model)); } var user = EmployeeManager.Users.FirstOrDefault(u => u.UserName == username); EmployeeUpdateModel employee = new EmployeeUpdateModel { LoggedUser = CurrentUser, //BaseViewModel LoggedCompany = CurrentCompany, //BaseViewModel LogoUrl = CurrentLogoUrl, //BaseViewModel Username = user.UserName, FirstName = user.FirstName, LastName = user.LastName, Payrate = user.PayRate, OvertimeRate = user.OverTimeRate, Phone = user.PhoneNumber, Address = user.Address, TaxRate = user.TaxRate, PayMethod = user.PayMethod, PayMethods = new List <PayMethod>() { PayMethod.Hour, PayMethod.Day, PayMethod.Month, PayMethod.Year } }; return(View("UpdateEmployee", employee)); }
public async Task <IActionResult> UpdateEmployee([FromBody] EmployeeUpdateModel employeeModel) { try { // TO DO this validation could still be moved to a filter attribute if (employeeModel == null) { _logger.Error("Employee object received is null."); return(BadRequest("Employee object is null")); } var data = await _updateEmployeeCommand.Execute(employeeModel); return(Ok(data)); } catch (Exception ex) { _logger.Error(ex, ex.Message, null); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async void Should_Update_Employee_By_Id() { // given Company company = new Company("company_name_1"); string request = JsonConvert.SerializeObject(company); StringContent requestBody = new StringContent(request, Encoding.UTF8, "application/json"); Employee employee_1 = new Employee("Tom", 5000); string employeeRequest_1 = JsonConvert.SerializeObject(employee_1); StringContent employeeRequestBody_1 = new StringContent(employeeRequest_1, Encoding.UTF8, "application/json"); Employee employee_2 = new Employee("Jerry", 3000); string employeeRequest_2 = JsonConvert.SerializeObject(employee_2); StringContent employeeRequestBody_2 = new StringContent(employeeRequest_2, Encoding.UTF8, "application/json"); // when await client.PostAsync("company/companies", requestBody); string companyId = "company_1"; string employeeId = "employee_2"; EmployeeUpdateModel updateModel = new EmployeeUpdateModel("Fred", 10000); string updateRequest = JsonConvert.SerializeObject(updateModel); StringContent updateRequestBody = new StringContent(updateRequest, Encoding.UTF8, "application/json"); await client.PostAsync($"company/companies/{companyId}/employees", employeeRequestBody_1); await client.PostAsync($"company/companies/{companyId}/employees", employeeRequestBody_2); var response = await client.PatchAsync($"company/companies/{companyId}/employees/{employeeId}", updateRequestBody); // then response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); Employee actualEmployee = JsonConvert.DeserializeObject <Employee>(responseString); employee_2.EmployeeID = "employee_2"; employee_2.Name = "Fred"; employee_2.Salary = 10000; Assert.Equal(employee_2, actualEmployee); }
public async Task <EmployeeUpdateModel> ApproveEmployeeAsync(EmployeeUpdateModel model, int clientId, int userId) { if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanAddEmployee)) { throw new Exception("User has not permission to perform this operation"); } if (model == null) { throw new ArgumentNullException(); } var existingemployee = await _employeeRepository.GetAsync(model.Id); if (existingemployee == null) { throw new Exception("Employee does not exist which you trying to approve"); } //this is using for the set the shift time var employeeApprove = new ShiftHistoryModel(); employeeApprove.EmployeeId = model.Id; employeeApprove.ShiftId = model.ShiftId; employeeApprove.StartDate = DateTime.UtcNow; await _shiftHistroyManager.AddAsync(employeeApprove, clientId, userId); //this is using for the approve the employee var employee = _employeeUpdateMapper.ConvertToDataModel(model); employee.UpdatedOn = DateTime.UtcNow; employee.Status = (int)EmployeeStatus.Active; employee.ApprovedBy = userId; employee = await _employeeRepository.ApproveEmployeeAsync(employee); return(_employeeUpdateMapper.ConvertToModel(employee)); }
public async Task <EmployeeResponseModel> UpdateAsync(Guid id, EmployeeUpdateModel model) { var newEmployee = _mapper.Map <Employee>(model); var updatedEmployee = await _employeeService.UpdateAsync(id, newEmployee); if (updatedEmployee.CanAccessTheSystem()) { if (await _accountService.Exists(updatedEmployee.Id)) { await _accountService.UpdateAsync(updatedEmployee); } else { await _accountService.CreateAsync(updatedEmployee); } } else { await _accountService.DeleteAsync(updatedEmployee.Id); } return(_mapper.Map <EmployeeResponseModel>(updatedEmployee)); }
public async Task <ActionResult> UpdateEmployee(string companyID, string employeeID, EmployeeUpdateModel employeeUpdateModel) { var employee = companies[companyID].Employees[employeeID]; employee.Name = employeeUpdateModel.Name is null ? employee.Name : employeeUpdateModel.Name; employee.Salary = employeeUpdateModel.Salary.HasValue ? employeeUpdateModel.Salary.Value : employee.Salary; return(Ok()); }
public async Task <ActionResult <Employee> > UpdateEmployee(string companyName, string employeeName, EmployeeUpdateModel employeeUpdateModel) { var company = companies.FirstOrDefault(c => c.Name == companyName); if (company == null) { return(NotFound()); } var employee = company.Employees.FirstOrDefault(employee => employee.Name == employeeName); if (employee == null) { return(NotFound()); } employee.Name = employeeUpdateModel.Name; employee.Salary = employeeUpdateModel.Salary; return(Ok(employee)); }
public async Task <ActionResult <int> > ChangeName(int id, [FromBody] EmployeeUpdateModel model) { var result = await this.employeeService.UpdateEmployee(id, model); return(Created(nameof(this.Create), result)); }