Пример #1
0
        //MAIN METHODS

        public int CreateEmployee(EmployeeCreateRequest req)
        {
            using (SqlConnection con = new SqlConnection(connectionString))
            {
                try
                {
                    con.Open();

                    SqlCommand cmd = con.CreateCommand();
                    cmd.CommandText = "Post_Employee";
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@FirstName", req.FirstName);
                    cmd.Parameters.AddWithValue("@LastName", req.LastName);
                    cmd.Parameters.AddWithValue("@PhoneNumber", req.PhoneNumber);
                    cmd.Parameters.AddWithValue("@Zipcode", req.Zipcode);
                    cmd.Parameters.AddWithValue("@HireDate", req.HireDate);
                    cmd.Parameters.AddWithValue("@Id", SqlDbType.Int).Direction = ParameterDirection.Output;

                    cmd.ExecuteNonQuery();

                    int id = (int)cmd.Parameters["@Id"].Value;
                    return(id);
                }
                catch (SqlException ex) when(ex.Number == 2627)
                {
                    throw;
                }
            }
        }
Пример #2
0
        public async Task <Guid> Create(EmployeeCreateRequest request)
        {
            var employee = EmployeeAggregate.CreateFromRequest(request);

            await _repo.Add(employee);

            return(employee.Id);
        }
Пример #3
0
 /// <summary>Создание работника</summary>
 /// <param name="request">Запрос на создание работника</param>
 /// <returns>Новый работника</returns>
 public static EmployeeAggregate CreateFromRequest(EmployeeCreateRequest request)
 {
     return(new EmployeeAggregate()
     {
         Id = Guid.NewGuid(),
         UserId = request.UserId,
         IsDeleted = false,
     });
 }
Пример #4
0
        /// <summary>Запрос на создание случайного работника</summary>
        public static EmployeeCreateRequest CreateRandomEmployeeCreateRequest()
        {
            var request = new EmployeeCreateRequest()
            {
                UserId = Guid.NewGuid(),
            };

            return(request);
        }
Пример #5
0
        public IActionResult CreateEmployee(EmployeeCreateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _employeeRepository.CreateEmployee(request);
            return(Ok());
        }
Пример #6
0
        public async Task <bool> Create(EmployeeCreateRequest request)
        {
            var json        = JsonConvert.SerializeObject(request);
            var httpContent = new StringContent(json, Encoding.UTF8, "application/json");
            var client      = _httpClientFactory.CreateClient();

            client.BaseAddress = new Uri(_configuration["BaseAddress"]);
            var response = await client.PostAsync($"/api/Employee/Create", httpContent);

            return(response.IsSuccessStatusCode);
        }
Пример #7
0
        public async Task <IActionResult> Create([FromBody] EmployeeCreateRequest request)
        {
            var MaNV = await _manageEmployeeService.Create(request);

            if (MaNV == 0)
            {
                return(BadRequest());
            }
            var nhanvien = await _manageEmployeeService.GetById(MaNV);

            return(CreatedAtAction(nameof(GetById), new { id = MaNV }, nhanvien));
        }
Пример #8
0
        public async Task <IActionResult> Create(EmployeeCreateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var result = await _employeeApiClient.Create(request);

            if (result)
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(View(request));
        }
Пример #9
0
        protected void btnSubmitNew_Click(object sender, EventArgs e)
        {
            var newEmployee = new EmployeeCreateRequest();

            newEmployee.FirstName   = txtFirstName.Text;
            newEmployee.LastName    = txtLastName.Text;
            newEmployee.PhoneNumber = "(" + txtPhoneNumber.Text.Substring(0, 3) + ") " + txtPhoneNumber.Text.Substring(3, 3) + "-" + txtPhoneNumber.Text.Substring(6, 4);
            newEmployee.Zipcode     = txtZipcode.Text;
            newEmployee.HireDate    = txtHireDate.Text;
            int newId = CreateEmployee(newEmployee);

            GetAllEmployees();
            ClearTextBoxes(Page);
        }
Пример #10
0
        //create employee
        /// <summary>
        /// entity to add: Employee
        /// </summary>
        /// <param name="employeeCreateRequest"></param>
        /// <returns></returns>
        public static Employee MapFromEmployeeCreateRequestToEmployee(EmployeeCreateRequest employeeCreateRequest)
        {
            Employee employee = new Employee
            {
                Name         = employeeCreateRequest.Name,
                Age          = employeeCreateRequest.Age,
                PhoneNumber  = employeeCreateRequest.PhoneNumber,
                DepartmentId = employeeCreateRequest.DepartmentId,
                PositionId   = employeeCreateRequest.PositionId,

                CreatedAt = DateTime.UtcNow
            };

            return(employee);
        }
Пример #11
0
        public async Task <int> Create(EmployeeCreateRequest request)
        {
            var nhanvien = new NhanVien()
            {
                TenNv    = request.TenNv,
                GioiTinh = request.GioiTinh,
                ChucVu   = request.ChucVu,
                MaPb     = request.MaPb,
                CMND     = request.CMND,
                NgaySinh = request.NgaySinh,
            };

            _context.NhanViens.Add(nhanvien);
            await _context.SaveChangesAsync();

            return(nhanvien.MaNV);
        }
Пример #12
0
        public async Task <IActionResult> Create([FromBody] EmployeeCreateRequest requestModel)
        {
            //if (!ModelState.IsValid)
            //{
            //    logger.Here().Warning("Created employee failed. Model is not valid");
            //    return BadRequest(ModelState);
            //}

            //map to entity
            Employee employee = EmployeeMapper.MapFromEmployeeCreateRequestToEmployee(requestModel);

            db.Employees.Add(employee);
            await db.SaveChangesAsync();

            logger.Here().Information("Created employee successfully");

            return(CreatedAtRoute("GetEmployeeById", new { id = employee.EmployeeId }, null));
        }
Пример #13
0
        public async Task <IActionResult> Create([FromBody] EmployeeCreateRequest request)
        {
            var id = await _manager.Create(request);

            return(Ok(id));
        }