//상세데이터를 뽑아오는 함수이다. public String[] MALLinfo() { MALLinfos = new string[12]; if (name == "auction") { auction = new auction("http://itempage3.auction.co.kr/DetailView.aspx?ItemNo=" + itemNum, itemNum, "auction"); MALLinfos = auction.getdatas(); mall = "옥션"; } else if (name == "gmarket") { gmarket = new gmarket("http://item2.gmarket.co.kr/Item/detailview/Item.aspx?goodscode=" + itemNum, itemNum, "gmarket"); MALLinfos = gmarket.getdatas(); mall = "G마켓"; } else if (name == "gsshop") { gsshop = new gsshop("http://www.gsshop.com/prd/prd.gs?prdid=" + itemNum, itemNum, "gsshop"); MALLinfos = gsshop.getdatas(); mall = "GSSHOP"; } else if (name == "eleven") { eleven = new eleven("http://www.11st.co.kr/product/SellerProductDetail.tmall?method=getSellerProductDetail&prdNo=" + itemNum, itemNum, "eleven"); MALLinfos = eleven.getdatas(); mall = "11번가"; } else if (name == "cjmall") { cjmall = new cjmall("http://www.cjmall.com/prd/detail_cate.jsp?item_cd=" + itemNum, itemNum, "cjmall"); MALLinfos = cjmall.getdatas(); mall = "CJmall"; } return(MALLinfos); }
private void HandleLoadAuction(auction a) { selectedAuction = a; loadParametersVM.Dispose(); ClosePage(); LoadButton.IsEnabled = false; StartButton.IsEnabled = true; }
public ActionResult ConfirmCreate(E_Commerce.Models.auctionNEW model) { log.Info("Auction/ConfirmCreate has been fired."); if (ModelState.IsValid) { DateTime curr = DateTime.Now; byte[] image = null; if (model.picture != null) { // Convert HttpPostedFileBase to byte array. image = new byte[model.picture.ContentLength]; model.picture.InputStream.Read(image, 0, image.Length); } using (var context = new AuctionsDB()) { using (var trans = context.Database.BeginTransaction(IsolationLevel.Serializable)) { try { var newAuction = new auction() { id = Guid.NewGuid(), title = model.title, duration = model.duration, startPrice = model.startPrice, currentPrice = model.startPrice, createdAt = curr, status = "READY", picture = image }; context.auction.Add(newAuction); context.SaveChanges(); trans.Commit(); } catch (Exception e) { log.Error("Error with creating auction."); trans.Rollback(); } } } return(RedirectToAction("Home", new { Message = MessageInfo.SuccessCreation })); } return(RedirectToAction("Home", new { Message = MessageInfo.RequiredFields })); }
private Auction CreateAuction(auction a) { using (kffg_simulations2Context db = new kffg_simulations2Context()) { simulation simModel = db.simulations.First(s => s.id == a.simulation_id); parameter parameters = db.parameters.First(p => p.id == simModel.parameters_id); Dictionary <string, clock_item> keyToPEA = db.clock_item.Where(ci => ci.pea_group_id == parameters.pea_group_id && ci.item_set_id == parameters.item_set_id) .ToList() .ToDictionary(ci => ForwardAuction.ProductKey(ci), ci => ci); List <bidder> bidders = db.bidders.Where(b => b.simulation_id == a.simulation_id).ToList(); IEnumerable <bidder_assigned_strategy> strats = db.bidder_assigned_strategy.Where(s => s.auction_id == a.id); statusVM = new AuctionStatusViewModel(); return(new Auction(a, keyToPEA, bidders, strats, parameters, statusVM)); } }
public ActionResult OpenConfirm(Guid idAukcije) { log.Info("Auction/OpenConfirm has been fired."); if (idAukcije == null) { log.Error("Auction/Home idAuction is null."); return(RedirectToAction("Home", new { Message = MessageInfo.ChangeUnsuccess })); } using (var context = new AuctionsDB()) { using (var trans = context.Database.BeginTransaction(IsolationLevel.Serializable)) { try { auction auction = context.auction.Find(idAukcije); if (auction == null) { throw new Exception(); } if (!auction.status.Contains("READY")) { log.Error("Auction/Home auction is not ready."); throw new Exception(); } //otvaranje auction.status = "OPENED"; auction.openedAt = DateTime.Now; auction.closedAt = DateTime.Now.AddSeconds((double)auction.duration); context.Entry(auction).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); trans.Commit(); var myHub = GlobalHost.ConnectionManager.GetHubContext <AuctionsHub>(); myHub.Clients.All.updateStatus(idAukcije); return(RedirectToAction("Home", new { Message = MessageInfo.ChangeSuccess })); } catch (Exception ex) { log.Error("Error with opening auction"); trans.Rollback(); } } } return(RedirectToAction("Home", new { Message = MessageInfo.ChangeUnsuccess })); }
public Auction( auction a, Dictionary <string, clock_item> keyToPEA, List <bidder> bidders, IEnumerable <bidder_assigned_strategy> strategies, parameter p, AuctionStatusViewModel auctionVM) { rand = new Random(a.seed); this.keyToPEA = keyToPEA; auctionModel = a; List <AuctionItem> items = CreateAuctionItems(keyToPEA.Values); this.bidders = CreateBidders(bidders, p.activity_requirement, strategies, items); forwardAuction = new SmrForwardAuction(this.bidders.ToArray(), items, p, rand); auctionStatus = new AuctionStatus(); auctionStatusVM = auctionVM; }
public string AuctionOver(Guid id) { string result = ""; auction auction = null; using (var context = new AuctionsDB()) { auction = context.auction.Find(id); } if (auction != null) { if (!auction.status.Equals("OPENED")) { result = auction.status; } else { auction.status = "COMPLETE"; result = auction.status; using (var context = new AuctionsDB()) { context.Entry(auction).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); if (result == "COMPLETE") { /* kako dodati poslednji bid?? * Bid bid = context.Bids.Find(aukcija.BidID); * Korisnik korisnik = context.Korisniks.Find(bid.KorisnikID); * * korisnik.Aukcijas.Add(auction); * context.SaveChanges(); */ } } } } return(result); }
public ActionResult Show(Guid idAukcije, MessageInfo?message) { log.Info("Auction/Show has been fired."); ViewBag.StatusMessage = message == MessageInfo.ChangeSuccess ? "Successfully opened an auction." : message == MessageInfo.ChangeUnsuccess ? "Error, something went wrong." : message == MessageInfo.AuctionFinished ? "Error, the auction is not in the READY state." : message == MessageInfo.AuctionClosed ? "Auction has been successfully closed." : message == MessageInfo.AuctionOver ? "The auction has finished." : message == MessageInfo.BidSuccess ? "Your bid has been successfully placed." : message == MessageInfo.NoTokens ? "Not enough tokens." : message == MessageInfo.RequiredFields ? "All fields are required." : message == MessageInfo.SuccessCreation ? "Auction successfully created." : ""; auction auction = null; using (var context = new AuctionsDB()) { auction = context.auction.Find(idAukcije); if (auction == null) { return(HttpNotFound()); } //dohvati bids i korisnike--izlistaj var bids = context.bid .Where(b => b.idAuction.Equals(idAukcije)) .OrderByDescending(b => b.numTokens) .Take(20); //foreachbid get user info IEnumerable <bid> allBids = bids.ToArray(); var model = new AuctionAndBidsModel { auction = auction, bids = allBids }; return(View(model)); } }
public void FinishAuction(Guid id) { //da li mora actionresult da vrati----check log.Info("Auction/FinishAuction has been fired."); if (id == null) { return; } using (var context = new AuctionsDB()) { using (var trans = context.Database.BeginTransaction(IsolationLevel.Serializable)) { try { auction auction = context.auction.Find(id); if (auction == null) { return; } if (!auction.status.Contains("OPENED")) { return; } //otvaranje auction.status = "COMPLETED"; context.Entry(auction).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); trans.Commit(); var myHub = GlobalHost.ConnectionManager.GetHubContext <AuctionsHub>(); myHub.Clients.All.closeAuction(id); } catch (Exception e) { log.Error("Error with finnishing auction(called)"); trans.Rollback(); } } } }
/* * public void ChangePrice(int? id, string newPrice) * { * * try * { * double doubleValue = Convert.ToDouble(newPrice); * Aukcija editAukcija; * * using (var context = new AukcijaEntities()) * { * editAukcija = context.Aukcijas.Find(id); * } * * if (editAukcija != null) * { * editAukcija.PocetnaCena = doubleValue; * editAukcija.TrenutnaCena = doubleValue; * } * * using (var context = new AukcijaEntities()) * { * context.Entry(editAukcija).State = System.Data.Entity.EntityState.Modified; * context.SaveChanges(); * * logger.Error("AUCTION PRICE CHANGE: AuctionID: " + editAukcija.AukcijaID + ", AuctionStatus: " + editAukcija.Status + ", AuctionStartPrice: " + editAukcija.PocetnaCena); * } * } * catch (FormatException) * { * Console.WriteLine("Unable to convert '{0}' to a Double.", newPrice); * } * catch (OverflowException) * { * Console.WriteLine("'{0}' is outside the range of a Double.", newPrice); * } * * //return RedirectToAction("Index", "Admin", new { id = id }); * } */ //not used public void OpenAuction(Guid?id) { if (id == null) { return; } try { auction auction = null; using (var context = new AuctionsDB()) { auction = context.auction.Find(id); } if (auction != null) { DateTime startTime = DateTime.Now; DateTime endTime = startTime.AddSeconds((int)auction.duration); auction.status = "OPENED"; auction.closedAt = endTime; auction.openedAt = startTime; } using (var context = new AuctionsDB()) { context.Entry(auction).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } catch (Exception) { Console.WriteLine("Unable to open auction"); } }
//To post user bids public static AuctionResponse CreateBid(AuctionRequest auctionRequest) { AuctionResponse auctionResponse = new AuctionResponse(); auctionEntities = new AuctionSystemEntities(); Model.Message.Auction auction = new Model.Message.Auction(); //Retrieve user products to check if user is bidding on own product var userproduct = auctionEntities.products.Where(c => c.id == auctionRequest.ProductId && c.customer_id == auctionRequest.CustomerId).FirstOrDefault(); if (userproduct != null) { auctionResponse.Error = new Error { Code = ErrorCodes.BidNotAllowed, Message = "Bidding on your product is not allowed" }; return(auctionResponse); } //retrieve auctions from autions table with productid to see if this is the first bid on product var dbAuctions = auctionEntities.auctions.Where(c => c.product_id == auctionRequest.ProductId).ToList(); if (dbAuctions == null || dbAuctions.Count == 0) { //Retrieve product from product table to compare the bidding price var dbProduct = auctionEntities.products.Where(c => c.id == auctionRequest.ProductId).FirstOrDefault(); if (dbProduct == null) { auctionResponse.Error = new Error { Code = ErrorCodes.ProductUnavailable, Message = "Product is not available" }; return(auctionResponse); } if (dbProduct.product_bid_price > auctionRequest.BidPrice) { auctionResponse.Error = new Error { Code = ErrorCodes.InvalidBidPrice, Message = "Bid price cannot be less than minimum bid price" }; return(auctionResponse); } auction dbAuction = new auction() { customer_id = auctionRequest.CustomerId, product_id = auctionRequest.ProductId, bid_price = auctionRequest.BidPrice, auction_datetime = auctionRequest.ProductBidTime, bidstatus_id = (int)BidStatusCode.Active, reason_id = (int)BidReasonCode.AuctionIsOpen }; auctionEntities.auctions.Add(dbAuction); auctionEntities.SaveChanges(); auction = new Model.Message.Auction() { AuctionId = dbAuction.id, ProductId = dbAuction.product_id }; auctionResponse.Auctions = new List <Model.Message.Auction>(); //add userauction object to list auctionResponse.Auctions.Add(auction); return(auctionResponse); } var currentHighestBid = dbAuctions.Max(p => p.bid_price); //check if user has product in auction table already var dbExistingAuction = auctionEntities.auctions.Where(c => c.product_id == auctionRequest.ProductId && c.customer_id == auctionRequest.CustomerId).FirstOrDefault(); if (dbExistingAuction != null) { if (auctionRequest.BidPrice < currentHighestBid) { auctionResponse.Error = new Error { Code = ErrorCodes.InvalidBidPrice, Message = "Bid price cannot be less than current highest bid price" }; return(auctionResponse); } auction = new Model.Message.Auction(); dbExistingAuction.bid_price = auctionRequest.BidPrice; auctionEntities.SaveChanges(); auction.AuctionId = dbExistingAuction.id; auction.ProductId = dbExistingAuction.product_id; auctionResponse.Auctions = new List <Model.Message.Auction>(); auctionResponse.Auctions.Add(auction); return(auctionResponse); } //compare currenthighestbid with userbid if (currentHighestBid >= auctionRequest.BidPrice) { //if user bid is less then set fault as invalid price auctionResponse.Error = new Error { Code = ErrorCodes.InvalidBidPrice, Message = "Bid price cannot be less than current highest bid" }; return(auctionResponse); } //if user bid is higher than currenthighestbid auction Auctions = new auction() { customer_id = auctionRequest.CustomerId, product_id = auctionRequest.ProductId, bid_price = auctionRequest.BidPrice, auction_datetime = auctionRequest.ProductBidTime, bidstatus_id = (int)BidStatusCode.Active, reason_id = (int)BidReasonCode.AuctionIsOpen }; auctionEntities.auctions.Add(Auctions); auctionEntities.SaveChanges(); auction = new Model.Message.Auction() { AuctionId = Auctions.id, ProductId = Auctions.product_id }; auctionResponse.Auctions = new List <Model.Message.Auction>(); auctionResponse.Auctions.Add(auction); return(auctionResponse); }
public void BidAuction(Guid auctionID, string userID, out string fullName, out string newPrice, out bool tokens, out double timeRemaining) { try { auction auction = null; User user = null; using (var context = new AuctionsDB()) { using (var trans = context.Database.BeginTransaction(IsolationLevel.Serializable)) { try { auction = context.auction.Find(auctionID); user = context.User.Find(userID); if ((auction != null) && (user != null)) { //cena da ulozimo jos jedan token int minNext = (int)(auction.currentPrice + AdminParams.T); int userMoney = (int)(user.NumberOfTokens * AdminParams.T); if ((userMoney >= minNext) && (auction.status.Contains("OPENED"))) { tokens = false; //kako korisnik da bira koliko? int price = minNext; int tokensNeeded = (int)Math.Ceiling(minNext / AdminParams.T); /* * double remaining = ((DateTime)auction.closedAt - DateTime.Now).TotalSeconds; * * DateTime newClosed = (DateTime)auction.closedAt; * if (remaining <= 10) * { * double increment = remaining * (-1); * increment += 10; * * newClosed = newClosed.AddSeconds(increment); * } * * auction.closedAt = newClosed; * timeRemaining = ((DateTime)auction.closedAt - DateTime.Now).TotalSeconds; */ timeRemaining = 1; //umanjujemo za onoliko koliko potrebno tokena user.NumberOfTokens = user.NumberOfTokens - tokensNeeded; context.Entry(user).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); bid latestBid = new bid() { id = Guid.NewGuid(), numTokens = tokensNeeded, placedAt = DateTime.Now, idUser = userID, idAuction = auctionID }; auction.bidId = latestBid.id; //mozda povecamo za 10 posto? auction.currentPrice = price; //? sta je ovo auction.bid.Add(latestBid); context.Entry(auction).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); context.bid.Add(latestBid); context.SaveChanges(); trans.Commit(); fullName = user.FirstName + " " + user.LastName; newPrice = "" + price; } else { fullName = newPrice = null; if (!auction.status.Contains("OPENED")) { tokens = false; timeRemaining = -1; } else { tokens = true; timeRemaining = 1; } } } else { fullName = newPrice = null; tokens = true; timeRemaining = -1; throw new Exception(); } } catch (Exception ex) { trans.Rollback(); fullName = newPrice = null; tokens = true; timeRemaining = -1; } } } } catch (FormatException) { fullName = newPrice = null; tokens = true; timeRemaining = -1; Console.WriteLine("Error with bidding."); } }