Example #1
0
        public async Task RejectedApplication(int ActiveProductID)
        {
            var rejectProd = db.activeproductitems.Find(ActiveProductID);
            var prodValue  = rejectProd.productValue;
            var tempCons   = db.consumers.Find(rejectProd.Consumer_ID);
            var tempUser   = db.users.Find(tempCons.User_ID);

            refundConsumer(tempCons.User_ID, rejectProd.productValue);

            //deactive product from active
            rejectProd.isActive = false;
            rejectProd.Accepted = false;
            rejectProd.activeProductItemPolicyNum = "Rejected";
            //notify user push Notification
            var NC = new NotificationController();

            var message = "NanoFin: Your purchase for '";

            message += prodIDToProdName(rejectProd.Product_ID);
            message += "; has been rejected. Your Account has been refunded with R";
            message += rejectProd.productValue.ToString() + ".";
            //db.UpdateConsumerRiskValues();
            NC.SendSMS(tempUser.userContactNumber, message);

            //reflect on blockchain
            string productName = prodIDToProdName(rejectProd.Product_ID);
            MConsumerController consumerCtrl = new MConsumerController(tempUser.User_ID);

            consumerCtrl = await consumerCtrl.init();

            await consumerCtrl.refundConsumer(productName, Decimal.ToInt32(prodValue));
        }
        public async Task <IHttpActionResult> consumerSendVoucher_RecipientUnknown(int consumerUserID, string recipientDetails, decimal transferAmount)
        {
            if (isUserConsumer(consumerUserID))
            {
                int recipientUserID = getUserDetailsToUserID(recipientDetails);
                if (isUserConsumer(recipientUserID))
                {
                    SendVoucher(consumerUserID, recipientUserID, transferAmount, 21, 2);


                    MConsumerController consumerCtrl = new MConsumerController(consumerUserID);
                    consumerCtrl = await consumerCtrl.init();

                    await consumerCtrl.sendVoucherToConsumer(recipientUserID, Decimal.ToInt32(transferAmount));

                    return(Ok());
                }
                else
                {
                    return(BadRequest("Receiver is not a consumer"));
                }
            }
            else
            {
                return(BadRequest("Sender is not a consumer"));
            }
        }
        public async Task <IHttpActionResult> consumerSendVoucher(int consumerUserID, int recipientID, decimal transferAmount)
        {
            if (isUserConsumer(consumerUserID) && isUserConsumer(recipientID))
            {
                if (recipientID > 0)
                {
                    if (getVoucherAccountBalance(consumerUserID) < transferAmount)
                    {
                        return(BadRequest("invalid funds"));
                    }
                    else
                    {
                        SendVoucher(consumerUserID, recipientID, transferAmount, 21, 2);

                        MConsumerController consumerCtrl = new MConsumerController(consumerUserID);
                        consumerCtrl = await consumerCtrl.init();

                        await consumerCtrl.sendVoucherToConsumer(recipientID, Decimal.ToInt32(transferAmount));
                    }
                }
                else
                {
                    return(BadRequest("Recipient details invalid"));
                }

                return(Ok());
            }
            else
            {
                return(BadRequest("Sender and Receiver must both be of type Consumer"));
            }
        }
Example #4
0
        public async Task <bool> invalidateProduct(int productID, int userID, int amount)
        {
            string productName = MUtilityClass.removeSpaces(await prodIDToProdName(productID));

            MConsumerController consumerCtrl = new MConsumerController(userID);

            consumerCtrl = await consumerCtrl.init();

            await consumerCtrl.invalidateProduct(productName, amount);

            return(true);
        }
