public ActionResult ChangeProfile(FormChangeUser u) { User user = (User)Session[KeysUtils.SessionUser()]; if (!user.email.Trim().Equals(u.email) && Models.User.EmailExists(u.email)) { ModelState.AddModelError("EmailExists", "Email already exists"); } else { if (u.password == null || u.password.Trim().Equals("")) { u.password = ((User)(Session[KeysUtils.SessionUser()])).password; } else { user.password = CryptUtils.Hash(u.password); } user.email = u.email; user.first_name = u.firstName; user.last_name = u.lastName; user.saveChanges(); Session[KeysUtils.SessionUser()] = user; ViewBag.Status = true; ViewBag.Message = "Changed profile successfully"; } return(View(u)); }
public ActionResult CreateAuction(FormCreateAuction fcAuction) { User u = (User)Session[KeysUtils.SessionUser()]; if (u == null) { u = (User)Session[KeysUtils.SessionAdmin()]; if (u == null) { return(RedirectToAction("Index", "Home")); } } if (ModelState.IsValid) { Auction a = Auction.Create(fcAuction, u.user_id); a.save(); ViewBag.Status = true; ViewBag.Message = "Successfuly creaed auction"; } else { ViewBag.Message = "Invalid request"; } return(View(fcAuction)); }
public ActionResult Login(FormLoginUser luser) { User user = Models.User.getByEmail(luser.email); if (user == null) { ViewBag.Message = "Email does not exist"; } else { if (!user.ValidatePassword(luser.password)) { ViewBag.Message = "Bad password"; } else { if (user.admin_flag) { Session[KeysUtils.SessionAdmin()] = user; return(RedirectToAction("Index", "Admin")); } else { Session[KeysUtils.SessionUser()] = user; return(RedirectToAction("Index", "Home")); } } } return(View(luser)); }
public ActionResult InsertBid(Guid auction_id, int token_price) { User user = (User)Session[KeysUtils.SessionUser()]; if (user != null) { Bid bid = Bid.factoryMethod(user.user_id, auction_id, token_price + 1); bid.processBid(); } return(RedirectToAction("Index", "Home")); }
public Boolean StartAuction() { if (this.state.Equals(KeysUtils.AuctionReady())) { this.state = KeysUtils.AuctionOpened(); this.current_price = this.starting_price; this.opened = DateTime.Now; this.closed = DateTime.Now.AddMilliseconds(this.duration * 1000); return(true); } return(false); }
public ActionResult EditSystemConfig() { User u = (User)Session[KeysUtils.SessionAdmin()]; if (u == null) { return(RedirectToAction("Index", "Home")); } else { return(View(SystemConf.GetSystemConf())); } }
public ActionResult MyOrders() { User u = (User)Session[KeysUtils.SessionUser()]; if (u == null) { return(RedirectToAction("Index", "Home")); } else { List <TokenOrder> to = TokenOrder.getOrdersForUser(u.user_id); return(View(to)); } }
public ActionResult Index() { User u = (User)Session[KeysUtils.SessionAdmin()]; if (u == null) { return(RedirectToAction("Index", "Home")); } else { List <Auction> list = Auction.getReadyAuctions(); return(View(list)); } }
public ActionResult MyTokens() { User u = (User)Session[KeysUtils.SessionUser()]; if (u == null) { return(RedirectToAction("Index", "Home")); } else { u = Models.User.getById(u.user_id); ViewBag.tokens = u.tokens; return(View()); } }
public static List <Auction> Search(int?min, int?max, int?itemsPerPage, string state, string searchString) { List <Auction> la = null; using (Database db = new Database()) { string op_state = KeysUtils.AuctionReady(); la = db.Auction.Where(a => !a.state.Equals(op_state)).OrderByDescending(a => a.created).ToList(); if (!String.IsNullOrEmpty(state) && !state.Trim().Equals("Auction State")) { la = la.Where(a => a.state.Equals(state.Trim())).ToList(); } if (min != null) { la = la.Where(a => a.token_price > min).ToList(); } if (max != null) { la = la.Where(a => a.token_price < max).ToList(); } if (!String.IsNullOrWhiteSpace(searchString)) { string[] tokens = searchString.ToLower().Trim().Split(' '); foreach (string s in tokens) { la = la.Where(a => a.title.ToLower().Contains(s)).ToList(); } } if (itemsPerPage != null) { la = la.Take(itemsPerPage.GetValueOrDefault()).ToList(); } else { int tt = db.SystemConf.FirstOrDefault().mrp_group; la = la.Take(tt).ToList(); } } foreach (Auction a in la) { a.checkAuctionEnd(); } return(la); }
public void checkAuctionEnd() { if (this.state.Equals(KeysUtils.AuctionOpened())) { if (DateTime.Now > this.closed) { Bid b = Zeka.Models.Bid.LastBidForAuction(this); if (b != null) { b.winner = true; b.saveChanges(); } this.state = KeysUtils.AuctionCompleted(); this.saveChanges(); } } }
internal static void LoadConfig() { int i; String game_config_filename = String.Empty; dynamic config = JObject.Parse(File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "config.json"))); try { refresh_config_key = KeysUtils.ConvertFromString((String)config.refresh_config_key); igt_display_type = (IGTDisplayType)Enum.Parse(typeof(IGTDisplayType), (String)config.igt_display_type); if (MetroidPrime != null) { if (MetroidPrime.GetType().BaseType == typeof(Prime.Prime)) { game_config_filename = "prime.json"; } if (MetroidPrime.GetType().BaseType == typeof(Echoes.Echoes)) { game_config_filename = "echoes.json"; } if (MetroidPrime.GetType().BaseType == typeof(Corruption.Corruption)) { game_config_filename = "corruption.json"; } if (game_config_filename != String.Empty) { dynamic game_config = JObject.Parse(File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), game_config_filename))); try { pickups_to_show = new String[game_config.pickups.Count]; for (i = 0; i < game_config.pickups.Count; i++) { pickups_to_show[i] = game_config.pickups[i]; } } catch { pickups_to_show = null; } } } } catch { refresh_config_key = Key.F5; igt_display_type = IGTDisplayType.WithoutMS; pickups_to_show = null; } }
public ActionResult MyWinns() { User u = (User)Session[KeysUtils.SessionUser()]; if (u == null) { return(RedirectToAction("Index", "Home")); } else { List <Bid> ll = Bid.WonBids(u.user_id); List <Auction> la = new List <Auction>(); foreach (Bid b in ll) { la.Add(Auction.getByKey(b.auction_id)); } return(View(la)); } }
public ActionResult ChangeProfile() { User u = (User)Session[KeysUtils.SessionUser()]; if (u == null) { return(RedirectToAction("Register", "Home")); } else { FormChangeUser fcu = new FormChangeUser(); fcu.lastName = u.last_name.Trim(); fcu.firstName = u.first_name.Trim(); fcu.email = u.email; fcu.password = ""; return(View(fcu)); } }
public static Auction Create(FormCreateAuction fcAuction, Guid user_id) { Auction auction = new Auction(); auction.title = fcAuction.title; auction.starting_price = fcAuction.starting_price; auction.duration = fcAuction.duration; auction.picture = new byte[fcAuction.image.ContentLength]; fcAuction.image.InputStream.Read(auction.picture, 0, fcAuction.image.ContentLength); auction.current_price = 0; auction.created = DateTime.Now; auction.state = KeysUtils.AuctionReady(); SystemConf config = SystemConf.GetSystemConf(); auction.currency = config.currency; auction.tokenValue = config.token_value; auction.token_price = (int)Math.Ceiling(auction.starting_price / auction.tokenValue); auction.user_id = user_id; return(auction); }
public ActionResult EditSystemConfig(SystemConf conf) { User u = (User)Session[KeysUtils.SessionAdmin()]; if (u == null) { return(RedirectToAction("Index", "Home")); } else { if (ModelState.IsValid) { conf.save(); ViewBag.Status = true; ViewBag.Message = "Successfuly edited configuration"; } else { ViewBag.Message = "Invalid Request"; conf = SystemConf.GetSystemConf(); } return(View(conf)); } }
internal Keyboard(Window window) { Window = window; for (int i = 0; i < KeysUtils.MAX_KEY_INDEX; ++i) { _lastKeys[i] = _currKeys[i] = false; _lastPress[i] = _lastRelease[i] = _lastTap[i] = 0; } _keyfunc = (window, key, scancode, action, mods) => { if (action == Glfw.REPEAT) { return; } var keys = KeysUtils.Translate(key); if (keys == Keys.Unknown) { return; } handleKey(keys, scancode, action == Glfw.PRESS); }; Glfw.SetKeyCallback(window.Handle, _keyfunc); }
public ActionResult StartAuction(Guid key) { User u = (User)Session[KeysUtils.SessionAdmin()]; if (u == null) { return(RedirectToAction("Index", "Home")); } else { Auction auction = Auction.getByKey(key); if (auction != null) { auction.state = KeysUtils.AuctionOpened(); auction.current_price = auction.starting_price; DateTime t = DateTime.Now; auction.opened = t; auction.closed = t.AddSeconds(auction.duration); auction.saveChanges(); } return(RedirectToAction("Index", "Admin")); } }
public ActionResult SignOut() { Session[KeysUtils.SessionUser()] = null; Session[KeysUtils.SessionAdmin()] = null; return(RedirectToAction("Index", "Home")); }
public Boolean processBid() { object u = SynchronizationUtils.getLockOnUser(this.user_id); Boolean status; lock (u) { status = User.Pay(this.tokens, this.user_id); } if (!status) { return(false); } Bid lastBid = null; object a = SynchronizationUtils.getLockOnAuction(this.auction_id); lock (a) { Auction auction = Auction.getByKey(this.auction_id); if (auction == null || auction.state != KeysUtils.AuctionOpened() || auction.token_price > this.tokens) { status = false; } else { //TODO calculate more stuf? price in currency(cant think right now) auction.token_price = this.tokens; auction.current_price = auction.token_price * auction.tokenValue; auction.saveChanges(); lastBid = Bid.LastBidForAuction(auction); //TODO should remove last bid? this.save(); User thisUser = User.getById(this.user_id); AuctionHub.RefreshPrice(this.auction_id, thisUser.email, this.tokens, auction.currency, auction.current_price); AuctionHub.UpdateBidInsert(this.tokens, this.auction_id, thisUser.email, this.time, auction.current_price, auction.currency); status = true; } } if (status == false) { lock (u) { User.Pay(-this.tokens, this.user_id); } } else { if (lastBid != null) { object uOld = SynchronizationUtils.getLockOnUser(lastBid.user_id); lock (uOld) { User.Pay(-lastBid.tokens, lastBid.user_id); } SynchronizationUtils.returnLockOnUser(lastBid.user_id); } } SynchronizationUtils.returnLockOnUser(this.user_id); SynchronizationUtils.returnLockOnAuction(this.auction_id); return(status); }