public static IdentityResult CreateUser(User userModel, ref int id) { AuctionContext db = new AuctionContext(); // Validate model // check if there is a user with the same login and password var IsExist = db.User.Any(item => item.Password == userModel.Password && item.Login == userModel.Login); if (IsExist) { throw new BadRequestException("there is a user with the same login and password"); } // Register new user db.User.Add(userModel); db.SaveChanges(); // Get User_id of created user id = db.User.OrderByDescending(item => item.UserId).Select(item => item.UserId).FirstOrDefault(); // Create default user configuration with default fields User_Configuration localConfiguration = new User_Configuration(); localConfiguration.UserId = (short)id; localConfiguration.AuctionFinished = false; localConfiguration.BidPlacedHigher = false; localConfiguration.BidWinLot = false; db.User_Configuration.Add(localConfiguration); db.SaveChanges(); IdentityResult result = new IdentityResult(); return(result); }
public IActionResult register(RegisterViewModel registerVM) { if (ModelState.IsValid) { User user = new User { Name = registerVM.Name, Alias = registerVM.Alias, Email = registerVM.Email, Password = registerVM.Password, }; //Hashed Password PasswordHasher <User> Hasher = new PasswordHasher <User>(); user.Password = Hasher.HashPassword(user, user.Password); //Save to DB _context.Add(user); _context.SaveChanges(); //set userid into session HttpContext.Session.SetInt32("user_id", user.UserId); return(RedirectToAction("Home")); } return(View("Index")); }
public ActionResult Bid(Bid bid) { AuctionContext context = new AuctionContext(); var auction = db.Auctions.Find(bid.AuctionId); if (auction == null) { ModelState.AddModelError("AuctionId", "Auction not found!"); } else if (auction.CurrentPrice >= bid.Amount) { ModelState.AddModelError("Amount", "Bid amount must exceed current bid"); } else { bid.Username = User.Identity.Name; auction.Bids.Add(bid); auction.CurrentPrice = bid.Amount; db.SaveChanges(); } if (!Request.IsAjaxRequest()) { return(RedirectToAction("Auction", new { id = bid.AuctionId })); } return(Json(new { CurrentPrice = bid.Amount.ToString("C"), BidCount = auction.BidCount })); }
public IActionResult Dashboard() { if (HttpContext.Session.GetInt32("UserId") == null) { return(RedirectToAction("Index", "User")); } User CurrentUser = _context.Users.SingleOrDefault(user => user.UserId == HttpContext.Session.GetInt32("UserId")); List <AuctionItem> AllItems = _context.AuctionItems .Include(i => i.Bids) .ThenInclude(b => b.User) .Include(i => i.User) .OrderBy(i => i.EndDate) .ToList(); foreach (var item in AllItems) { if (item.EndDate == DateTime.Now) { foreach (var bid in item.Bids) { Bid HighestBid = _context.Bids .Include(b => b.User) .Include(b => b.AuctionItem).OrderByDescending(b => b.Amount) .SingleOrDefault(b => b.ItemId == item.ItemId); HighestBid.User.Wallet -= HighestBid.Amount; _context.SaveChanges(); } } } ViewBag.UserId = HttpContext.Session.GetInt32("UserId"); ViewBag.AllItems = AllItems.Where(i => i.EndDate > DateTime.Now); ViewBag.CurrentUser = CurrentUser; ViewBag.CurrentDate = DateTime.Now.Date; return(View()); }
public IActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { if (_context.users.SingleOrDefault(user => user.UserName == model.UserName) == null) { User NewUser = new User { FirstName = model.FirstName, LastName = model.LastName, UserName = model.UserName, Password = model.Password }; PasswordHasher <User> Hasher = new PasswordHasher <User>(); NewUser.Password = Hasher.HashPassword(NewUser, NewUser.Password); _context.Add(NewUser); _context.SaveChanges(); User CurrentUser = _context.users.SingleOrDefault(user => user.UserName == NewUser.UserName); HttpContext.Session.SetString("loggedin", "yes"); HttpContext.Session.SetString("username", NewUser.UserName); return(RedirectToAction("Home")); } else { ViewBag.error = "UserName Already in use"; return(View("Index")); } } else { return(View("Index")); } }
public void SaveItemNames(IDictionary <long, string> itemNames) { var items = itemNames.Select(x => new Item(x.Key, x.Value)).ToList(); _itemRepository.Save(items); _auctionContext.SaveChanges(); }
public IActionResult Register(PersonViewModel model) { if (ModelState.IsValid) { Person newUser = new Person { firstName = model.firstName, lastName = model.lastName, userName = model.userName, created_at = DateTime.Now, updated_at = DateTime.Now, wallet = 1000 }; PasswordHasher <Person> hasher = new PasswordHasher <Person>(); newUser.password = hasher.HashPassword(newUser, model.password); context.Add(newUser); context.SaveChanges(); HttpContext.Session.SetInt32("currentUserId", newUser.id); HttpContext.Session.SetString("currentUserName", newUser.firstName); return(RedirectToAction("Dash")); } else { return(View(model)); } }
public ActionResult Create(Listing listing, HttpPostedFileBase file) { if (ModelState.IsValid) { listing.UserID = Convert.ToInt32(Session["CurrentUserID"]); listing.User = db.Users.FirstOrDefault(u => u.UserID == listing.UserID); listing.StartTimestamp = DateTime.Now; if (file != null) { string FileName = System.IO.Path.GetFileName(file.FileName); string FileExtension = FileName.Substring(FileName.IndexOf(".")); string FinalFileName = listing.Title + FileExtension; string Path = System.IO.Path.Combine( Server.MapPath("~/Content/Images"), FinalFileName); file.SaveAs(Path); listing.ImageUrl = Url.Content("~/Content/Images/") + FinalFileName; } db.Listings.Add(listing); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserID = new SelectList(db.Users, "UserID", "Username", listing.UserID); return(View(listing)); }
public IActionResult ChangeProfile(ChangeProfile model) { CountScore(); if (ModelState.IsValid) { var changeUser = db.Users.FirstOrDefault(u => u.Id == currentProfile.Id); if (changeUser != null) { changeUser.Name = model.Name; changeUser.Nickname = model.Nickname; changeUser.Email = model.Email; changeUser.Password = model.Password ?? changeUser.Password; db.SaveChanges(); if (currentProfile.Nickname != model.Nickname) { return(RedirectToAction("Login", "Account")); } else { return(RedirectToAction("Lots", "Home")); } } else { ModelState.AddModelError("", "Ошибка авторизации"); } } return(ChangeProfile()); }
public IActionResult CreateAuction(FormViewModel model) { if (model.bid <= 0) { TempData["bid_error"] = "Starting bid must be higher than 0!"; return(View("newauction")); } if (model.end_date <= DateTime.Now) { TempData["date_error"] = "Only future dates!"; return(View("newauction")); } if (ModelState.IsValid) { Product newProduct = new Product { name = model.name, description = model.description, end_date = model.end_date, bid = model.bid, sellerid = (int)HttpContext.Session.GetInt32("current_userid") }; _context.products.Add(newProduct); _context.SaveChanges(); return(RedirectToAction("Dashboard")); } return(View("newauction")); }
public IActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { User n = _context.Users.Where(x => x.UserName == model.UserName).SingleOrDefault(); if (n == null) { User NewUser = new User(); NewUser.FirstName = model.FirstName; NewUser.LastName = model.LastName; NewUser.UserName = model.UserName; NewUser.Password = model.Password; _context.Users.Add(NewUser); _context.SaveChanges(); HttpContext.Session.SetInt32("Userid", NewUser.Userid); return(Redirect($"Dash/{NewUser.Userid}")); } else { TempData["Error"] = "UserName Already Taken"; return(View("Index")); } } else { return(View("Index")); } }
//public ActionResult Create([Bind(Include = "ID,BuyerID,ItemID,Timestamp,Price")] Bid bid) public ActionResult Create(int BuyerID, int ItemID, float Price) { Bid NewBid = new Bid(); if (ModelState.IsValid) { NewBid.BuyerID = BuyerID; NewBid.ItemID = ItemID; NewBid.Price = Price; NewBid.Timestamp = DateTime.Now; //Item.Timestamp = DateTime.Now; // ViewBag.NewBid = NewBid; db.Bids.Add(NewBid); db.SaveChanges(); //db.Bids.Add(bid); //db.SaveChanges(); return(RedirectToAction("Index", "Home")); } ViewBag.BuyerID = new SelectList(db.Buyers, "ID", "Name", NewBid.BuyerID); ViewBag.ItemID = new SelectList(db.Items, "ID", "Name", NewBid.ItemID); return(View(NewBid)); }
public IActionResult Auct(RegisterAuctModel model) { int? Int = HttpContext.Session.GetInt32("Userid"); User Cur = _context.Users.Include(b => b.Bids).ThenInclude(w => w.Auction).Where(c => c.Userid == (int)Int).SingleOrDefault(); ViewBag.Userid = Cur.Userid; if (ModelState.IsValid) { if (model.StartingBid < 1) { TempData["Error"] = "Starting bid must be greater than 0"; return(View("NewAuction")); } if (DateTime.Now > model.EndDate) { TempData["Error"] = "EndDate Can't be in the past"; return(View("NewAuction")); } Auction New = new Auction(); New.ProductName = model.ProductName; New.Description = model.Description; New.StartingBid = model.StartingBid; New.Creator = Cur.UserName; New.EndDate = model.EndDate; _context.Auctions.Add(New); _context.SaveChanges(); return(Redirect($"/Dash/{Cur.Userid}")); } return(View("NewAuction")); }
public ActionResult Create([Bind(Include = "Id,Name,EmailAddress,MobailNumber,Address")] PersonalInformation personalInformation) { if (ModelState.IsValid) { db.PersonalInformations.Add(personalInformation); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(personalInformation)); }
public ActionResult Create([Bind(Include = "CateparentID,CateparentName")] Cateparent cateparent) { if (ModelState.IsValid) { db.Cateparents.Add(cateparent); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cateparent)); }
public ActionResult Create([Bind(Include = "Id,AuctionId,Timestamp,Username,Amount")] Bid bid) { if (ModelState.IsValid) { db.Bids.Add(bid); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bid)); }
public ActionResult CreateItem([Bind(Include = " Name, Description, SellerID")] Item item) { if (ModelState.IsValid) { db.Items.Add(item); db.SaveChanges(); return(RedirectToAction("ListItems")); } return(View(db.Sellers)); }
public ActionResult Create([Bind(Include = "Id,Name,EmailAddress,MobailNumber,TextDescription")] Contact contact) { if (ModelState.IsValid) { db.Contacts.Add(contact); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contact)); }
public ActionResult Create([Bind(Include = "CateID,CateName,CateparentID")] Cate cate) { if (ModelState.IsValid) { db.Cates.Add(cate); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CateparentID = new SelectList(db.Cateparents, "CateparentID", "CateparentName", cate.CateparentID); return(View(cate)); }
public ActionResult Create([Bind(Include = "ID,Name,Description,Seller")] Item item) { if (ModelState.IsValid) { db.Items.Add(item); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Seller = new SelectList(db.Sellers, "ID", "Name", item.Seller); return(View(item)); }
public ActionResult Create([Bind(Include = "ID,NAME,DECRIPTION,SELLER")] ITEM iTEM) { if (ModelState.IsValid) { db.ITEMs.Add(iTEM); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SELLER = new SelectList(db.SELLERs, "ID", "NAME", iTEM.SELLER); return(View(iTEM)); }
public IActionResult Dashboard() { // check if user is logged in if (ActiveUser == null) { return(RedirectToAction("Index", "Home")); } // now we check to see if any auctions should be closed TimeSpan Zero = new TimeSpan(0, 0, 1); List <Auction> AllAuctions = _context.auctions.Where(a => a.auction_status == "active").ToList(); foreach (Auction auc in AllAuctions) { TimeSpan current = auc.end_date.Subtract(DateTime.Now); if (current > Zero) { auc.time_remaining = current.Days; _context.SaveChanges(); } else { auc.time_remaining = Zero.Days; auc.auction_status = "closed"; //now that auction is closed lets find out who submitted the winning bid User seller = _context.users.SingleOrDefault(u => u.userid == auc.userid); List <Bid> winning_bid = _context.bids.Where(b => b.auctionid == auc.auctionid) .Where(b => b.amount == auc.top_bid).ToList(); Bid winner_bid = winning_bid[0]; User winner = _context.users.SingleOrDefault(u => u.userid == winner_bid.userid); //now lets update the wallets seller.wallet = seller.wallet + winner_bid.amount; winner.wallet = winner.wallet - winner_bid.amount; _context.SaveChanges(); } } return(View(new ShowAuctions { User = ActiveUser, OpenAuctions = _context.auctions.OrderBy(a => a.time_remaining) .Where(a => a.auction_status == "active") .Include(a => a.user) .Include(a => a.bids).ToList() })); }
public ActionResult Create([Bind(Include = "ITEMID,ITEMNAME,ITEMDESC,SELLERID")] Item item) { if (ModelState.IsValid) { db.Items.Add(item); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ITEMID = new SelectList(db.Bids, "ITEMID", "ITEMID", item.ItemID); ViewBag.SELLERID = new SelectList(db.Sellers, "SELLERID", "SELLERNAME", item.SellerID); return(View(item)); }
public ActionResult BidCreate([Bind(Include = "ID,ItemID,Buyer,Price,TimeStamp")] Bid bid) { if (ModelState.IsValid) { db.Bids.Add(bid); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Buyer = new SelectList(db.Buyers, "Name", "Name", bid.Buyer); ViewBag.ItemID = new SelectList(db.Items, "ID", "Name", bid.ItemID); return(View(bid)); }
public ActionResult IsCheckCars(int id) { var car = db.Cars.Find(id); if (car != null) { car.IsCheck = true; db.Entry(car).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("UnchecktedCars")); } return(HttpNotFound()); }
public IActionResult Register(User newUserAttempt) { //check modelstate if (ModelState.IsValid) { //check if username has been used User testName = context.Users.FirstOrDefault(u => u.Username == newUserAttempt.Username); if (testName == null) { //Hash password PasswordHasher <User> hasher = new PasswordHasher <User>(); newUserAttempt.Password = hasher.HashPassword(newUserAttempt, newUserAttempt.Password); //set created_at and updated_at newUserAttempt.Created_At = DateTime.Now; newUserAttempt.Updated_At = DateTime.Now; //add user to DB and savechanges context.Users.Add(newUserAttempt); context.SaveChanges(); //set session id HttpContext.Session.SetInt32("UserId", newUserAttempt.Id); //send to home return(RedirectToAction("Home")); } else { ModelState.AddModelError(string.Empty, "Username is already taken, please try again."); } } return(View("logreg")); }
public ActionResult Create(User user) { if (ModelState.IsValid) { if (!db.Users.Any(u => u.Username == user.Username)) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } } return(View(user)); }
public void UpdateItems() { HtmlWeb web = new HtmlWeb(); List <string> NewItemList = new List <string>(); List <ItemClass> NewItems = new List <ItemClass>(); string[] a = new[] { "head", "body", "weapon", "hands", "feet", "amulet", "consumable" }; HtmlDocument doc; HtmlEntity util; foreach (var i in a) { doc = web.Load($"https://www.roshpit.ca/items?slot={i}"); HtmlNodeCollection items = doc.DocumentNode.SelectNodes($"//div[@id={Strings.Chr(34)}item-table-container{Strings.Chr(34)}]//a"); foreach (var it in items) { NewItemList.Add(it.GetAttributeValue("href", "none")); } } foreach (var it in NewItemList) { NewItems.Add(LoadItem($"https://www.roshpit.ca/{it}")); System.Threading.Thread.Sleep(500); } using (AuctionContext myx = new AuctionContext()) { myx.Items.AddRange(NewItems); myx.SaveChanges(); } }
public void LoadGlyphsData(string link, string hero) { HtmlWeb web = new HtmlWeb(); HtmlDocument doc = web.Load(link); HtmlNodeCollection imgs = doc.DocumentNode.SelectNodes($"//div[@class={Strings.Chr(34)}glyph_container{Strings.Chr(34)}]"); List <ItemClass> Itemlist = new List <ItemClass>(); foreach (HtmlNode img in imgs) { Itemlist.Add(new ItemClass() { Name = System.Net.WebUtility.HtmlDecode(img.ChildNodes[1].GetAttributeValue("data-glyph-name", "Unknown")), Rarity = System.Net.WebUtility.HtmlDecode(img.ChildNodes[1].GetAttributeValue("data-rarity-color", "Unknown")), Slot = "Glyph", Image = img.ChildNodes[3].GetAttributeValue("src", "Unknown"), Special_Ability_Description = System.Net.WebUtility.HtmlDecode(img.ChildNodes[1].GetAttributeValue("data-glyph-description", "Unknown").Replace("<font color='#CCFF66'>", "**").Replace("</font>", "**").Replace("'", "'").Replace("<font color="#EF4126">", "**").Replace("<font color="#87D9FF">", "**").Replace("<font color="#C25DFC">", "**").Replace("<font color="#5CCDF9">", "**").Replace("<font color="#69BC71">", "**").Replace("color="#DDDDDD">", "**").Replace("<font color="#B5FFB7">", "**")), AlternativeName = img.ChildNodes[3].GetAttributeValue("src", "Unknown").Replace("https://s3-us-west-2.amazonaws.com/roshpit-assets/glyphs/", "").Replace(".png", ""), Required_level = img.ChildNodes[1].GetAttributeValue("data-required-level", "Unknown"), Special_Ability = hero }); } using (AuctionContext a = new AuctionContext()) { a.Items.AddRange(Itemlist); a.SaveChanges(); } }
public bool SetWinnersForProducts() { var expiredProducts = ProductController.Instance().GetExpiredProductsIds(); using (var db = new AuctionContext()) { var bids = db.Bids .Where(b => expiredProducts.Contains(b.ProductId)) .ToList(); if (bids.Count == 0) { return(false); } foreach (var productId in expiredProducts) { var currentBids = bids .Where(b => b.ProductId == productId) .ToList(); // remove this and include the where in first or default below var lastBidder = currentBids .OrderByDescending(r => r.DateOfCreated) // or coins doesn't matter .Take(1) .FirstOrDefault(); lastBidder.IsWon = true; } db.SaveChanges(); } return(true); }