Exemple #1
0
        public IActionResult CreateEmployee([FromBody] NewEmployeeForm employeeForm)
        {
            // Create a new employee Form
            var employee = employeeForm.NewEmployee;
            var res      = new BaseResponse();

            try
            {
                // Send the employee body to the manager
                var createdUser = manager.CreateEmployee(employeeForm.NewEmployee);
                if (createdUser)
                {
                    // Send a 200 back + the full employee data
                    res.Code = 200;
                    res.HasBeenSuccessful = true;
                    return(Ok(res));
                }
                // Send a 401, something went wrong
                res.Code = 401;
                res.HasBeenSuccessful = false;
                return(Ok(res));
            }
            catch (Exception e)
            {
                // Send a 501, something went wrong internally
                Console.WriteLine(e.Message);
                res.Code = 501;
                res.HasBeenSuccessful = false;

                return(Ok(res));
            }
        }
 public IActionResult Create(EmployeeViewModel Employee)
 {
     if (ModelState.IsValid)
     {
         string update = _EmployeeManager.CreateEmployee(Employee);
         return(RedirectToAction(nameof(Index)));
     }
     ViewBag.ManagerList    = new SelectList(Manager, "Value", "Text");
     ViewBag.DepartmentList = new SelectList(Manager, "Value", "Text");
     return(View(Employee));
 }
Exemple #3
0
        /// <summary>
        /// Alissa Duffy
        /// Updated: 2017/04/24
        ///
        /// Post Employee Views/
        /// Standardized Methods.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPost_Click(object sender, RoutedEventArgs e)
        {
            decimal parsedSalary;
            bool    shouldPost = true;

            if (0 > cboUserID.SelectedIndex)
            {
                shouldPost = false;
                MessageBox.Show("Select a user to assign to role");
            }
            if (!Decimal.TryParse(txtSalary.Text, out parsedSalary))
            {
                shouldPost = false;
                MessageBox.Show("Salary needs a decimal");
            }
            if (null == dpBirthDatePicker.SelectedDate)
            {
                shouldPost = false;
            }
            if (shouldPost)
            {
                if (inAddMode)
                {
                    try
                    {
                        _employeeManager.CreateEmployee(new Employee()
                        {
                            Active      = (bool)chkActive.IsChecked,
                            DateOfBirth = (DateTime)dpBirthDatePicker.SelectedDate,
                            Salary      = parsedSalary,
                            UserId      = _userList[cboUserID.SelectedIndex].UserId
                        });
                        MessageBox.Show("Employee Added");
                        this.Close();
                    }
                    catch (System.Data.SqlClient.SqlException ex)
                    {
                        if (2627 == ex.Number)
                        {
                            MessageBox.Show("Unique key constraint violated");
                        }
                        else
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }
        public async Task <IActionResult> CreateEmployee(AddEmployeeDto model)
        {
            try
            {
                var employee = _mapper.Map <Employee>(model);
                if (!await _manager.CreateEmployee(employee))
                {
                    return(Ok(new JsonMessageResult("创建失败!", 0, 0)));
                }

                return(CreatedAtAction(nameof(GetEmployee), new { employee.Id }, employee));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(Ok(new JsonMessageResult(e.Message, 0, 0)));
            }
        }
Exemple #5
0
 public ActionResult PostHotel([FromBody] EmployeeViewModel employee)
 {
     return(StatusCode(201, _EmployeeManager.CreateEmployee(employee)));
 }
        public async Task <IActionResult> CreateUser([FromBody] EmployeeDTO request)
        {
            var response = await _employeeManager.CreateEmployee(request);

            return(Ok(response));
        }