コード例 #1
0
        public EmployeeComplex(IDataReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader), $"{nameof(reader)} is null.");
            }

            EmployeeKey = reader.GetInt32(reader.GetOrdinal("EmployeeKey"));
            FirstName   = reader.GetString(reader.GetOrdinal("FirstName"));
            if (!reader.IsDBNull(reader.GetOrdinal("MiddleName")))
            {
                MiddleName = reader.GetString(reader.GetOrdinal("MiddleName"));
            }
            LastName = reader.GetString(reader.GetOrdinal("LastName"));
            if (!reader.IsDBNull(reader.GetOrdinal("Title")))
            {
                Title = reader.GetString(reader.GetOrdinal("Title"));
            }
            if (!reader.IsDBNull(reader.GetOrdinal("OfficePhone")))
            {
                OfficePhone = reader.GetString(reader.GetOrdinal("OfficePhone"));
            }
            if (!reader.IsDBNull(reader.GetOrdinal("CellPhone")))
            {
                CellPhone = reader.GetString(reader.GetOrdinal("CellPhone"));
            }

            EmployeeClassification = new EmployeeClassification(reader);
        }
コード例 #2
0
        public void TestFlags()
        {
            var a = new EmployeeClassification()
            {
                EmployeeClassificationName = "A T T " + DateTime.Now.Ticks, IsExempt = true, IsEmployee = true
            };
            var b = new EmployeeClassification()
            {
                EmployeeClassificationName = "A F T " + DateTime.Now.Ticks, IsExempt = false, IsEmployee = true
            };
            var c = new EmployeeClassification()
            {
                EmployeeClassificationName = "A T F " + DateTime.Now.Ticks, IsExempt = true, IsEmployee = false
            };
            var d = new EmployeeClassification()
            {
                EmployeeClassificationName = "A F F " + DateTime.Now.Ticks, IsExempt = false, IsEmployee = false
            };

            using (var db = DbConnectionFactory.OpenDbConnection())
            {
                db.Save(a);
                db.Save(b);
                db.Save(c);
                db.Save(d);
            }
        }
 public override void Delete(EmployeeClassification classification)
 {
     using (var context = new OrmCookbook())
     {
         context.Database.ExecuteSqlCommand("DELETE FROM HR.EmployeeClassification WHERE EmployeeClassificationKey = @p0", classification.EmployeeClassificationKey);
     }
 }
 public override void Update(EmployeeClassification classification)
 {
     using (var context = new OrmCookbook())
     {
         context.Entry(classification).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #5
0
        override public void Update(EmployeeClassification classification)
        {
            if (classification == null)
            {
                throw new ArgumentNullException(nameof(classification), $"{nameof(classification)} is null.");
            }

            using (var con = OpenConnection())
                con.Update(classification);
        }
コード例 #6
0
        override public int Create(EmployeeClassification classification)
        {
            if (classification == null)
            {
                throw new ArgumentNullException(nameof(classification), $"{nameof(classification)} is null.");
            }

            using (var con = OpenConnection())
                return((int)con.Insert(classification));
        }
        override public async Task UpdateAsync(EmployeeClassification classification)
        {
            if (classification == null)
            {
                throw new ArgumentNullException(nameof(classification), $"{nameof(classification)} is null.");
            }

            using (var con = await OpenConnectionAsync().ConfigureAwait(false))
                await con.UpdateAsync(classification).ConfigureAwait(false);
        }
コード例 #8
0
 public override void DeleteByKey(int employeeClassificationKey)
 {
     using (var context = CreateDbContext())
     {
         var temp = new EmployeeClassification()
         {
             EmployeeClassificationKey = employeeClassificationKey
         };
         context.Entry(temp).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
コード例 #9
0
        public override void Update(EmployeeClassification classification)
        {
            if (classification == null)
            {
                throw new ArgumentNullException(nameof(classification), $"{nameof(classification)} is null.");
            }

            using (var context = CreateDbContext())
            {
                context.Entry(classification).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
コード例 #10
0
        public int Create(EmployeeClassification classification)
        {
            if (classification == null)
            {
                throw new ArgumentNullException(nameof(classification), $"{nameof(classification)} is null.");
            }

            using (var session = m_SessionFactory.OpenSession())
            {
                session.Save(classification);
                session.Flush();
                return(classification.EmployeeClassificationKey);
            }
        }
コード例 #11
0
        public int CreateEmployeeClassification(EmployeeClassification employeeClassification)
        {
            if (employeeClassification == null)
            {
                throw new ArgumentNullException(nameof(employeeClassification),
                                                $"{nameof(employeeClassification)} is null.");
            }

            return(ExecuteScalar <int>("[HR].[CreateEmployeeClassification]", new
            {
                employeeClassification.EmployeeClassificationName,
                employeeClassification.IsExempt,
                employeeClassification.IsEmployee
            }, commandType: CommandType.StoredProcedure));
        }
コード例 #12
0
        public ReadOnlyEmployeeClassification(EmployeeClassification entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity), $"{nameof(entity)} is null.");
            }
            if (entity.EmployeeClassificationName == null)
            {
                throw new ArgumentNullException(nameof(entity), $"{nameof(entity.EmployeeClassificationName)} is null.");
            }

            EmployeeClassificationKey  = entity.EmployeeClassificationKey;
            EmployeeClassificationName = entity.EmployeeClassificationName;
            IsExempt   = entity.IsExempt;
            IsEmployee = entity.IsEmployee;
        }
コード例 #13
0
        private static void AddEmployeeClassificationRefDataToDb(DataRow row)
        {
            EmployeeClassification ec = new EmployeeClassification()
            {
                Code       = row.Field <String>("empl_classification"),
                DescShort  = row.Field <String>("empl_classification"),
                DescLong   = row.Field <String>("empl_classification"),
                ActiveFlag = true,
                CreatedDt  = DateTime.Now,
                CreatedBy  = 0,
                UpdatedDt  = DateTime.Now,
                UpdatedBy  = 0
            };

            try
            {
                using (SdmDbContext dbc = new SdmDbContext())
                {
                    // if this record already exists in db, dont save it (this is a reference table)
                    if (dbc.EmployeeClassifications.Any(o => o.Code == ec.Code))
                    {
                        //match! todo: fix this if else
                    }
                    else
                    {
                        dbc.EmployeeClassifications.Add(ec);
                        dbc.SaveChanges();
                    }
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"",
                                          ve.PropertyName,
                                          eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName),
                                          ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
コード例 #14
0
 public Developer(string firstName, string lastName, Hometown hometown, EmployeeClassification classification, Seniority seniorityLevel)
     : base(firstName, lastName, hometown, classification)
 {
     SeniorityLevel = seniorityLevel;
 }
コード例 #15
0
 protected Employee(string firstName, string lastName, Hometown hometown, EmployeeClassification classification)
     : base(firstName, lastName, hometown)
 {
     Classification = classification;
 }