public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, model.FirstName));
                    var db = new ApplicationDbContext();
                    var userBookRelation = new UserBookRelation {
                        ApplicationUserId = user.Id, FirstName = model.FirstName, LastName = model.LastName, BookId = -1, CreatedAt = DateTime.Now.ToString(), UpdatedAt = DateTime.Now.ToString()
                    };
                    db.UserBookRelation.Add(userBookRelation);
                    db.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));
        }
Ejemplo n.º 2
0
 public IActionResult thisbook_likebook(UserBookRelation NewRelation, int IdBook)
 {
     NewRelation.UserId = (int)HttpContext.Session.GetInt32("UserInSession");
     NewRelation.BookId = IdBook;
     dbContext.Add(NewRelation);
     dbContext.SaveChanges();
     return(Redirect("/thisbook/" + IdBook));
 }
Ejemplo n.º 3
0
        public IActionResult thisbook_unlikebook(int IdBook)
        {
            UserBookRelation toDelete = dbContext.UserBookRelations
                                        .Where(R => R.BookId == IdBook)
                                        .FirstOrDefault(Us => Us.UserId == (int)HttpContext.Session.GetInt32("UserInSession"));

            dbContext.Remove(toDelete);
            dbContext.SaveChanges();
            return(Redirect("/thisbook/" + IdBook));
        }