public async Task <DbStatus> AddOrUpdate(LocalAccount localAccount)
        {
            List <string>   commandsToExecute = new List <string>();
            IConnector      connector         = ConnectorFactory.CreateConnector();
            MySqlConnection connection        = connector.CreateConnection();
            await connector.OpenConnection(connection);

            LocalAccount currentAccount = await GetByUniqueIdentifiers(new string[] { "Email" }, localAccount, false);

            DeleteOrUpdateRoles(currentAccount, localAccount, commandsToExecute, connection);

            commandsToExecute.Add(new InsertOrUpdateCommand <LocalAccount>().GetCommand(connection, localAccount.GetAssociatedDbTableName(), localAccount).CommandText);
            DbTransactionProcedure transactionProcedure = new UpdateDbTransactionProcedure(commandsToExecute.ToArray());
            DbStatus status = await transactionProcedure.Execute();

            return(status);
        }
예제 #2
0
 public async Task<DbStatus> Update(Doctor doctor)
 {
     List<string> commandsToExecute = new List<string>();
     IConnector connector = ConnectorFactory.CreateConnector();
     MySqlConnection connection = connector.CreateConnection();
     await connector.OpenConnection(connection);
     Doctor currentDoctor = await GetByPrimaryKey(doctor);
     if (currentDoctor == null)
     {
         return DbStatus.NOT_FOUND;
     }
     DeleteOrUpdateClinics(currentDoctor, doctor, commandsToExecute, connection);
     DeleteOrUpdateTitles(currentDoctor, doctor, commandsToExecute, connection);
     commandsToExecute.Add(new UpdateCommand<Doctor>().GetCommand(connection, doctor.GetAssociatedDbTableName(), doctor).CommandText);
     DbTransactionProcedure transactionProcedure = new UpdateDbTransactionProcedure(commandsToExecute.ToArray());
     DbStatus status = await transactionProcedure.Execute();
     return status;
 }
        public async Task <DbStatus> Update(LocalAccount localAccount)
        {
            List <string>   commandsToExecute = new List <string>();
            IConnector      connector         = ConnectorFactory.CreateConnector();
            MySqlConnection connection        = connector.CreateConnection();
            await connector.OpenConnection(connection);

            LocalAccount currentAccount = await GetByPrimaryKey(localAccount);

            if (currentAccount == null)
            {
                return(DbStatus.NOT_FOUND);
            }
            DeleteOrUpdateRoles(currentAccount, localAccount, commandsToExecute, connection);

            commandsToExecute.Add(new UpdateCommand <LocalAccount>().GetCommand(connection, localAccount.GetAssociatedDbTableName(), localAccount).CommandText);
            DbTransactionProcedure transactionProcedure = new UpdateDbTransactionProcedure(commandsToExecute.ToArray());
            DbStatus status = await transactionProcedure.Execute();

            return(status);
        }
        public async Task <DbStatus> Add(LocalAccount localAccount)
        {
            List <string>   commandsToExecute = new List <string>();
            IConnector      connector         = ConnectorFactory.CreateConnector();
            MySqlConnection connection        = connector.CreateConnection();
            await connector.OpenConnection(connection);

            LocalAccount currentAccount = await GetByUniqueIdentifiers(new string[] { "Email" }, localAccount);

            if (currentAccount != null && currentAccount.Deleted == 0)
            {
                return(DbStatus.EXISTS);
            }
            else if (currentAccount != null && currentAccount.Deleted == 1)
            {
                DeleteOrUpdateRoles(currentAccount, localAccount, commandsToExecute, connection);

                commandsToExecute.Add(new InsertOrUpdateCommand <LocalAccount>().GetCommand(connection, localAccount.GetAssociatedDbTableName(), localAccount).CommandText);
            }
            else
            {
                commandsToExecute.Add(new InsertCommand <LocalAccount>().GetCommand(connection, localAccount.GetAssociatedDbTableName(), localAccount).CommandText);
                foreach (var role in localAccount.GetRoles())
                {
                    LocalAccountRole lr = new LocalAccountRole()
                    {
                        IdRole = role.IdRole
                    };
                    commandsToExecute.Add(new InsertIntoConnectionTableCommand <LocalAccountRole>("IdLocalAccount").GetCommand(connection, lr.GetAssociatedDbTableName(), lr).CommandText);
                }
            }
            DbTransactionProcedure transactionProcedure = new UpdateDbTransactionProcedure(commandsToExecute.ToArray());
            DbStatus status = await transactionProcedure.Execute();

            return(status);
        }