public IActionResult Post([FromBody] Employee employee)
        {
            var dbEmployee = Mapper.Map <DbEmployee>(employee);

            _employeesRepository.Add(dbEmployee);
            _employeesRepository.SaveChanges();

            return(CreatedAtAction("Get", new { id = dbEmployee.Id }, Mapper.Map <Employee>(dbEmployee)));
        }
        public async Task <ActionResult> PostEmployee([FromBody] Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _employeesRepository.Add(employee);

            return(CreatedAtAction("PostEmployee", new { id = employee.EmployeeId }, employee));
        }
Exemplo n.º 3
0
        public async Task <Employee> CreateEmployee()
        {
            var employee = new Employee(
                Guid.NewGuid(), "Davolio", "Nancy", "Sales Representative", DateTime.Parse("8.12.1948 00:00:00"),
                DateTime.Parse("1.05.1992 00:00:00"), "507 - 20th Ave. E.Apt. 2A", "Seattle", "98122", "USA"
                );
            await _employeeRepository.Add(employee);

            await _employeeRepository.UnitOfWork.Commit();

            return(employee);
        }
        public IHttpActionResult Create([FromBody] EmployeeCreateViewModel model)
        {
            if (model.StartDate > DateTime.Now || model.StartDate.Year != DateTime.Now.Year || model.StartDate.Month != DateTime.Now.Month)
            {
                ModelState.AddModelError("StartDate", "Date is not valid!");
            }
            if (!ModelState.IsValid)
            {
                return(Json(new { Success = false, Message = "Not valid data!", Data = ModelState.Keys.Select(k => k.Replace("model.", "")) }));
            }
            var result = _repository.Add(Mapper.Map <Employee>(model));

            if (!result)
            {
                return(Json(new { Success = false, Message = "Something went wrong!" }));
            }
            return(Json(new { Success = true, Message = "Employee successfully created!" }));
        }
Exemplo n.º 5
0
#pragma warning disable S4457 // Parameter validation in "async"/"await" methods should be wrapped
        public async Task <bool> AddEmployee(EmployeeDto model)
#pragma warning restore S4457 // Parameter validation in "async"/"await" methods should be wrapped
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            Employee employee = new Employee(model.IdNo, model.Name)
            {
                Address   = new Address(model.City, model.Line1, model.Line2),
                BirthDate = model.BirthDate,
            };

            await _repository.Add(employee);

            await _repository.Save();

            model.Id = employee.Id;
            _logger.LogInformation($"Employee {employee.Name} has been added.");
            return(true);
        }
Exemplo n.º 6
0
        public async Task <CommandResponse> Handle(EmployeeAddCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                return(request.CommandResponse);
            }

            var employee = new Employee(Guid.NewGuid(), request.FirstName, request.LastName, request.Title, request.BirthDate,
                                        request.HireDate, request.Address, request.City, request.PostalCode, request.Country);

            // Cretae Employee Event
            employee.Apply(new EmployeeAddEvent(employee.Id, employee.FirstName, employee.LastName, employee.Title, employee.BirthDate,
                                                employee.HireDate, employee.Address, employee.City));

            // save the Employee

            await _employeesRepository.Add(employee);

            // publish event

            await _eventStoreRepository.SaveAsync <Employee>(employee);

            return(await Commit(_employeesRepository.UnitOfWork));
        }
Exemplo n.º 7
0
 public void Add(Employee employee)
 {
     //TODO: regras de negócio, se tiver
     //Exemplo: enviar email para o RH com os dados do empregado adicionado
     repository.Add(employee);
 }
Exemplo n.º 8
0
 public IActionResult Post([FromBody] Employee employee)
 {
     _employeesRepository.Add(employee);
     return(Created($"/employees/{employee.Id}", employee));
 }