public ActionResult Bid(BidViewModel bidView) //////////PROVERI DA LI IMAS DOVOLJNO PARA { try { if (!ModelState.IsValid) { throw new Exception("All fields must be filled correctly!"); } PartialUser logged_user = IsLoggedIn(); if (logged_user == null) { throw new Exception("Forbidden access!"); } using (AuctionHouseModel db = new AuctionHouseModel()) { Guid auction_id = new Guid(bidView.Auction_id); if (logged_user.email == db.GetAuction(auction_id).owner) { throw new Exception("You can not bid your own auction!"); } Bid last_bid = db.GetLastBid(auction_id); if (bidView.Amount <= (last_bid != null ? last_bid.amount : db.GetAuction(auction_id).starting_price)) { throw new Exception("Your bidding amount must be greater then the last one!"); } if (db.GetAvailableTokens(logged_user.email) < bidView.Amount) { throw new Exception("You have not enough tokens to procceed with the transaction!"); } Bid bid = new Bid { id = Guid.NewGuid(), auction_id = auction_id, bidder = logged_user.email, created = DateTime.Now, amount = bidView.Amount }; db.Bids.Add(bid); db.SaveChanges(); string name = logged_user.first_name + " " + logged_user.last_name; AuctionHouseHub.HubContext.Clients.All.updatebid(logged_user.email, name, bidView.Auction_id, bidView.Amount, bid.created.ToString()); } } catch (Exception error) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, error.Message)); } return(null); }
public ActionResult Approve(string id) { try { if (IsAdmin() == null) { throw new Exception("Only administrator is allowed to approve auctions!"); } using (AuctionHouseModel db = new AuctionHouseModel()) { Auction auction = db.GetAuction(new Guid(id)); auction.state = "OPENED"; auction.opened = DateTime.Now; db.SaveChanges(); // OBAVESTI SVE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! } } catch (Exception error) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, error.Message)); } return(null); }