Example #5
0
        public async Task <bool> consumerRedeem(int productID, int userID, int amount)
        {
            string productName = await prodIDToProdName(productID);

            MConsumerController consumerCtrl = new MConsumerController(userID);

            consumerCtrl = await consumerCtrl.init();

            await consumerCtrl.redeemVoucher(productName, Decimal.ToInt32(amount));

            return(true);
        }
        public async Task <IHttpActionResult> redeemProduct(int userID, int productID, int numberUnits, DateTime startdate)
        {
            //check that the minimum number of units is applied according to what is in db:
            if (!isValidNumUnits(productID, numberUnits))
            {
                return(BadRequest("The minimum number of units constraint has not been met"));
            }


            //calculate price of products for the specified number of days/units
            //"ProductValue" field in activeProduct Items
            decimal prodTotalPrice = calcProductPrice(productID, numberUnits);

            //calculate totalVoucherValues for this user
            decimal totalVoucherValues = calcTotalVoucherValues(userID);

            //get the user's voucherList in ascending order
            List <voucher> vouchersList = new List <voucher>();

            vouchersList = getUserVouchersList(userID);

            //make a decimal to deduct
            decimal amountToDeduct = prodTotalPrice;

            //check that the user has sufficient vouchers: that prodTotalPrice <= totalVoucherValues
            if (prodTotalPrice <= totalVoucherValues)//can proceed with redeem process
            {
                //Add activeProductItem to db table
                var               consumerID     = (from c in db.consumers where c.User_ID == userID select c).FirstOrDefault();
                string            prodUnitType   = getProductUnitType(productID);                              //get the string eg 'per day'
                DateTime          endDate        = getEndDateForProduct(prodUnitType, startdate, numberUnits); //calculate the end date
                activeproductitem activeProdItem = createActiveProductItem(consumerID.Consumer_ID, productID, "", true, prodTotalPrice, numberUnits, startdate, endDate);
                activeProdItem.transactionlocation = consumerID.Location_ID;
                db.activeproductitems.Add(activeProdItem);
                db.SaveChanges();


                //Add productProviderPayment-right now it is for 2 help 1: PP_ID 11
                productproviderpayment ppPaymentRec = new productproviderpayment();
                ppPaymentRec.ProductProvider_ID    = 11;
                ppPaymentRec.ActiveProductItems_ID = activeProdItem.ActiveProductItems_ID;
                ppPaymentRec.Description           = "Payment to Product Provider";
                ppPaymentRec.AmountToPay           = activeProdItem.productValue;
                ppPaymentRec.hasBeenPayed          = false; //initially false
                db.productproviderpayments.Add(ppPaymentRec);
                db.SaveChanges();


                //Update the 1 voucher table, 2 voucherTransaction table-not anymore and the 3 productRedemptionLog table
                for (int i = 0; (i < vouchersList.Count) && (amountToDeduct > 0); i++)
                {
                    decimal voucherVal = vouchersList.ElementAt(i).voucherValue;

                    if (amountToDeduct > vouchersList.ElementAt(i).voucherValue)
                    {
                        //will have to finish up this small voucher, it's value becomes 0
                        //this voucher is recorded individually in the productRedemptionLog

                        vouchersList.ElementAt(i).voucherValue    = 0;
                        db.Entry(vouchersList.ElementAt(i)).State = EntityState.Modified;
                        db.SaveChanges();

                        //addVoucherTransactionLog()
                        //addVoucherTransactionLog(vouchersList.ElementAt(i).Voucher_ID, vouchersList.ElementAt(i).Voucher_ID, userID, 0, 31, voucherVal, "Voucher Redemption for Product Purchase", System.DateTime.Now);

                        //addProductRedemptionLog()
                        addProductRedemptionLog(activeProdItem.ActiveProductItems_ID, vouchersList.ElementAt(i).Voucher_ID, voucherVal);

                        //update amount to deduct: becomes less by voucher val
                        amountToDeduct -= voucherVal;
                    }

                    if (amountToDeduct <= vouchersList.ElementAt(i).voucherValue)
                    {
                        //use a part of this voucher
                        vouchersList.ElementAt(i).voucherValue    = voucherVal - amountToDeduct;
                        db.Entry(vouchersList.ElementAt(i)).State = EntityState.Modified;
                        db.SaveChanges();

                        //add voucherTransactionLog()
                        //addVoucherTransactionLog(vouchersList.ElementAt(i).Voucher_ID, vouchersList.ElementAt(i).Voucher_ID, userID, 0, 31, amountToDeduct, "Voucher Redemption for Product Purchase", DateTime.Now);

                        //add productRedemptionLog
                        addProductRedemptionLog(activeProdItem.ActiveProductItems_ID, vouchersList.ElementAt(i).Voucher_ID, amountToDeduct);

                        //update amount to deduct
                        amountToDeduct = 0;
                    }
                }//for loop

                string productName = await prodIDToProdName(productID);

                MConsumerController consumerCtrl = new MConsumerController(userID);
                consumerCtrl = await consumerCtrl.init();

                await consumerCtrl.redeemVoucher(productName, Decimal.ToInt32(prodTotalPrice));

                return(Content(HttpStatusCode.OK, activeProdItem.ActiveProductItems_ID));
            }
            return(BadRequest("Insufficient voucher total"));
        }//RedeemProduct method