Пример #1
0
        public async Task <IActionResult> InsertEmployee([FromBody] Entities.Concrete.Employee.Employee employeeRequest)
        {
            ActionResultResponse <EmployeeResponse> response;

            Entities.Concrete.Employee.Employee employee = null;
            try
            {
                if (_service.ValidateEmployee(employeeRequest.CompanyID, employeeRequest.UserName, false))
                {
                    if (_service.InsertEmployee(employeeRequest))
                    {
                        employee = _service.GetEmployeeByCompanyID(employeeRequest.CompanyID);
                    }
                    response = EmployeeMapper.EmployeeGetByIdResult(employee);
                }
                else
                {
                    response = new ActionResultResponse <EmployeeResponse>(System.Net.HttpStatusCode.Locked, MessageException.GetEmployeeAlreadyExists(employeeRequest.CompanyID, employeeRequest.UserName), null);
                }
            }
            catch (Exception ex)
            {
                LogException.WriteLog(ex, "EmployeeController.InsertEmployee", JsonSerializer.Serialize(employeeRequest), LogType.Error);
                response = new ActionResultResponse <EmployeeResponse>(System.Net.HttpStatusCode.InternalServerError, MessageException.GetGeneralMessage(ex), null);
            }
            return(GetResponse(response));
        }
Пример #2
0
        public static ActionResultResponse <EmployeeResponse> EmployeeGetByIdResult(Entities.Concrete.Employee.Employee prmEmployee)
        {
            EmployeeResponse response = new EmployeeResponse()
            {
                Employee = prmEmployee
            };

            return(new ActionResultResponse <EmployeeResponse>(System.Net.HttpStatusCode.OK, string.Empty, response));
        }
Пример #3
0
        public async Task <IActionResult> GetDummyEmployee()
        {
            Entities.Concrete.Employee.Employee     employee = new Entities.Concrete.Employee.Employee();
            ActionResultResponse <EmployeeResponse> response;

            try
            {
                response = EmployeeMapper.EmployeeGetByIdResult(employee);
            }
            catch (Exception ex)
            {
                LogException.WriteLog(ex, "EmployeeController.InsertEmployee", JsonSerializer.Serialize(employee), LogType.Error);
                response = new ActionResultResponse <EmployeeResponse>(System.Net.HttpStatusCode.InternalServerError, MessageException.GetGeneralMessage(ex), null);
            }
            return(GetResponse(response));
        }
Пример #4
0
 /// <summary>
 /// Metodo utilitario para llenar parametros de un objeto SQLCommand, se usa en el insert y update(usan los mismos paramentros).
 /// </summary>
 /// <param name="prmCommand"> Objeto SQLCommand previamente instanciado.</param>
 /// <param name="prmEmployee"></param>
 public static void EntityToParameters(ref SqlCommand prmCommand, Entities.Concrete.Employee.Employee prmEmployee)
 {
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmCompanyID", SqlDbType = SqlDbType.BigInt, Direction = ParameterDirection.Input, Value = prmEmployee.CompanyID
     });
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmName", SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Input, Value = prmEmployee.Name.Trim()
     });
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmUserName", SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Input, Size = 50, Value = prmEmployee.UserName.Trim()
     });
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmEmail", SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Input, Value = prmEmployee.Email.Trim()
     });
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmPassword", SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Input, Value = Encryptor.EncryptSHA1Managed(prmEmployee.Password.Trim())
     });
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmTelephone", SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Input, Value = prmEmployee.Telephone.Trim()
     });
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmFax", SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Input, Value = prmEmployee.Fax.Trim()
     });
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmPortalID", SqlDbType = SqlDbType.SmallInt, Direction = ParameterDirection.Input, Value = prmEmployee.PortalID
     });
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmRoleID", SqlDbType = SqlDbType.SmallInt, Direction = ParameterDirection.Input, Value = prmEmployee.RoleID
     });
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmStatusID", SqlDbType = SqlDbType.SmallInt, Direction = ParameterDirection.Input, Value = prmEmployee.StatusID
     });
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmLastLogin", SqlDbType = SqlDbType.DateTime, Direction = ParameterDirection.Input, Value = NullOrEmptyToDBNull(prmEmployee.LastLogin)
     });
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmCreatedOn", SqlDbType = SqlDbType.DateTime, Direction = ParameterDirection.Input, Value = NullOrEmptyToDBNull(prmEmployee.CreatedOn)
     });
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmUpdatedOn", SqlDbType = SqlDbType.DateTime, Direction = ParameterDirection.Input, Value = NullOrEmptyToDBNull(prmEmployee.UpdatedOn)
     });
     prmCommand.Parameters.Add(new SqlParameter {
         ParameterName = "@prmDeletedOn", SqlDbType = SqlDbType.DateTime, Direction = ParameterDirection.Input, Value = NullOrEmptyToDBNull(prmEmployee.DeletedOn)
     });
 }
Пример #5
0
        public bool InsertEmployee(Entities.Concrete.Employee.Employee prmEmployee)
        {
            bool result = false;

            using (var conn = GetConnection())
            {
                using (SqlCommand command = new SqlCommand("[dbo].[stpEmployeeInsert]", (SqlConnection)conn))
                {
                    var parametersMapper = command;
                    command.CommandType = CommandType.StoredProcedure;
                    EmployeeMapper.EntityToParameters(ref parametersMapper, prmEmployee);
                    command.Parameters.Add(new SqlParameter {
                        ParameterName = "@prmSuccessFlag", SqlDbType = SqlDbType.Bit, Direction = ParameterDirection.Output, Value = result
                    });
                    var rowsAffected = command.ExecuteNonQuery();
                    result = (bool)command.Parameters["@prmSuccessFlag"].Value;
                }
                conn.Close();
            }
            return(result);
        }
Пример #6
0
 public Entities.Concrete.Employee.Employee GetEmployeeByCompanyID(long prmCompanyID)
 {
     Entities.Concrete.Employee.Employee employee = null;
     using (var conn = GetConnection())
     {
         using (SqlCommand command = new SqlCommand("[dbo].[stpEmployeeSelectByCompanyID]", (SqlConnection)conn))
         {
             command.CommandType = CommandType.StoredProcedure;
             command.Parameters.Add(new SqlParameter {
                 ParameterName = "@prmCompanyID", SqlDbType = SqlDbType.BigInt, Direction = ParameterDirection.Input, Value = prmCompanyID
             });
             SqlDataReader reader = command.ExecuteReader();
             if (reader.HasRows)
             {
                 while (reader.Read())
                 {
                     employee = EmployeeMapper.SqlDataReaderToEntity(reader);
                 }
             }
         }
         conn.Close();
     }
     return(employee);
 }
Пример #7
0
        public bool UpdateEmployee(Entities.Concrete.Employee.Employee prmEmployee)
        {
            IEmployeeData employeeData = FactoryData.CreateEmployeeData();

            return(employeeData.UpdateEmployee(prmEmployee));
        }
Пример #8
0
        public bool UpdateEmployee(Entities.Concrete.Employee.Employee prmEmployee)
        {
            IEmployeeBusiness employeeBusiness = FactoryBusiness.CreateEmployeeBusiness();

            return(employeeBusiness.UpdateEmployee(prmEmployee));
        }