Пример #1
0
 public void Delete(Guid Id)
 {
     using (var ctx = new AdressbookDBContext())
     {
         var EntityToDelete = ctx.PersonAdress.FirstOrDefault(x => x.Id == Id);
         ctx.PersonAdress.Remove(EntityToDelete);
         ctx.SaveChanges();
     }
 }
Пример #2
0
        public void addOrEdit(PersonAdress personAdress)
        {
            using (var ctx = new AdressbookDBContext())
            {
                var Entity = ctx.PersonAdress.FirstOrDefault(x => x.Id == personAdress.Id)
                             ?? new PersonAdress()
                {
                    Id = Guid.NewGuid()
                };
                Entity.Namn          = personAdress.Namn;
                Entity.Adress        = personAdress.Adress;
                Entity.Telefonnummer = personAdress.Telefonnummer;
                Entity.Updaterades   = DateTime.Now;

                ctx.PersonAdress.Add(Entity);
                ctx.SaveChanges();
            }
        }