Hey guys, new to WPF and really struggling with 'the right way' to do things...
public void Save(CompanyContact entityToSave)
{
try
{
var saveEntity = (from cc in db.CompanyContacts
where cc.CompanyContactId == entityToSave.CompanyContactId
select cc).SingleOrDefault();
if (saveEntity == null)
{
//INSERT logic
entityToSave.CreatedById = new CompanyPersonRepository().GetCompanyPerson(DataContext.Default.LoginUsername).CompanyPersonId;
entityToSave.ModifiedById = entityToSave.CreatedById;
db.CompanyContacts.InsertOnSubmit(entityToSave);
db.CompanyContacts.Context.SubmitChanges();
}
else
{
//UPDATE logic
saveEntity.ModifiedById = new CompanyPersonRepository().GetCompanyPerson(DataContext.Default.LoginUsername).CompanyPersonId;
saveEntity.CompanyId = entityToSave.Company.CompanyId;
saveEntity.FirstName = entityToSave.FirstName;
saveEntity.LastName = entityToSave.LastName;
saveEntity.CompanyContactTypeId = entityToSave.CompanyContactTypeId;
db.CompanyContacts.Context.SubmitChanges();
}
...
if not can you please provide some comments on why it is not, or provide an example of a better way to write LINQ functions if I am not on the right path?? (thanks)