public async Task <bool> AddEmployee(NewEmployeeDTO newEmployee)
        {
            Random rnd     = new Random();
            int    newCode = rnd.Next(1, 10000000);
            // Take a employee object
            // call the employee repository passing in the employee object
            // return true or false depending on whether the record was successfully added to the database
            Employee databaseEmployee = new Employee()
            {
                FullName       = newEmployee.FullName,
                Position       = newEmployee.Position,
                OfficeLocation = newEmployee.OfficeLocation,
                EmpCode        = newCode,
                Department     = newEmployee.Department,
                DepartmentId   = newEmployee.DepartmentId
            };

            _employeeRepository.AddEmployeeToDatabase(databaseEmployee);
            int results = _employeeRepository.SaveChanges();

            if (results == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        public HttpResponseMessage AddCoworkerEmployee(NewEmployeeDTO person)
        {
            Claims claims = new Claims().Values();
            Guid   personIntegrationCode = Guid.NewGuid();

            try
            {
                if (ModelState.IsValid)
                {
                    var command    = new AddPersonEmployeeCommand();
                    var employeeId = Guid.NewGuid();
                    command.IntegrationCode           = employeeId;
                    command.Name                      = person.Name;
                    command.PhoneNumber               = person.SmartPhoneNumber;
                    command.CreatedBy                 = claims.userSystemId;
                    command.Email                     = person.Email;
                    command.SecundaryEmail            = person.Email;
                    command.EnrollmentIP              = HttpContext.Current.Request.UserHostAddress;
                    command.PersonIntegrationFatherId = person.CompanyIntegrationCode; // todo: eliminar o campo CompanyIntegrationCode e usar apenas o IntegrationCode
                    command.UserProfileId             = (GeneralEnumerators.EnumUserProfile)person.UserProfileId;
                    command.PersonOriginType          = GeneralEnumerators.EnumPersonOriginType.IntegracaoAPIExterna;
                    command.SkinId                    = 3;
                    this.bus.Send(command);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, personIntegrationCode));
            }
            catch (System.Exception e)
            {
                LogManager.Error("Erro ao Add Empresa Coworker", e);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }
        public async Task <IActionResult> Add([FromBody] NewEmployeeDTO newEmployee)
        {
            // call into service to add the employee
            // depending on result return a result to the user
            if (!ModelState.IsValid)
            {
                return(BadRequest(401));
            }

            var result = await _employeeService.AddEmployee(newEmployee);

            return(Ok(result));
        }
 public IActionResult Create([FromHeader] string authorizationUsername, [FromBody] NewEmployeeDTO model)
 {
     try
     {
         this.authHelper.TryGetEmployee(authorizationUsername);
         var employee = this.employeeService.Create(model);
         return(Created("post", employee));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Exemple #5
0
        /// <summary>
        /// Creae an employee
        /// </summary>
        /// <param name="model">Data of the employee to be created.</param>
        /// <returns>Returns new employee or an appropriate error message.</returns>
        public EmployeeDTO Create(NewEmployeeDTO model)
        {
            var address  = this.addressService.GetBaseForTest(model.AddressId);
            var employee = new Employee();

            employee.FirstName = model.FirstName;
            employee.LastName  = model.LastName;
            employee.Email     = model.Email;
            employee.AddressId = model.AddressId;
            employee.CreatedOn = DateTime.UtcNow;
            address.Employees.Add(employee);
            this.dbContext.Employees.Add(employee);
            this.dbContext.SaveChanges();
            var createdEmployee = FindEmployee(employee.Id);

            return(new EmployeeDTO(createdEmployee));
        }