Exemplo n.º 1
0
        public ActionResult TransactionSuccessful(string trxref, string reference)
        {
            Transaction Transaction      = new Transaction();
            string      UserId           = LoggedInUser.Id.ToString();
            List <Cart> CartTransactions = CartRepo.GetAll(x => x.CustomerId == UserId).ToList();

            foreach (var item in CartTransactions)
            {
                TransactionRepo.Add(new Transaction()
                {
                    AuctioneeId       = UserId,
                    BatchId           = item.Auction.BatchId,
                    BulkPurchase      = false,
                    DateOfTransaction = DateTime.Now,
                    Quantity          = item.Quantity,
                    TransactionType   = TransactionType.Auction,
                    TotalCost         = item.Auction.AuctionPrice * item.Quantity,
                });

                Batch batch = BatchRepo.Get(x => x.Id == item.Auction.BatchId);
                batch.QuantityAuctioned += item.Quantity;
                BatchRepo.Update(batch);
            }

            Guid[] ids = CartTransactions.Select(x => x.Id).ToArray();

            foreach (var item in ids)
            {
                CartRepo.Delete(item);
            }



            return(View());
        }
Exemplo n.º 2
0
 public ActionResult Update(int id)
 {
     ViewBag.Technology   = new SelectList(TechnologyRepo.All(null), "id", "name");
     ViewBag.Trainer      = new SelectList(TrainerRepo.All(null), "id", "name");
     ViewBag.BootcampType = new SelectList(BootcampTypeRepo.All(), "id", "name");
     ViewBag.Room         = new SelectList(RoomRepo.All(), "id", "name");
     return(PartialView("_Update", BatchRepo.Get(id)));
 }
Exemplo n.º 3
0
        public double ProfitForBatch(Guid BatchId, Boolean IsDiscount)
        {
            Batch   Batch              = BatchRepo.Get(x => x.Id == BatchId);
            Product Product            = Batch.Product;
            double  DiscountPercentage = Product.BulkPurchaseDiscountPercent;
            double  ProfitForBatch     = Batch.SellingPrice - Batch.PurchasePrice;

            return(IsDiscount == false? ProfitForBatch : ProfitForBatch - (Batch.SellingPrice * (DiscountPercentage / 100)));
        }
Exemplo n.º 4
0
        public double ExpectedProfitForBatch(Guid batchId)
        {
            double ExpectedProfit = 0;
            Batch  Batch          = BatchRepo.Get(x => x.Id == batchId);

            if (Batch != null)
            {
                ExpectedProfit = Batch.SellingPrice * Batch.QuantityPurchased - Batch.PurchasePrice * Batch.QuantityPurchased;
            }
            return(ExpectedProfit);
        }
Exemplo n.º 5
0
        public double CalculateProfitLossForBatch(Guid batchId)
        {
            Batch  Batch         = BatchRepo.Get(x => x.Id == batchId);
            double PurchasePrice = Batch.PurchasePrice;
            double Value         = 0;

            Batch.Transactions.ToList().ForEach(m => {
                Value += ProfitForTransaction(m);
            });

            return(Value);
        }
        //MessedUp Code...Logic shouldnt have write actions to database
        public async Task <Transaction> AddSalesTransactionAsync(Transaction model, string agentId)
        {
            Transaction TransactionRecord = model;
            Batch       Batch             = BatchRepo.Get(c => c.Id == model.BatchId);
            Product     Product           = Batch.Product;

            if (TransactionRecord.BulkPurchase)
            {
                TransactionRecord.Quantity *= Product.QuantityPerCarton;
                TransactionRecord.TotalCost = TransactionRecord.Quantity * Batch.SellingPrice * ((100 - Product.BulkPurchaseDiscountPercent) / 100);
            }
            else
            {
                TransactionRecord.TotalCost = TransactionRecord.Quantity * Batch.SellingPrice;
            }
            TransactionRecord.AgentId         = agentId;
            TransactionRecord.TransactionType = TransactionType.Sale;
            Batch.QuantitySold += TransactionRecord.Quantity;

            await BatchRepo.UpdateAsync(Batch);

            return(await TransactionRepo.AddAsync(TransactionRecord));
        }