Esempio n. 1
0
        private void addAccount(SystemPerson acc)
        {
            DBService <Account> _accountService = new AccountService();

            _accountService.add(new Account
            {
                creationDate = DateTime.Now,
                name         = acc.name,
                password     = acc.Password,
                id           = acc.id
            });
        }
Esempio n. 2
0
 public SystemPerson add(SystemPerson acc)
 {
     try
     {
         addAccount(acc);
         _context.SystemPersons.Add(acc);
         _context.SaveChanges();
         Logger.Log(acc.name + " is Added", LogType.Info);
     }
     catch (Exception e)
     {
         Logger.Log(e.ToString(), LogType.Error);
     }
     return(acc);
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 public SystemPerson delete(SystemPerson acc)
 {
     try
     {
         DBService <Account> _accountService = new AccountService();
         Account             account         = _accountService.get(acc.id);
         if (account != null)
         {
             _accountService.delete(account);
         }
         _context.Entry(acc).State = System.Data.Entity.EntityState.Deleted;
         _context.SaveChanges();
         Logger.Log(acc.name + " is Deleted", LogType.Info);
     }
     catch (Exception e)
     {
         Logger.Log(e.ToString(), LogType.Error);
     }
     return(acc);
 }
Esempio n. 5
0
        public SystemPerson getByName(string name)
        {
            SystemPerson acc = _context.SystemPersons.FirstOrDefault(o => o.name == name);

            return(acc);
        }
Esempio n. 6
0
        public SystemPerson get(Guid id)
        {
            SystemPerson acc = _context.SystemPersons.FirstOrDefault(o => o.id == (id));

            return(acc);
        }