public void Save(Model.Project entity) { using (_entities = new GreenovaEntities()) { if (entity.Id == 0) { EFRepository.Project dbEntry = new EFRepository.Project { code = entity.Code, name = entity.Name, remarks = entity.Remarks, budget = entity.Budget }; _entities.Projects.AddObject(dbEntry); } else { EFRepository.Project dbEntry = _entities.Projects.Where(x => x.id == entity.Id) .SingleOrDefault(); if (dbEntry != null) { dbEntry.name = entity.Name; dbEntry.code = entity.Code; dbEntry.remarks = entity.Remarks; dbEntry.budget = entity.Budget; } } _entities.SaveChanges(); } }
public void Save(Model.Person entity) { using (_entities = new GreenovaEntities()) { if (entity.Id == 0) { EFRepository.Person dbEntry = new EFRepository.Person { id = entity.Id, first_name = entity.FirstName, last_name = entity.LastName, username = entity.Username, password = entity.Password }; _entities.Persons.AddObject(dbEntry); } else { EFRepository.Person dbEntry = _entities.Persons.Where(x => x.id == entity.Id) .SingleOrDefault(); if (dbEntry != null) { dbEntry.first_name = entity.FirstName; dbEntry.last_name = entity.LastName; dbEntry.username = entity.Username; dbEntry.password = entity.Password; } } _entities.SaveChanges(); } }