示例#1
0
 /// <summary>
 /// add a sale
 /// </summary>
 /// <param name="Sale"></param>
 public static void AddSale(Sale Sale)
 {
     using (var model = new KreationModel())
     {
         model.Sales.Add(Sale);
         model.SaveChanges();
     }
 }
示例#2
0
 /// <summary>
 ///
 /// </summary>
 /// <returns>List of saved sales</returns>
 public List <Sale> GetCartList()
 {
     using (var model = new KreationModel())
     {
         Cart cart = model.Carts.FirstOrDefault(i => i.Id == this.Id);
         return(cart.Sales.ToList());
     }
 }
示例#3
0
 /// <summary>
 /// method to add a seller
 /// </summary>
 /// <param name="Seller"></param>
 public static void AddSeller(Seller Seller)
 {
     using (var model = new KreationModel())
     {
         model.Sellers.Add(Seller);
         model.SaveChanges();
     }
 }
示例#4
0
 /// <summary>
 /// add a product
 /// </summary>
 /// <param name="Product"></param>
 public static void AddProduct(Product Product)
 {
     using (var model = new KreationModel())
     {
         model.Products.Add(Product);
         model.SaveChanges();
     }
 }
示例#5
0
 /// <summary>
 /// method to add an auction to the website
 /// </summary>
 /// <param name="Auction"></param>
 public static void AddAuction(Auction Auction)
 {
     using (var model = new KreationModel())
     {
         model.Auctions.Add(Auction);
         model.SaveChanges();
     }
 }
示例#6
0
 /// <summary>
 /// method to add an order to the website
 /// </summary>
 /// <param name="Order"></param>
 public static void AddOrder(Order Order)
 {
     using (var model = new KreationModel())
     {
         model.Orders.Add(Order);
         model.SaveChanges();
     }
 }
示例#7
0
 /// <summary>
 /// method to add a review to the website
 /// </summary>
 /// <param name="buyer"></param>
 public static void AddReview(Review Review)
 {
     using (var model = new KreationModel())
     {
         model.Reviews.Add(Review);
         model.SaveChanges();
     }
 }
示例#8
0
 /// <summary>
 /// method to add a Buyer to the website
 /// </summary>
 /// <param name="buyer"></param>
 public static void AddBuyer(Buyer Buyer)
 {
     using (var model = new KreationModel())
     {
         model.Buyers.Add(Buyer);
         model.SaveChanges();
     }
 }
示例#9
0
 /// <summary>
 /// add a cart to the database
 /// </summary>
 /// <param name="Cart"></param>
 public static void AddCart(Cart Cart)
 {
     using (var model = new KreationModel())
     {
         model.Carts.Add(Cart);
         model.SaveChanges();
     }
 }
示例#10
0
 /// <summary>
 /// constructor to create a cart for specific buyer
 /// </summary>
 /// <param name="BuyerId">integer of the buyer id</param>
 public Cart(int BuyerId)
 {
     using (var model = new KreationModel())
     {
         Buyer buyer = model.Buyers.FirstOrDefault(i => i.Id == BuyerId);;
         this.Buyer   = buyer;
         this.BuyerId = BuyerId;
     }
 }
示例#11
0
 /// <summary>
 /// update the database in the end of the auction to store the winning bid id
 /// </summary>
 public void GetWinningBid()
 {
     using (var model = new KreationModel())
     {
         Auction auction = (from Auction in model.Auctions where Auction.Id == this.Id select Auction).Single();
         auction.WinningBidId = this.GetCurrentHighestBidId();
         model.SaveChanges();
     }
 }
示例#12
0
 /// <summary>
 /// add a sale to a specific cart
 /// </summary>
 /// <param name="CartId">integer id of the cart to add sale to</param>
 /// <param name="SaleId">integer id of the sale to be added</param>
 public static void AddToCart(int CartId, int SaleId)
 {
     using (var model = new KreationModel())
     {
         Cart cart = model.Carts.FirstOrDefault(i => i.Id == CartId);
         Sale sale = model.Sales.FirstOrDefault(i => i.Id == SaleId);
         cart.Sales.Add(sale);
         model.SaveChanges();
     }
 }
示例#13
0
        /// <summary>
        /// add a bid to the auction, it checks whether the bid price is larger than the current highest bid plus
        /// the minimum increment, if it is larger, add the bid to Bids table and update the current highest bid;
        /// if it is less, bid will not be added to be Bids table and console will write error
        /// </summary>
        /// <param name="Bid"></param>
        public static void AddBid(Bid Bid)
        {
            int AuctionId = Bid.AuctionId; //get the id of the auction that the bid is to go to

            using (var model = new KreationModel())
            {
                int     HighestBidId    = model.Auctions.Where(a => a.Id == AuctionId).Single().GetCurrentHighestBidId();       //get the id of the highest bid in this auction
                decimal HighestBidPrice = model.Bids.Where(b => b.Id == HighestBidId).Single().BidPrice;                        //get the price of the highest bid
                decimal MinBid          = model.Auctions.Where(a => a.Id == AuctionId).Single().MinIncrement + HighestBidPrice; //calculate the min bid price acceptable, considering the min increment

                if (Bid.BidPrice >= MinBid)
                {
                    model.Bids.Add(Bid);
                    model.SaveChanges();
                }
                else
                {
                    System.Console.WriteLine("You need to bid more than " + MinBid + " dollars.");
                }
            }
        }