Ejemplo n.º 1
0
        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 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));
        }