public ViewApplication(activeproductitem prod) { this.activeProductID = prod.ActiveProductItems_ID; this.customerIDNo = prod.consumer.user.IDnumber; this.customerName = prod.consumer.user.userFirstName + " " + prod.consumer.user.userLastName; this.address = prod.consumer.consumerAddress; this.startdate = prod.activeProductItemStartDate.ToString(); this.InsurnceName = prod.product.productName; }
public async Task <DTOactiveproductitem> Postactiveproductitem(DTOactiveproductitem newDTO) { activeproductitem newProd = EntityMapper.updateEntity(null, newDTO); db.activeproductitems.Add(newProd); await db.SaveChangesAsync(); return(newDTO); }
public DTOconsumerActiveProductItems(activeproductitem prod) { productID = prod.Product_ID; productName = prod.product.productName; productDescription = prod.product.productDescription; productValue = prod.productValue; UnitDuration = prod.duration; itemStartDate = prod.activeProductItemStartDate; }
public async Task <IHttpActionResult> Putactiveproductitem(int ID, DTOactiveproductitem editedDTO) { // activeproductitem toUpdate = db.activeproductitems.Find(ID); toUpdate = EntityMapper.updateEntity(toUpdate, editedDTO); db.Entry(toUpdate).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> setIsActiveToTrue(int activeProductID) { activeproductitem toUpdate = (from c in db.activeproductitems where c.ActiveProductItems_ID == activeProductID select c).SingleOrDefault(); DTOactiveproductitem dtoAct = new DTOactiveproductitem(toUpdate); dtoAct.isActive = true; toUpdate = EntityMapper.updateEntity(toUpdate, dtoAct); db.Entry(toUpdate).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
private activeproductitem createActiveProductItem(int ConsumerID, int ProductID, string policyNum, bool isActive, decimal productValue, int duration, DateTime startDate, DateTime endDate) { activeproductitem activeProdItem = new activeproductitem(); activeProdItem.Consumer_ID = ConsumerID; activeProdItem.Product_ID = ProductID; activeProdItem.activeProductItemPolicyNum = policyNum; activeProdItem.isActive = isActive; activeProdItem.productValue = productValue; activeProdItem.duration = duration; activeProdItem.activeProductItemStartDate = startDate; activeProdItem.activeProductItemEndDate = endDate; return(activeProdItem); }
public async Task <IHttpActionResult> updateInsuranceProviderPaymentStatus(int ppID) { //list of what has not been paid to this productProvider: List <productproviderpayment> paymentsNotMadeList = (from c in db.productproviderpayments where c.hasBeenPayed == false && c.ProductProvider_ID == ppID select c).ToList(); //Note isActive and Expiry are not too relevant here: should still pay if a product has expired. //never be paid if a refund was made: ie purchase rejected. foreach (productproviderpayment p in paymentsNotMadeList) { activeproductitem activeProdRelatedToPayment = (from a in db.activeproductitems where a.ActiveProductItems_ID == p.ActiveProductItems_ID select a).SingleOrDefault(); if (activeProdRelatedToPayment.Accepted == true)//this product purchase has gone through so the IM should get paid { p.hasBeenPayed = true; db.Entry(p).State = EntityState.Modified; await db.SaveChangesAsync(); } else if (activeProdRelatedToPayment.Accepted == false) //product purchase rejected: Refund so the IM won't get paid { p.hasBeenPayed = false; db.Entry(p).State = EntityState.Modified; await db.SaveChangesAsync(); } else // IM has not accepted/rejected the product. //Check if date has passed - if yes pay IM. This assumes the rule: consumer covered by Product Provider unless IM rejects { if (hasDateExpired(activeProdRelatedToPayment.activeProductItemEndDate) == true) { activeProdRelatedToPayment.Accepted = true; activeProdRelatedToPayment.isActive = false; db.Entry(activeProdRelatedToPayment).State = EntityState.Modified; await db.SaveChangesAsync(); p.hasBeenPayed = true; db.Entry(p).State = EntityState.Modified; await db.SaveChangesAsync(); } else { p.hasBeenPayed = false; db.Entry(p).State = EntityState.Modified; await db.SaveChangesAsync(); } } } return(StatusCode(HttpStatusCode.OK)); }
public async Task <IHttpActionResult> ProcessInsuranceProduct(ProcessedInsuranceProd prod) { activeproductitem temp = await db.activeproductitems.SingleAsync(c => c.product.ProductProvider_ID == prod.providerID && c.ActiveProductItems_ID == prod.activeproductID); Boolean toreturn = false; if (temp != null) { temp.isActive = true; temp.activeProductItemPolicyNum = prod.policyNo; await db.SaveChangesAsync(); toreturn = true; } return(Ok(toreturn)); }
public static activeproductitem updateEntity(activeproductitem entityObjct, DTOactiveproductitem dto) { if (entityObjct == null) { entityObjct = new activeproductitem(); } entityObjct.ActiveProductItems_ID = dto.ActiveProductItems_ID; entityObjct.Consumer_ID = dto.Consumer_ID; entityObjct.Product_ID = dto.Product_ID; entityObjct.activeProductItemPolicyNum = dto.activeProductItemPolicyNum; entityObjct.isActive = dto.isActive; entityObjct.Accepted = dto.Accepted; entityObjct.productValue = dto.productValue; entityObjct.duration = dto.duration; entityObjct.activeProductItemStartDate = dto.activeProductItemStartDate; entityObjct.transactionlocation = dto.transactionlocation; entityObjct.activeProductItemEndDate = dto.activeProductItemEndDate; entityObjct.PurchaseConfirmationDocPath = dto.PurchaseConfirmationDocPath; return(entityObjct); }
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
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.Consumer_ID).FirstOrDefault(); activeproductitem activeProdItem = createActiveProductItem(consumerID, productID, "", true, prodTotalPrice, numberUnits, startdate); db.activeproductitems.Add(activeProdItem); db.SaveChanges(); //Update the 1 voucher table, 2 voucherTransaction table 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; await db.SaveChangesAsync(); //addVoucherTransactionLog() //addVoucherTransactionLog(vouchersList.ElementAt(i).Voucher_ID, vouchersList.ElementAt(i).Voucher_ID, userID, 0, 31, voucherVal, "Voucher Redemption for Product Purchase", startdate); //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; await db.SaveChangesAsync(); //add voucherTransactionLog() //addVoucherTransactionLog(vouchersList.ElementAt(i).Voucher_ID, vouchersList.ElementAt(i).Voucher_ID, userID, 0, 31, amountToDeduct, "Voucher Redemption for Product Purchase", startdate); //add productRedemptionLog addProductRedemptionLog(activeProdItem.ActiveProductItems_ID, vouchersList.ElementAt(i).Voucher_ID, amountToDeduct); //update amount to deduct amountToDeduct = 0; } }//for loop return(StatusCode(HttpStatusCode.OK)); } return(BadRequest("Insufficient voucher total")); }//RedeemProduct method