public bool Update(DocumentTypeInfo documentTypeInfo) { try { using (var scope = new TransactionScope()) { using (var item = new IGDDemoEntities()) { // Un tercer parámetro del FirstOrDefault recibe un predicado que es una función que me devuelve un valor. var documentTypeData = item.DocumentTypes.FirstOrDefault(d => d.Id == documentTypeInfo.Id); if (documentTypeData != null) { documentTypeData.Title = documentTypeInfo.Title; documentTypeData.Code = documentTypeInfo.Code; item.Entry(documentTypeData).State = System.Data.Entity.EntityState.Modified; item.Entry(documentTypeData).CurrentValues.SetValues(documentTypeData); item.SaveChanges(); scope.Complete(); return(true); } scope.Dispose(); return(false); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
public bool Update(ClientInfo client) { try { using (var scope = new TransactionScope()) { using (var item = new IGDDemoEntities()) { var clientData = item.Clients.FirstOrDefault(c => c.Id == client.Id); if (clientData != null) { var personData = item.People.FirstOrDefault(p => p.Id == clientData.PersonId); personData.DocumentTypeId = client.DocumentTypeId; personData.DocumentNumber = client.DocumentNumber; personData.FirstName = client.FirstName; personData.SecondName = client.SecondName; item.Entry(personData).State = System.Data.Entity.EntityState.Modified; item.Entry(personData).CurrentValues.SetValues(personData); item.SaveChanges(); clientData.Readed = client.Readed; clientData.Phone = client.Phone; clientData.LastReading = client.LastReading; clientData.Anniversary = client.Anniversary; clientData.Email = client.Email; clientData.Address = client.Address; item.Entry(clientData).State = System.Data.Entity.EntityState.Modified; item.Entry(clientData).CurrentValues.SetValues(clientData); item.SaveChanges(); scope.Complete(); return(true); } scope.Dispose(); return(false); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
public bool Delete(int documentTypeId) { try { using (var scope = new TransactionScope()) { using (var item = new IGDDemoEntities()) { var documentTypeData = item.DocumentTypes.FirstOrDefault(d => d.Id == documentTypeId); if (documentTypeData != null) { item.Entry(documentTypeData).State = System.Data.Entity.EntityState.Deleted; item.SaveChanges(); scope.Complete(); return(true); } scope.Dispose(); return(false); } } } catch (Exception ex) { throw new Exception(ex.Message); } }