Example #1
0
        public bool DeletePerson(PersonContract personContract)
        {
            Logger logger = LogManager.GetCurrentClassLogger();
            try
            {
                using (CareerEntities context = new CareerEntities())
                {

                    var person = context.Person.Where(p => p.ID == personContract.ID).FirstOrDefault();
                    if (person != null)
                    {
                        context.Person.Remove(person);
                        context.SaveChanges();
                        logger.Info("Delete a person " + personContract.ToString());
                        return true;
                    }
                    else
                    {
                        logger.Warn("Delete a nonexistent person " + personContract.ToString());
                        return false;
                    }
                }
            }
            catch (Exception exp)
            {
                logger.Error(exp, "Delete a person " + personContract.ToString());
                return false;
            }
        }
Example #2
0
 public bool SavePerson(PersonContract personContract)
 {
     Logger logger = LogManager.GetCurrentClassLogger();
     try
     {
         using (CareerEntities context = new CareerEntities())
         {
             var person = context.Person.Where(p => p.ID == personContract.ID).FirstOrDefault();
             if (person == null)
             {
                 context.Person.Add(personContract.ContractToPerson());
                 context.SaveChanges();
                 logger.Info("Add a person " + personContract.ToString());
                 return true;
             }
             else
             {
                 person.Address = personContract.Address;
                 person.Birthday = personContract.Birthday;
                 person.CellPhone = personContract.CellPhone;
                 person.ChineseName = personContract.ChineseName;
                 person.Email = personContract.Email;
                 person.EnglishName = personContract.EnglishName;
                 person.Male = personContract.Male;
                 person.NativePlace = personContract.NativePlace;
                 context.SaveChanges();
                 logger.Info("Update a person " + personContract.ToString());
                 return true;
             }
         }
     }
     catch (DbEntityValidationException exp)
     {
         logger.Error(exp, "Save a person " + personContract.ToString());
         return false;
     }
     catch (Exception exp)
     {
         logger.Error(exp, "Save a person " + personContract.ToString());
         return false;
     }
 }