Exemplo n.º 1
0
 public Process UpdateProcess(Process process)
 {
     using (SQLiteConnection conn = new SQLiteConnection(UrlBuilder.ToString()))
     {
         conn.Open();
         if(process == null)
             throw new NoNullAllowedException("Process can't be null");
         StringBuilder sb = new StringBuilder();
         sb.Append(Update);
         sb.Append(ProcessTable);
         sb.Append(Set);
         sb.Append("WebId=@webId, AccountId=@accountId, Name=@name, UpdatedAt=@updatedAt");
         sb.Append(Where);
         sb.Append("Id= " + process.Id);
         sb.Append(End);
         var command = new SQLiteCommand(sb.ToString(), conn);
             command.Parameters.Add(new SQLiteParameter("@webId", process.WebId));
             command.Parameters.Add(new SQLiteParameter("@accountId", process.AccountId));
             command.Parameters.Add(new SQLiteParameter("@name", process.Name));
             command.Parameters.Add(new SQLiteParameter("@updatedAt", DateTime.Now));
         Console.WriteLine(sb.ToString());
         command.ExecuteNonQuery();
     }
     return GetProcessById(process.Id);
 }
Exemplo n.º 2
0
 public Process SaveProcess(Process process)
 {
     using (SQLiteConnection conn = new SQLiteConnection(UrlBuilder.ToString()))
     {
         conn.Open();
         if (process == null)
             throw new NoNullAllowedException("Process object can't be null");
         /*if (process.AccountId <= 0)
             throw new ArgumentException("AccountId needs to be specified.");*/
         StringBuilder sb = new StringBuilder();
         Console.WriteLine("Saving a Process");
         sb.Append(InsertInto);
         sb.Append(ProcessTable);
         sb.Append("(AccountId, Name, CreatedAt, UpdatedAt)");
         sb.Append(Values);
         sb.Append("(@accountid, @name, @createdAt, @updatedAt)");
         sb.Append(End);
         var command = new SQLiteCommand(sb.ToString(), conn);
         command.Parameters.Add(new SQLiteParameter("@accountid", process.AccountId));
         command.Parameters.Add(new SQLiteParameter("@name", process.Name));
         command.Parameters.Add(new SQLiteParameter("@createdAt", DateTime.Now));
         command.Parameters.Add(new SQLiteParameter("@updatedAt", DateTime.Now));
         Console.WriteLine(sb.ToString());
         command.ExecuteNonQuery();
     }
     Console.WriteLine("Done writing Process");
     var savedProcess = GetProcesses().First(p => p.AccountId == process.AccountId && p.Name == process.Name);
     return savedProcess;
 }