public visit edit(visit acc) { try { var entry = _context.Entry <visit>(acc); if (entry.State == System.Data.Entity.EntityState.Detached) { var set = _context.Set <visit>(); visit attachedEntity = set.Local.SingleOrDefault(e => e.id == acc.id); // You need to have access to key if (attachedEntity != null) { var attachedEntry = _context.Entry(attachedEntity); attachedEntry.CurrentValues.SetValues(acc); } else { entry.State = System.Data.Entity.EntityState.Modified; // This should attach entity } } } catch (Exception e) { Logger.Log(e.ToString(), LogType.Error); } return(acc); }
public SystemPerson edit(SystemPerson acc) { try { DBService <Account> _accountService = new AccountService(); Account account = _accountService.get(acc.id); if (account != null) { account.name = acc.name; account.password = acc.Password; _accountService.edit(account); } else { addAccount(acc); } var entry = _context.Entry <SystemPerson>(acc); if (entry.State == System.Data.Entity.EntityState.Detached) { var set = _context.Set <SystemPerson>(); SystemPerson attachedEntity = set.Local.SingleOrDefault(e => e.id == acc.id); // You need to have access to key if (attachedEntity != null) { var attachedEntry = _context.Entry(attachedEntity); attachedEntry.CurrentValues.SetValues(acc); } else { entry.State = System.Data.Entity.EntityState.Modified; // This should attach entity } } _context.SaveChanges(); Logger.Log(acc.name + " is Edited", LogType.Info); } catch (Exception e) { Logger.Log(e.ToString(), LogType.Error); } return(acc); }