public string ChangeSystem([Bind(Include = "RecentAuctions,DefaultAuctionTime,SilverPackage,GoldPackage,PlatinumPackage,Currency,PriceRate")] SystemParameters parameters) { if (!ModelState.IsValid) { return("#Error: One or more parameters are not valid."); } using (var db = new AuctionHouseDB()) { try { var current = db.GetCurrentSystemParameters(); current.RecentAuctions = parameters.RecentAuctions; current.DefaultAuctionTime = parameters.DefaultAuctionTime; current.SilverPackage = parameters.SilverPackage; current.GoldPackage = parameters.GoldPackage; current.PlatinumPackage = parameters.PlatinumPackage; current.Currency = parameters.Currency; current.PriceRate = parameters.PriceRate; db.Entry(current).State = EntityState.Modified; db.SaveChanges(); return("Successfully changed parameters!"); } catch (Exception ex) { log.Error(ex.Message, ex); return("#Error: Could change parameters."); } } }
public string OrderTokens(int package) { if (Session["user"] == null) { return(string.Empty); } using (var db = new AuctionHouseDB()) { try { var parameters = db.GetCurrentSystemParameters(); decimal amount = 0; switch (package) { case 0: amount = parameters.SilverPackage; break; case 1: amount = parameters.GoldPackage; break; case 2: amount = parameters.PlatinumPackage; break; default: return("#Error: Such package does not exist."); } var order = new TokenOrder { ID = Guid.NewGuid(), Buyer = ((User)Session["user"]).ID, Amount = amount, Currency = parameters.Currency, PriceRate = parameters.PriceRate, Status = null }; try { db.TokenOrders.Add(order); db.SaveChanges(); } catch (Exception ex) { log.Error(ex.Message, ex); return("#Error: Could not initiate order. Please, try again."); } AuctionHub.HubContext.Clients.All.onTokenOrderCreated(order.Buyer.ToString(), order.ID.ToString(), order.Amount.ToString(Settings.DecimalFormat), order.Currency, order.PriceRate.ToString(Settings.DecimalFormat)); return("<a id=\"c-mobile-payment-widget\" href=\"https://stage.centili.com/payment/widget?apikey=b23180535003ba668fe3d1d2876ad928&reference=" + order.ID + "&country=rs&package=" + package + "\" target=\"_blank\"><img src=\"https://www.centili.com/images/centili-widget-button.png\"/></a>"); } catch (Exception ex) { log.Error(ex.Message, ex); return("#Error: Unknown error occured."); } } }
public ActionResult Index() { using (var db = new AuctionHouseDB()) { try { ViewBag.NavIndex = 0; ViewBag.RecentAuctions = db.GetCurrentSystemParameters().RecentAuctions; return(View(db.FindActiveAndCompletedAuctions(true))); } catch (Exception ex) { log.Error(ex.Message, ex); return(View("Error")); } } }
public ActionResult System() { if (Session["user"] == null || !(bool)Session["isAdmin"]) { return(HttpNotFound()); } using (var db = new AuctionHouseDB()) { try { ViewBag.NavIndex = 4; return(View(db.GetCurrentSystemParameters())); } catch (Exception ex) { log.Error(ex.Message, ex); return(View("Error")); } } }
public string Create(string title, int time, decimal price) { if (Session["user"] == null) { return(string.Empty); } using (var db = new AuctionHouseDB()) { try { var sysparams = db.GetCurrentSystemParameters(); if (title == null || string.IsNullOrWhiteSpace(title)) { return("#Error: Invalid title."); } if (time <= 0) { time = sysparams.DefaultAuctionTime; } if (price < 0) { return("#Error: Invalid price."); } var uploadFailed = true; var guid = Guid.NewGuid(); for (int i = 0; i < Request.Files.Count; ++i) { if (Request.Files[i].ContentType == "image/png") { Directory.CreateDirectory(Server.MapPath("~/assets/storage/auctions/" + guid.ToString() + "/")); Request.Files[i].SaveAs(Server.MapPath("~/assets/storage/auctions/" + guid.ToString() + "/" + i + ".png")); uploadFailed = false; } } if (uploadFailed) { return("#Error: You must supply at least one image."); } var user = (User)Session["user"]; var auction = new Auction { ID = guid, Title = title, AuctionTime = time, CreatedOn = DateTime.Now, OpenedOn = null, CompletedOn = null, StartingPrice = price, Currency = sysparams.Currency, PriceRate = sysparams.PriceRate, Holder = user.ID }; try { db.Auctions.Add(auction); db.SaveChanges(); } catch { return("#Error: Could not create the auction. Some of the values are invalid."); } AuctionHub.HubContext.Clients.All.onAuctionCreated(auction.ID.ToString(), auction.Title, auction.AuctionTime, auction.StartingPrice, auction.CreatedOn.ToString(Settings.DateTimeFormat), user.FirstName + " " + user.LastName); return(auction.ID.ToString()); } catch (Exception ex) { log.Error(ex.Message, ex); return("#Error: Unknown error occured."); } } }