public static int InsertAlternative(EmployeeAddRequest model)
        {
            int empId = 0;

            Action <SqlParameterCollection> inputParamDelegate = delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@FirstName", model.FirstName);
                paramCollection.AddWithValue("@LastName", model.LastName);

                paramCollection.AddWithValue("@Email", model.Email);
                paramCollection.AddWithValue("@JobTitle", model.JobTitle);
                paramCollection.AddWithValue("@DOB", model.DOB);
                paramCollection.AddWithValue("@Salary", model.Salary);


                SqlParameter idParameter = new SqlParameter("@Id", System.Data.SqlDbType.Int);
                idParameter.Direction = System.Data.ParameterDirection.Output;

                paramCollection.Add(idParameter);
            };

            Action <SqlParameterCollection> returnParamDelegate = delegate(SqlParameterCollection paramCollection)
            {
                Int32.TryParse(paramCollection["@Id"].Value.ToString(), out empId);
            };

            DataProvider.ExecuteNonQuery(GetConnection
                                         , "dbo.Employees_Insert"
                                         , inputParamDelegate
                                         , returnParamDelegate);


            return(empId);
        }
Exemplo n.º 2
0
        public int AddEmployee(EmployeeAddRequest model)
        {
            using (var conn = Getconn())
            {
                int id = 0;
                if (conn.State == ConnectionState.Open)
                {
                    using (var cmd = new SqlCommand("Employee_Create", conn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.AddWithValue("@first_name", model.First_Name);
                        cmd.Parameters.AddWithValue("@last_name", model.Last_Name);
                        cmd.Parameters.AddWithValue("@gender", model.Gender);
                        cmd.Parameters.AddWithValue("@salary", model.Salary);
                        cmd.Parameters.AddWithValue("@position", model.Position);
                        cmd.Parameters.AddWithValue("@department_id", model.Department_Id);
                        cmd.Parameters.AddWithValue("@employee_id", SqlDbType.Int).Direction = ParameterDirection.Output;

                        cmd.ExecuteNonQuery();
                        id = (int)cmd.Parameters["@employee_id"].Value;
                    }
                }
                else
                {
                    BadConn();
                }
                return(id);
            }
        }
Exemplo n.º 3
0
        public async Task <EmployeeDto> AddEmployeeAsync(EmployeeAddRequest employeeAddRequest)
        {
            var position = await _positionRepository.GetByIdAsync(employeeAddRequest.PositionId);

            var employee = new Employee()
            {
                Name          = employeeAddRequest.Name,
                Surname       = employeeAddRequest.Surname,
                CreatedAtUtc  = _dateService.GetDateTimeUtcNow(),
                ModifiedAtUtc = _dateService.GetDateTimeUtcNow(),
                Positions     = new List <EmployeePosition>()
                {
                    new EmployeePosition
                    {
                        HiredAt    = employeeAddRequest.HiredAt,
                        LeftAt     = employeeAddRequest.LeftAt,
                        PositionId = employeeAddRequest.PositionId,
                        Title      = position.Title,
                        Salary     = employeeAddRequest.Salary
                    }
                }
            };

            await _employeeRepository.InsertAsync(employee);

            return(_mapper.Map <Employee, EmployeeDto>(employee));
        }
        public bool Add(EmployeeAddRequest employee)
        {
            try
            {
                SqlConnection sqlconn = new SqlConnection(connectionString);
                SqlCommand    sqlComm = new SqlCommand("addEmployee");
                sqlconn.Open();
                sqlComm.Connection  = sqlconn;
                sqlComm.CommandType = CommandType.StoredProcedure;
                sqlComm.Parameters.AddWithValue("@empType", employee.EmpType);
                sqlComm.Parameters.AddWithValue("@firstName", employee.FirstName);
                sqlComm.Parameters.AddWithValue("@middleName", employee.MiddleName);
                sqlComm.Parameters.AddWithValue("@lastName", employee.LastName);
                sqlComm.Parameters.AddWithValue("@email", employee.Email);
                sqlComm.Parameters.AddWithValue("@salary", employee.Salary);
                sqlComm.Parameters.AddWithValue("@username", employee.Username);
                sqlComm.Parameters.AddWithValue("@locationId", employee.Location);
                sqlComm.Parameters.AddWithValue("@project", employee.Project);
                sqlComm.ExecuteNonQuery();

                SqlCommand sqlCommand = new SqlCommand("addOtherEmployeeDetails");
                sqlCommand.Connection  = sqlconn;
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.AddWithValue("@manager", employee.Manager);
                sqlCommand.Parameters.AddWithValue("@email", employee.Email);

                sqlCommand.ExecuteNonQuery();
                sqlconn.Close();
                return(true);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds emplyee to database
        /// </summary>
        /// <param name="addRequest">Employee add request</param>
        public async Task AddEmployee(EmployeeAddRequest addRequest)
        {
            var newShopUser = Mapper.Map <ShopEmployee>(addRequest);
            await ShopEmployeeRepo.CreateAsync(newShopUser);

            await ShopEmployeeRepo.SaveChangesAsync();
        }
Exemplo n.º 6
0
 public IHttpActionResult Add(EmployeeAddRequest model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     else
     {
         return(Ok("Employee " + svc.AddEmployee(model) + " has been added"));
     }
 }
Exemplo n.º 7
0
 public bool Add(EmployeeAddRequest employee)
 {
     try
     {
         return(_employeeRepository.Add(employee));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 8
0
        public int AddEmployee(EmployeeAddRequest model)
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();

                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = "dbo.Employee_Insert";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@FirstName", model.FirstName);
                cmd.Parameters.AddWithValue("@LastName", model.LastName);
                cmd.Parameters.AddWithValue("@HiredDate", model.HiredDate);

                DataTable taskTable = null;

                if (model.Tasks.Count > 0)
                {
                    taskTable = new DataTable();
                    taskTable.Columns.Add("Name", typeof(string));
                    taskTable.Columns.Add("StartTime", typeof(DateTime));
                    taskTable.Columns.Add("Deadline", typeof(DateTime));

                    foreach (var item in model.Tasks)
                    {
                        DataRow dr = taskTable.NewRow();
                        dr[0] = item.Name;
                        dr[1] = item.StartTime;
                        dr[2] = item.Deadline;
                        taskTable.Rows.Add(dr);
                    }
                }
                cmd.Parameters.AddWithValue("@Tasks", taskTable);



                SqlParameter idParam = cmd.Parameters.Add("@Id", SqlDbType.Int);
                idParam.Direction = ParameterDirection.Output;

                cmd.ExecuteNonQuery();

                conn.Close();

                return((int)idParam.Value);
            }
        }
        public EmployeeResponse Create(EmployeeAddRequest request)
        {
            using (var adapter = DataAccessAdapterFactory.NewDataAccessAdapter())
            {
                OnBeforeEmployeeAddRequest(adapter, request);

                var entity = request.FromDto();
                entity.IsNew = true;

                if (adapter.SaveEntity(entity, true))
                {
                    OnAfterEmployeeAddRequest(adapter, request);
                    return(new EmployeeResponse(entity.ToDto()));
                }
            }

            throw new InvalidOperationException();
        }
Exemplo n.º 10
0
        public async Task <EmployeeInfo> AddEmployeeInfoAsync(EmployeeAddRequest employeeAddRequest)
        {
            DateTime     dateTime     = DateTime.UtcNow;
            EmployeeInfo employeeInfo = new EmployeeInfo
            {
                FirstName  = employeeAddRequest.FirstName,
                LastName   = employeeAddRequest.LastName,
                Email      = employeeAddRequest.Email,
                NationalID = employeeAddRequest.NationalID
            };
            await employeeInfoRepository.CreateAsync(employeeInfo);

            if (await employeeInfoRepository.EntitySaveChangeAsync())
            {
                return(employeeInfo);
            }
            else
            {
                throw new ApiExceptions("somthing went wrong");
            }
        }
 partial void OnAfterEmployeeAddRequest(IDataAccessAdapter adapter, EmployeeAddRequest request);
Exemplo n.º 12
0
        public async Task <ActionResult <EmployeeDto> > AddEmployeeAsync([FromBody] EmployeeAddRequest request)
        {
            var employeeDto = await _employeeService.AddEmployeeAsync(request);

            return(new ActionResult <EmployeeDto>(employeeDto));
        }
Exemplo n.º 13
0
 public async Task <IActionResult> AddEmployee(EmployeeAddRequest employeeInfo)
 {
     return(Ok(await _employeeService.AddEmployeeInfoAsync(employeeInfo)));
 }