Exemple #1
0
        public DBActions InsertOrUpdate(Person newPerson)
        {
            DBActions action = DBActions.None;

            using (var dao = new PersonLINQDao())
            {
                var thePerson = dao.Persons.Find(newPerson.Id);
                action = thePerson != null ? DBActions.Update : DBActions.Insert;

                switch (action)
                {
                case DBActions.Insert:
                    //newPerson.Id = 0;
                    newPerson.Intime = DateTime.Now;
                    newPerson.Utime  = DateTime.Now;
                    newPerson.Id     = Convert.ToInt32(dao.InsertWithIdentity(newPerson));
                    break;

                case DBActions.Update:
                    newPerson.Intime = thePerson.Intime;
                    newPerson.Utime  = DateTime.Now;
                    dao.Update(newPerson);
                    break;
                }
            }

            return(action);
        }
Exemple #2
0
 public static List <Person> GetAll()
 {
     using (var dao = new PersonLINQDao())
     {
         var query = from p in dao.Persons
                     select p;
         return(query.ToList());
     }
 }
Exemple #3
0
 public IList <Person> GetPersonByBirthDateTimeRange(DateTime dateTime, int intervalDay)
 {
     using (var dao = new PersonLINQDao())
     {
         var query = from p in dao.Persons
                     where p.Birthday.Month == dateTime.Month &&
                     p.Birthday.Day >= dateTime.Date.AddDays(-1 * intervalDay).Day&&
                     p.Birthday.Day <= dateTime.Date.AddDays(intervalDay).Day
                     select p;
         return(query.ToList());
     }
 }