コード例 #1
0
ファイル: Dal.cs プロジェクト: kristallklart/Uppgifter_CSharp
        public static List <EmployeeRelative> GetEmployeeRelatives()
        {
            try
            {
                OpenConnection();
                Query = "select [Employee No_] , [First Name], [Last Name], [Relative Code] from [CRONUS Sverige AB$Employee Relative]";
                SqlCommand cmd = new SqlCommand(Query, connection);
                dataReader        = cmd.ExecuteReader();
                employeeRelatives = new List <EmployeeRelative>();

                while (dataReader.Read())
                {
                    EmployeeRelative relative = new EmployeeRelative();
                    relative.FirstName      = dataReader["First Name"].ToString();
                    relative.LastName       = dataReader["Last Name"].ToString();
                    relative.EmployeeNumber = dataReader["Employee No_"].ToString();
                    employeeRelatives.Add(relative);
                }
                return(employeeRelatives);
            }
            finally
            {
                CloseConnection();
            }
        }
コード例 #2
0
        public int Update(EmpRelativeItem model)
        {
            Mapper.CreateMap <EmpRelativeItem, EmployeeRelative>();
            EmployeeRelative objRel = DBContext.EmployeeRelatives.SingleOrDefault(m => m.Id == model.Id);

            objRel = Mapper.Map(model, objRel);
            return(DBContext.SaveChanges());
        }
コード例 #3
0
        //For Insert Records in EmployeeRelative table
        public int Insert(EmpRelativeItem model)
        {
            Mapper.CreateMap <EmpRelativeItem, EmployeeRelative>();
            EmployeeRelative objRelative = Mapper.Map <EmployeeRelative>(model);

            DBContext.EmployeeRelatives.Add(objRelative);
            return(DBContext.SaveChanges());
        }
コード例 #4
0
        public EmpRelativeItem GetById(int id)
        {
            Mapper.CreateMap <EmployeeRelative, EmpRelativeItem>();
            EmployeeRelative objRelative     = DBContext.EmployeeRelatives.SingleOrDefault(m => m.Id == id);
            EmpRelativeItem  objRelativeItem = Mapper.Map <EmpRelativeItem>(objRelative);

            return(objRelativeItem);
        }
コード例 #5
0
 public List <EmployeeRelative> GetEmployeeRelative()
 {
     try
     {
         List <EmployeeRelative> relatives = new List <EmployeeRelative>();
         navConnection.Open();
         using (SqlCommand command = new SqlCommand("select employee.[First Name], employee.[Last Name], employee.[Job Title], relative.[First Name], relative.[Relative Code] from[CRONUS Sverige AB$Employee] employee right join[CRONUS Sverige AB$Employee Relative] relative on employee.No_ = relative.[Employee No_]", navConnection))
         {
             using (SqlDataReader reader = command.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     EmployeeRelative tmp = new EmployeeRelative
                     {
                         EmpFirstName      = reader.GetValue(0) as string,
                         EmpLastName       = reader.GetValue(1) as string,
                         EmpJobTitle       = reader.GetValue(2) as string,
                         RelativeFirstName = reader.GetValue(3) as string,
                         RelativeCode      = reader.GetValue(4) as string
                     };
                     relatives.Add(tmp);
                 }
             }
         }
         navConnection.Close();
         return(relatives);
     }
     catch (Exception e)
     {
         throw ExceptionHandler.HandleEFException(e);
     }
     finally
     {
         navConnection.Close();
     }
 }