public CredentialItem DeleteCredential(CredentialItem item)
        {
            Credential dbItem = db.Credentials.Find(item.CredentialID);

            db.Credentials.Remove(dbItem);
            db.SaveChanges();
            return(item);
        }
        public CredentialItem GetCredential(int credentialID)
        {
            Credential     dbItem = db.Credentials.Find(credentialID);
            CredentialItem item   = new CredentialItem
            {
                CredentialID     = dbItem.CredentialID,
                Password         = dbItem.Password,
                SettingID        = dbItem.SettingID,
                CredentialStatus = dbItem.Status,
                UsageDateTime    = dbItem.UsageDateTime
            };

            return(item);
        }
        public CredentialItem UpdateCredential(CredentialItem item)
        {
            Setting    setting = db.Settings.Find(item.SettingID);
            Credential dbItem  = db.Credentials.Find(item.CredentialID);

            dbItem.CredentialID  = item.CredentialID;
            dbItem.Password      = item.Password;
            dbItem.SettingID     = item.SettingID;
            dbItem.Status        = item.CredentialStatus;
            dbItem.UsageDateTime = item.UsageDateTime;
            dbItem.Setting       = setting;
            db.Credentials.Attach(dbItem);
            db.Entry(dbItem).State = EntityState.Modified;
            db.SaveChanges();
            return(item);
        }
        public CredentialItem InsertCredential(CredentialItem item)
        {
            Setting    setting = db.Settings.Find(item.SettingID);
            Credential dbItem  = new Credential
            {
                Password      = item.Password,
                SettingID     = item.SettingID,
                Status        = item.CredentialStatus,
                UsageDateTime = item.UsageDateTime,
                Setting       = setting
            };

            db.Credentials.Add(dbItem);
            db.SaveChanges();
            item.CredentialID = dbItem.CredentialID;
            return(item);
        }