public IHttpActionResult Create([FromBody] CreateEmployee command) { command.EmployeeId = Guid.NewGuid(); _employeeServices.CreateEmployee(command.EmployeeId, command.Name, command.Email); return(Ok()); }
public String Post(String path, CreateEmployee createEmployee) { return(restClient() .Execute <Employees>(new RestRequest(path, Method.POST) .AddJsonBody(JsonConvert.SerializeObject(createEmployee))) .Content); }
public Employee CreateEmployee(CreateEmployee employee) { entity.Employee entity = mapper.Map <entity.Employee>(employee); unitOfWork.EmployeeRepository.Add(entity); unitOfWork.Commit(); return(mapper.Map <dto.Employee>(entity)); }
public IActionResult Create(CreateEmployee model) { if (ModelState.IsValid) { //1. get root //2. create folder path //3. filename path //4. copy image to folder step 2 var folderPath = Path.Combine(webHostEnvironment.WebRootPath, "images"); var filename = model.Avatar.FileName; var filePath = Path.Combine(folderPath, filename); using (var fs = new FileStream(filePath, FileMode.Create)) { model.Avatar.CopyTo(fs); } var employee = new Employee() { Age = model.Age, AvatarPath = $"~/images/{filename}", Code = model.Code, Email = model.Email, Firstname = model.Firstname, Lastname = model.Lastname }; if (employeeService.Create(employee)) { return(RedirectToAction("Index")); } } return(View(model)); }
public void CreateEmployee_Action_Fails() { // Arrange var employeeDto = TestHelper.EmployeeDto(); GenericServiceResponse <bool> fakeResponse = null; mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable(); mockClientServicesProvider.Setup(x => x.EmployeeService.CreateEmployee(employeeDto)).Returns(fakeResponse).Verifiable(); var viewModel = new GenericViewModel(); var action = new CreateEmployee <GenericViewModel>(mockClientServicesProvider.Object) { OnComplete = model => viewModel = model }; // Act var result = action.Invoke(employeeDto); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(GenericViewModel)); Assert.IsNotNull(result.Notifications); Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection)); Assert.IsTrue(result.Notifications.Count() == 1); Assert.IsTrue(result.HasErrors); Assert.IsNotNull(result.Success); Assert.IsInstanceOfType(result.Success, typeof(bool)); Assert.IsFalse(result.Success); }
public void TestInitialize() { this.dbStub = new HatchlingCompanyDbContext(Effort.DbConnectionFactory.CreateTransient()); this.writerStub = new Mock <IWriter>(); this.mapperStub = new Mock <IMapper>(); this.createEmployeeService = new CreateEmployee(dbStub, writerStub.Object, mapperStub.Object); }
public IActionResult Create(CreateEmployee model) { var requestUrl = client.CreateRequestUri(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Employee")); var response = client.PostAsync(requestUrl, model); return(this.RedirectToAction("Index", "Home", new { id = model.CompanyId })); }
public void WhenUserSendThePostRequestWithAnd_(string name, string salary, string age) { CreateEmployee createEmployee = new CreateEmployee(name, salary, age); Dictionary <string, string> dict = new Dictionary <string, string>(); dict.Add("Accpet", "application/json"); restResponse = HttpClientHelper.PerformPostRequest(requestUrl, new StringContent(createEmployee.GetCreateEmployeePayload(), Encoding.UTF8, "application/json"), dict); }
public async Task <IActionResult> NewEmployee() { var model = new CreateEmployee { }; ViewBag.Areas = new SelectList(await _areaRepository.GetAllAreas(), "IdArea", "Nombre"); return(View("NewEmployee", model)); }
public static CreateEmployee createNewUser(String name, Int32 salary, byte age) { CreateEmployee createEmployee = new CreateEmployee(); createEmployee.age = age; createEmployee.name = name; createEmployee.salary = salary; return(createEmployee); }
public virtual void SetUp() { deleteEmployee = A.Fake <DeleteEmployee>(); createEmployee = A.Fake <CreateEmployee>(); queryFactory = A.Fake <IQueryFactory>(); sut = new EmployeesController(queryFactory, createEmployee, deleteEmployee); }
public async Task <IActionResult> Post() { var command = new CreateEmployee { Name = $"Diminic-{DateTime.Now.ToLongDateString()}" }; await _mediator.Send(command); return(Ok()); }
public void Run() { IExecutable command = null; string line = Console.ReadLine(); while (line != "end") { string[] tokens = line.Split(); switch (tokens[0]) { case "create-company": command = new CreateCompany(db, tokens[1], tokens[2], tokens[3], decimal.Parse(tokens[4])); break; case "create-employee": string departmentName = null; if (tokens.Length > 5) { departmentName = tokens[5]; } command = new CreateEmployee(db, tokens[1], tokens[2], tokens[3], tokens[4], departmentName); break; case "create-department": string mainDepartmentName = null; if (tokens.Length > 5) { mainDepartmentName = tokens[5]; } command = new CreateDepartment(db, tokens[1], tokens[2], tokens[3], tokens[4], mainDepartmentName); break; case "pay-salaries": command = new PaySalaries(db, tokens[1]); break; case "show-employees": command = new ShowEmployees(db, tokens[1]); break; default: throw new ArgumentException("Unknoun command"); } try { Console.Write(command.Execute()); } catch (Exception e) { Console.WriteLine(e.Message); } finally { line = Console.ReadLine(); } } }
internal static Entities.Employee MapToEntity(CreateEmployee employee) { return(new Entities.Employee { SSN = employee.SSN, FirstName = employee.FirstName, LastName = employee.LastName, PhoneNumber = employee.PhoneNumber, EmailAddress = employee.EmailAddress }); }
public async Task <IActionResult> CreateAsync([FromBody] CreateEmployee request, CancellationToken cancellationToken) { var employee = new Employee(request.Name, request.DepartmentId); _employeeRepository.Add(employee); await _employeeRepository.UnitOfWork.SaveChangesAsync(cancellationToken); var vm = _mapper.Map <ViewEmployee>(employee); return(CreatedAtAction(nameof(GetAsync), new { id = vm.Id }, vm)); }
public async Task HandleAsync_Should_Throw_An_Exception_When_Employee_Year_Of_Birth_Is_Not_Within_The_Range() { //ARRANGE var command = new CreateEmployee(Guid.NewGuid(), "No Avatar", "Testowy Testo", Position.Grabarz, 2010); //ACT var exception = await Record.ExceptionAsync(async() => await Act(command)); //ASSERT exception.ShouldNotBeNull(); exception.ShouldBeAssignableTo <WrongDateException>(); }
public IActionResult AddEmployee([FromBody] CreateEmployee createEmployeeModel) { try { _employeeDataManager.AddEmployee(createEmployeeModel); return(new OkResult()); } catch { return(new BadRequestResult()); } }
private void btnAddEmployee_Click(object sender, EventArgs e) { EmployeeForm form = new EmployeeForm(); var listofEmployees = managementService.GetEmployees(0, 0).Select(x => new ManagerComboBoxItem(x.Name + " " + x.LastName + "(" + x.Id + ")", x.Id)).ToList(); form.comboManager.Items.AddRange(listofEmployees.ToArray()); if (DialogResult.OK == form.ShowDialog(this)) { var managerText = form.comboManager.Text; var manager = listofEmployees.Where(t => t.ToString() == managerText).SingleOrDefault(); CreateEmployee createEmployee = new CreateEmployee(form.textName.Text, form.textLastname.Text, form.textEmail.Text, manager == null ? 0 : (int)manager.Value); var project = managementService.CreateEmployee(createEmployee); UpdateGridEmployees(); } }
/// <summary> /// Skapa en anställd /// </summary> /// <returns>Den skapade anställda</returns> public EmployeeResponse Post(CreateEmployee request) { if (!DepartmentRepository.GetDepartments().Any(x => x.Id == request.DepartmentId)) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(null); } int createdEmployeeId = EmployeeRepository.CreateEmployee(request.FirstName, request.LastName, request.Title, request.DepartmentId); return(new EmployeeResponse { Employee = EmployeeRepository.GetEmployee(createdEmployeeId).ToDto() }); }
public async Task HandleAsync_Should_Throw_An_Exception_When_Employee_With_Given_Id_Already_Exists() { //ARRANGE var command = new CreateEmployee(Guid.NewGuid(), "No Avatar", "Testowy Testo", Position.Grabarz, 1980); var employee = new Employee(command.Id, "No Avatar", "Testowy Testo", Position.Grabarz, 1980); _repository.GetAsync(command.Id).Returns(employee); //ACT var exception = await Record.ExceptionAsync(async() => await Act(command)); //ASSERT exception.ShouldNotBeNull(); exception.ShouldBeAssignableTo <EmployeeAlreadyExistException>(); }
public async Task HandleAsync_Should_Create_Employee_With_Given_Data_Using_Repository() { var command = new CreateEmployee(Guid.NewGuid(), "No Avatar", "Testowy Testo", Position.Grabarz, 1980); await Act(command); await _repository .Received(1) .AddAsync(Arg.Is <Employee>(e => e.Id == command.Id && e.Name == command.Name && e.Avatar == command.Avatar && e.Position == command.Position && e.YearOfBirth == command.YearOfBirth)); }
public ActionResult Create([Bind(Include = "EmployeeID,Username,Email,FullName,Password,ComfirmPassword,JoinDate,Position,Team,Security")] CreateEmployee createEmployee) { if (ModelState.IsValid) { var employee = createEmployee.ToEmployee(); employee.Status = Status.Active; db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(createEmployee)); }
public async Task PostEmployeeShouldReturnOk() { var employee = new CreateEmployee { SSN = "test1", FirstName = "Andy", LastName = "Andersen", EmailAddress = "*****@*****.**", PhoneNumber = "123456" }; var content = new StringContent(JsonConvert.SerializeObject(employee), Encoding.UTF8, "application/json"); var response = await client.PostAsync("v1/employees", content).ConfigureAwait(false); Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
public void AddEmployee(CreateEmployee createEmployeeModel) { using (var dbContext = new EmployeeDBEntities(_connectionString)) { dbContext.Employees.Add(new Employee() { DateJoined = createEmployeeModel.DateJoined, EmployeeNumber = createEmployeeModel.EmployeeNumber, Extension = createEmployeeModel.Extension, FirstName = createEmployeeModel.FirstName, LastName = createEmployeeModel.LastName, RoleID = createEmployeeModel.RoleId }); dbContext.SaveChanges(); } }
public EmployeeDto Insert(CreateEmployee employee) { var person = new Employee() { FirstName = employee.FirstName, LastName = employee.LastName, MiddleName = employee.MiddleName, Email = employee.Email, MobilePhone = employee.MobilePhone, State = employee.State }; _repository.Add(person); _repository.SaveChanges(); return(_mapper.Map <Employee, EmployeeDto>(person)); }
public void WhenICreateARequestBoydWithFollowingData(Table table) { employee = table.CreateInstance <CreateEmployee>(); var obj = new CreateEmployee() { Age = employee.Age, Name = employee.Name, Salary = employee.Salary }; JsonSerializer serializer = new JsonSerializer(); jsonBody = serializer.Serialize(obj); }
public async Task <IActionResult> SaveEmployee(CreateEmployee createEmployee) { try { if (ModelState.IsValid) { await _empleadoRepository.CreateEmployee(_mapper.Map <Empleado>(createEmployee)); return(RedirectToAction(nameof(Index))); } } catch (Exception) { return(BadRequest()); } return(View("NewEmployee", createEmployee)); }
public IActionResult CreateEmployee([FromBody] CreateEmployee employee) { if (!ModelState.IsValid) { return(BadRequest()); } var employeeEntity = Mapper.Map <Employee>(employee); _repo.AddEmployee(employeeEntity); if (!_repo.Save()) { throw new Exception("Creating an author failed on save."); } var employeeToReturn = _repo.GetEmployee(employeeEntity.EmployeeGuid); return(Created("getEmployee", new { employeeGuid = employeeToReturn.EmployeeGuid })); }
static void Main(string[] args) { var config = new ConfigurationBuilder() .AddEnvironmentVariables() .Build(); var services = new ServiceCollection(); var bus = new GsBus(new GsBusConfig { HostName = config["RmqHostName"], UserName = config["RmqUserName"], Password = config["RmqPassword"], VirtualHost = config["RmqVHost"], SerializerType = SerializerType.Json //SendOnly = false }, services); bus.Connect(); Console.WriteLine("Publisher is started. Press any key to send message or q to exit!"); while (Console.ReadKey().Key != ConsoleKey.Q) { var id = Guid.NewGuid(); var message = new CreateEmployee { Id = id, Name = $"User Name is {id}", Address = $"Address for user {id}" }; var header = new Dictionary <string, object> { ["tenantId"] = "d1cfef8f-3a6e-44e8-a5ed-34a34230e2ef" }; bus.Send(header, message); Console.WriteLine($"Message is sent:\n {JsonConvert.SerializeObject(message, Formatting.Indented)}"); } Console.ReadKey(); }
public async Task <int> Add(CreateEmployee command) { var newEmployee = new Entities.Employee { FirstName = command.Employee.FirstName, LastName = command.Employee.LastName, Dependents = command.Dependents.Select(d => new Entities.Person { FirstName = d.FirstName, LastName = d.LastName }).ToList() }; db.Add(newEmployee); await db.SaveChangesAsync(); return(newEmployee.Id); }
public async Task <IActionResult> Post([FromBody] CreateEmployee employee) { if (!ModelState.IsValid) { var message = string.Join(", ", ModelState.Values.SelectMany(m => m.Errors).Select(m => m.ErrorMessage)); return(BadRequest(message)); } var entity = EmployeesMapper.MapToEntity(employee); employeeService.Create(entity); var createdEmployee = EmployeesMapper.MapToApiModel(entity); await humanusResursus.SendWelcomeEmailAsync(createdEmployee.Id); return(Ok(createdEmployee)); }
protected Employee Seed(CreateEmployee command) { // make sure entity does not already exist var employee = QueryProcessor.Execute(new EmployeeByPersonId(command.PersonId)); if (employee != null) return employee; _createEmployee.Handle(command); _unitOfWork.SaveChanges(); return command.CreatedEmployee; }