public ActionResult Create(HttpPostedFileBase upload, [Bind(Include = "IDimage,image,name,hint1,hint2,info,latitude,longitude")] Image image) { try { if (upload != null && upload.ContentLength > 0) { using (var reader = new System.IO.BinaryReader(upload.InputStream)) { image.image = reader.ReadBytes(upload.ContentLength); } } // image.IDimage = db.Image.Max(d => d.IDimage) + 1; if (ModelState.IsValid) { db.Image.Add(image); db.SaveChanges(); return(RedirectToAction("Index")); } }catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(image)); }
//user adding himself to the leaderboard public ActionResult CreateReg(int idgame, int iduser, decimal score, string username) { var leaderboard = new LeaderBoard { IDgame = idgame, IDuser = iduser, score = score, username = username }; db.LeaderBoard.Add(leaderboard); db.SaveChanges(); return(RedirectToAction("IndexCommon")); }
public async Task <ActionResult> SetPassword(SetPasswordViewModel model) { if (ModelState.IsValid) { var result = await UserManager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword); if (result.Succeeded) { var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); // spremi promjene također i u bazu podataka context = new Guess_WhereEntities1(); RegisteredUser u = context.RegisteredUser.First(x => x.email == user.Email); u.password = model.NewPassword.GetHashCode().ToString(); context.SaveChanges(); if (user != null) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); } return(RedirectToAction("Index", new { Message = ManageMessageId.SetPasswordSuccess })); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Create([Bind(Include = "IDgame,IDimg1,IDimg2,IDimg3,IDimg4,IDimg5,IDimg6,IDimg7")] Game game) { if (ModelState.IsValid) { db.Game.Add(game); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IDimg1 = new SelectList(db.Image, "IDimage", "name", game.IDimg1); ViewBag.IDimg2 = new SelectList(db.Image, "IDimage", "name", game.IDimg2); ViewBag.IDimg3 = new SelectList(db.Image, "IDimage", "name", game.IDimg3); ViewBag.IDimg4 = new SelectList(db.Image, "IDimage", "name", game.IDimg4); ViewBag.IDimg5 = new SelectList(db.Image, "IDimage", "name", game.IDimg5); ViewBag.IDimg6 = new SelectList(db.Image, "IDimage", "name", game.IDimg6); ViewBag.IDimg7 = new SelectList(db.Image, "IDimage", "name", game.IDimg7); return(View(game)); }
// GET: SavedGames/Create public ActionResult Create(int idgame, int iduser, decimal score) { //if a user wants to save a game he already played var saved = db.SavedGames.AsNoTracking().FirstOrDefault(x => x.IDGame == idgame); if (saved != null && saved.IDuser == iduser) { return(RedirectToAction("Edit", new { id = saved.IDSavedGame, score = score })); } var savedGame = new SavedGames { IDGame = idgame, IDuser = iduser, score = score, datePlayed = DateTime.Today.Date }; db.SavedGames.Add(savedGame); db.SaveChanges(); return(RedirectToAction("Index", iduser)); }
public ActionResult Save(HttpPostedFileBase upload) { var userId = User.Identity.GetUserId(); var userUserName = User.Identity.GetUserName(); var id = (db.User.Where(x => x.username == userUserName).First()).IDuser; var registered = db.RegisteredUser.First(x => x.IDuser == id); if (upload != null && upload.ContentLength > 0) { using (var reader = new System.IO.BinaryReader(upload.InputStream)) { registered.avatar = reader.ReadBytes(upload.ContentLength); } db.Entry(registered).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index", "Manage")); }
public async Task<ActionResult> Register(HttpPostedFileBase upload, RegisterViewModel model) { if (ModelState.IsValid) { if (upload != null && upload.ContentLength > 0) { using (var reader = new System.IO.BinaryReader(upload.InputStream)) { model.Avatar = reader.ReadBytes(upload.ContentLength); } } var user = new ApplicationUser { UserName = model.Username, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { context = new Guess_WhereEntities1(); User u = new User(); bool exist = false; foreach (var korisnik in context.User) { if (korisnik.username == model.Username) { exist = true; u.IDuser = korisnik.IDuser; break; } } if (!exist) { context.User.Add(new User { username = model.Username }); context.RegisteredUser.Add(new RegisteredUser { email = model.Email, password = model.Password.GetHashCode().ToString(), avatar = model.Avatar }); } else { context.RegisteredUser.Add(new RegisteredUser { email = model.Email, password = model.Password.GetHashCode().ToString(), avatar = model.Avatar, IDuser = u.IDuser }); } context.SaveChanges(); await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }