public static void CloseAllPendingArbiterTasks_ParentTaskEvalidated(ResponseTipTask task) { foreach (TextAnswerValidationTask arbiterTask in task.TextAnswerValidationTasks) { arbiterTask.CloseThisTask_ParentTaskIsEvalidated(); } }
// GET: TextAnswerValidationTasks/Task/5 public ActionResult Task(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TextAnswerValidationTask textAnswerValidationTask = db.TextAnswerValidationTasks.Find(id); if (textAnswerValidationTask == null) { return(HttpNotFound()); } if (User.Identity.GetUserId() != textAnswerValidationTask.ApplicationUserId) //check if right user is requesting to answer { return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized)); } ResponseTipTask responseTipTask = db.ResponseTipTasks.Find(textAnswerValidationTask.ResponseTipTaskID); if (responseTipTask == null) { return(HttpNotFound()); } TextAnswerValidationPresented newTask = new TextAnswerValidationPresented(id, responseTipTask.question, responseTipTask.answer, (decimal)0.02); return(View(newTask)); }
public static void TaskNotPaid(ResponseTipTask task) { // backendLogger.LogLine(""+task.ResponseTipTaskID, Logger.log_types.MESSAGE_LOG); decimal addressBalance = BtcHandling.BtcHandlingClass.CheckAdressBalance(task.BitcoinPublicAdress); if (addressBalance == task.BitcoinPrice) { task.taskStatus = TaskStatusesEnum.responseTip_paid; } else if (addressBalance > task.BitcoinPrice + BtcHandlingClass.UpdateEstimatedTxFee()) //if amount higher than neccessary and difference higher than txfee --return it to return address { BtcHandlingClass.SendFromAndToAddress(task.BitcoinPublicAdress, task.BitcoinReturnPublicAddress, addressBalance - task.BitcoinPrice, ConfigurationManager.AppSettings["Bitcoin_WalletPassword"]); task.taskStatus = TaskStatusesEnum.responseTip_paid; } else if (addressBalance > task.BitcoinPrice) //if amount higher than neccessary but difference lower than txfee --let it be { task.taskStatus = TaskStatusesEnum.responseTip_paid; } else if (addressBalance < task.BitcoinPrice) // if its lower then check if not expired { TimeSpan timeElapsedFromCreation = DateTime.Now.Subtract(task.timeCreated); if (timeElapsedFromCreation.TotalDays > taskNotPaidExpirationTime) { task.taskStatus = TaskStatusesEnum.responseTip_notPaid_expired; } } }
public static void TaskQuestionAskedExpired(ResponseTipTask task) { decimal addressBalance = BtcHandling.BtcHandlingClass.CheckAdressBalance(task.BitcoinPublicAdress); BtcHandlingClass.SendFromAndToAddress(task.BitcoinPublicAdress, task.BitcoinReturnPublicAddress, addressBalance, ConfigurationManager.AppSettings["Bitcoin_WalletPassword"]); task.taskStatus = TaskStatusesEnum.responseTip_closed; }
public ActionResult FindUser(int?id, [Bind(Include = "ResponseTipTaskID,twitterUserNameSelected")] ResponseTipTask responseTipTaskChanged) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ResponseTipTask responseTipTask = db.ResponseTipTasks.Find(id); if (responseTipTask == null) { return(HttpNotFound()); } responseTipTask.twitterUserNameSelected = responseTipTaskChanged.twitterUserNameSelected; if (responseTipTask.twitterUserNameSelected != null) { db.SaveChanges(); ResponseTipTask responseTipTasktest = db.ResponseTipTasks.Find(id); return(RedirectToAction("Create")); } // return RedirectToAction("FindUser", new { id = responseTipTask.ResponseTipTaskID }); // ViewBag.SearchResultsInBag = TwitterHandling.TwitterHandlingClass.SearchUsersM(responseTipTask.twitterUserNameWritten); UserSearchResults = TwitterHandling.TwitterHandlingClass.SearchUsersM(responseTipTask.twitterUserNameWritten); return(View(responseTipTask)); // return View(); }
public ActionResult DeleteConfirmed(int id) { ResponseTipTask responseTipTask = db.ResponseTipTasks.Find(id); db.ResponseTipTasks.Remove(responseTipTask); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ResponseTipTaskID,userID,question,socialSiteUser,BitcoinPublicAdress,BitcoinPrice,isQuestionPublic,taskStatus")] ResponseTipTask responseTipTask) { if (ModelState.IsValid) { db.Entry(responseTipTask).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(responseTipTask)); }
// GET: ResponseTipTasks/Create public ActionResult Create() { ResponseTipTask newTask = new ResponseTipTask(); newTask.question = "AutomaticQuestion"; newTask.twitterUserNameWritten = "RichardVelky"; newTask.BitcoinReturnPublicAddress = "n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi"; newTask.DollarPrice = (decimal)1; /* string address = BtcHandling.BtcHandlingClass.GetNewBtcAdress(); * Debug.WriteLine("new adress: " + address);*/ // UserSearchResults = TwitterHandling.TwitterHandlingClass.SearchUsersM("bb"); return(View(newTask)); }
// GET: ResponseTipTasks/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ResponseTipTask responseTipTask = db.ResponseTipTasks.Find(id); if (responseTipTask == null) { return(HttpNotFound()); } return(View(responseTipTask)); }
public static void TaskQuestionAsked(ResponseTipTask task) { long answerTweetId = TwitterHandlingClass.CheckAnswerToQuestion((long)task.questionTweetId, task.twitterUserNameSelected); if (answerTweetId > 0) { task.answerTweetId = answerTweetId; task.answer = TwitterHandlingClass.GetTweetAsString((long)task.answerTweetId); task.taskStatus = TaskStatusesEnum.responseTip_questionAnswered; return; } TimeSpan timeElapsedFromQuestionAsked = DateTime.Now.Subtract(task.timeQuestionAsked); if (timeElapsedFromQuestionAsked.TotalDays > taskQuestionAskedExpirationTime) { task.taskStatus = TaskStatusesEnum.responseTip_questionAsked_expired; } }
/* public ActionResult GetImg() * { * * var srcImage = Image.FromFile(imageFile); * using (var streak = new MemoryStream()) * { * srcImage.Save(streak, ImageFormat.Png); * return File(streak.ToArray(), "image/png"); * } * }*/ //GET: ResponseTipTasks public ActionResult FindUser(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ResponseTipTask responseTipTask = db.ResponseTipTasks.Find(id); if (responseTipTask == null) { return(HttpNotFound()); } // Debug.WriteLine("taskcontroller: FindUser"); // TwitterHandling.TwitterHandlingClass.PublishTweet("hello " + responseTipTask.twitterUserNameWritten); // UserSearchResults= TwitterHandling.TwitterHandlingClass.SearchUsersM(responseTipTask.twitterUserNameWritten); UserSearchResults = TwitterHandling.TwitterHandlingClass.SearchUsersM(responseTipTask.twitterUserNameWritten); //ViewBag.SearchResultsInBag = TwitterHandling.TwitterHandlingClass.SearchUsersM(responseTipTask.twitterUserNameWritten); ViewBag.SearchResultsInBag = UserSearchResults; return(View(responseTipTask)); }
public ActionResult Create([Bind(Include = "ResponseTipTaskID,question,twitterUserNameWritten,BitcoinReturnPublicAddress,DollarPrice,isQuestionPublic,ArbiterCount")] ResponseTipTask responseTipTask) { responseTipTask.BitcoinPublicAdress = BtcHandlingClass.GetNewBtcAdress(); responseTipTask.BitcoinPrice = responseTipTask.DollarPrice / externalAPIs.UpdateBitcoinAverageDollarPrice(); decimal estimatedTxFee = BtcHandlingClass.UpdateEstimatedTxFee(); responseTipTask.BitcoinPrice += estimatedTxFee; ModelState.Clear(); TryValidateModel(responseTipTask); if (ModelState.IsValid) { responseTipTask.taskStatus = TaskStatusesEnum.responseTip_created; responseTipTask.userName = User.Identity.GetUserId(); responseTipTask.timeCreated = DateTime.Now; responseTipTask.timeQuestionAsked = DateTime.MinValue; db.ResponseTipTasks.Add(responseTipTask); db.SaveChanges(); return(RedirectToAction("FindUser", new { id = responseTipTask.ResponseTipTaskID })); } return(View(responseTipTask)); }
public static void TaskPaid(ResponseTipTask task) { task.questionTweetId = TwitterHandlingClass.PostATweetOnAWall(task.twitterUserNameSelected, task.question); task.taskStatus = TaskStatusesEnum.responseTip_questionAsked; task.timeQuestionAsked = DateTime.Now; }
public static void TaskCreated(ResponseTipTask task) { task.taskStatus = TaskStatusesEnum.responseTip_notPaid; }
public static void TaskAllPaymentsSettled(ResponseTipTask task) { //TODO }
/// <summary> /// will settle all payments /// </summary> /// <param name="task"></param> public static void TaskAnswerAfterEvalidation(ResponseTipTask task) { //close all pending Arbiter Tasks }
public static TextAnswerValidationTask[] TaskQuestionAnswered_CreateArbiterTasks(ResponseTipTask task, string[] arbiterIDs) { //if parent task is answered then dont add new arbiter tasks if (task.answerValidation != AnswerValidationEnum.responseTip_notValidated) { return(new TextAnswerValidationTask[0]); } TextAnswerValidationTask[] newArbiterTasks = new TextAnswerValidationTask[arbiterIDs.Count()]; for (int i = 0; i < arbiterIDs.Count(); i++) { newArbiterTasks[i] = new TextAnswerValidationTask(arbiterIDs[i], task.ResponseTipTaskID, taskForArbiterExpirationTime, taskForArbiterPriceInDollar); } return(newArbiterTasks); }
public static void TaskQuestionAnswered_CheckArbiterTasksStatus(ResponseTipTask task) { int yesVotes = 0; int noVotes = 0; int skipVotes = 0; IEnumerable <TextAnswerValidationTask> textAnswerValidationTaskEnumerator = task.TextAnswerValidationTasks.AsEnumerable(); foreach (TextAnswerValidationTask arbiterTask in textAnswerValidationTaskEnumerator) { switch (arbiterTask.arbiterAnswer) { case TextAnswerValidation_ArbiterAnswerEnum.notValid: noVotes++; break; case TextAnswerValidation_ArbiterAnswerEnum.Valid: yesVotes++; break; case TextAnswerValidation_ArbiterAnswerEnum.skip: skipVotes++; break; } if (yesVotes + noVotes == task.ArbiterCount) { if (yesVotes > noVotes) { task.answerValidation = AnswerValidationEnum.responseTip_AnswerIsValid; task.taskStatus = TaskStatusesEnum.responseTip_answerAfterEvalidation; } else if (yesVotes < noVotes) { task.answerValidation = AnswerValidationEnum.responseTip_AnswerIsNotValid; task.taskStatus = TaskStatusesEnum.responseTip_answerAfterEvalidation; } else // if Arbiter answer is 50:50 than answer is not Valid { task.answerValidation = AnswerValidationEnum.responseTip_AnswerIsNotValid; task.taskStatus = TaskStatusesEnum.responseTip_answerAfterEvalidation; } CloseAllPendingArbiterTasks_ParentTaskEvalidated(task); //foreach(TextAnswerValidationTask arbiterTask2 in textAnswerValidationTaskEnumerator) //{ // if(task.taskStatus==TaskStatusesEnum.responseTip_answerValid) // { // if(arbiterTask2.arbiterAnswer==TextAnswerValidation_ArbiterAnswerEnum.Valid) // { // dbContext.Users.Find(arbiterTask2.ApplicationUserId).IncrementNumOfPuzzlesSuccesfull(); // }else if(arbiterTask2.arbiterAnswer == TextAnswerValidation_ArbiterAnswerEnum.notValid) // { // } // } //} break; } } return; }