示例#1
0
 /// <summary>
 /// The method to calculate profit or loss.
 /// </summary>
 /// <param name="userId">The User id.</param>
 /// <returns>The profi or loss object.</returns>
 public ProfitOrLoss GetProfitOrLoss(short userId)
 {
     try
     {
         buyingTransactionRep = new BuyingTransactionRepository();
         Domain.Layer.Transactions.BuyingTransaction buyingTransaction = buyingTransactionRep.GetLastBuyingTransaction(userId);
         if (buyingTransaction != null)
         {
             productRep = new ProductRepository();
             //Hard coded the product since we have only oone product with ID as 1 now.
             if (CurrentGoldPricePerGram.Instance.currentGoldPricePerGram == null)
             {
                 CurrentGoldPricePerGram.Instance.currentGoldPricePerGram = productRep.GetProduct(buyingTransaction.ProductId).PricePerGram;
             }
             sellingTransaction = new SellingTransaction();
             return(sellingTransaction.GetProfitOrLoss(buyingTransaction));
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
        /// <summary>
        /// The method to create
        /// </summary>
        /// <param name="buyingTransaction"></param>
        /// <returns>Return true or false; true indicates the the creation is successful.</returns>
        public bool CreateBuyingTransaction(Domain.Layer.Transactions.BuyingTransaction buyingTransaction)
        {
            dbContext.BuyingTransactions.Add(MapTransaction(buyingTransaction));
            var result = dbContext.SaveChanges();

            return(result > 0 ? true : false);
        }
        private BuyingTransaction MapTransaction(Domain.Layer.Transactions.BuyingTransaction buyingTransaction)
        {
            return(new BuyingTransaction()
            {
                ProductId = buyingTransaction.ProductId,
                PurchasedDate = buyingTransaction.PurchasedDate,
                PurchasedPrice = buyingTransaction.PurchasedPrice,
                PurchasedQuantity = buyingTransaction.PurchasedQuantity,
                PurchasedRatePerGram = buyingTransaction.PurchasedRatePerGram,

                PurchasedTax = (decimal)((buyingTransaction.PurchasedPrice * DomainConstants.GST_PERCENTAGE) / 100),
                PurchasedTotalPrice = (decimal)(buyingTransaction.PurchasedPrice + ((buyingTransaction.PurchasedPrice * DomainConstants.GST_PERCENTAGE) / 100)),
                UserId = buyingTransaction.UserId,
                PurchasedTransactionId = buyingTransaction.PurchasedTransactionId
            });
        }
示例#4
0
 /// <summary>
 /// The method to create
 /// </summary>
 /// <param name="buyingTransaction"></param>
 /// <returns>Return true or false; true indicates the the creation is successful.</returns>
 public bool CreateBuyingTransaction(Domain.Layer.Transactions.BuyingTransaction buyingTransaction)
 {
     buyingTransactionRep = new BuyingTransactionRepository();
     return(buyingTransactionRep.CreateBuyingTransaction(buyingTransaction));
 }
示例#5
0
 /// <summary>
 /// The method to calculate selling price per gram.
 /// </summary>
 /// <param name="buyingRatePerGram">The base buying rate per gram.</param>
 /// <returns></returns>
 private decimal CalculateSellingPricePerGram(BuyingTransaction lastBuyingTransaction)
 {
     return((decimal)CurrentGoldPricePerGram.Instance.currentGoldPricePerGram + DomainConstants.COMMISSION_PER_GRAM + (lastBuyingTransaction.PurchasedRatePerGram * 5) / 100);
 }
示例#6
0
 /// <summary>
 /// THe main public method to expose to orchastrator.
 /// </summary>
 /// <param name="lastBuyingTransaction">The method which gives last buying transaction.</param>
 /// <returns></returns>
 public ProfitOrLoss GetProfitOrLoss(BuyingTransaction lastBuyingTransaction)
 {
     return(GetProfitOrLoss(CalculatePurchasedPricePerGram(lastBuyingTransaction.PurchasedRatePerGram), CalculateSellingPricePerGram(lastBuyingTransaction)));
 }