public async Task <JsonResult> UpdateList(int id, ShowStatus status, ShowRating rating, string type)
        {
            var user = await GetCurrentUserAsync();

            if (user == null)
            {
                return(Json("ERROR: failed to update"));
            }
            var toModify = await _context.MyListShows
                           .Include(x => x.MyList)
                           .SingleOrDefaultAsync(x => x.SafeCompareId(type, id) && x.MyList.UserForeignKey == user.Id);

            if (toModify == null)
            {
                return(Json("ERROR: Show not in list"));
            }
            _context.Update(toModify);
            toModify.Status = (int)status;
            toModify.Rating = (int)rating;
            await _context.SaveChangesAsync();

            return(Json("Updated list"));
        }
Exemple #2
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new AppUser {
                    UserName = model.Username, Email = model.Email, RegisterDate = DateTime.Now
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Action(nameof(ConfirmEmail), "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                    //    $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");
                    _context.Add(new MyList()
                    {
                        User        = user,
                        MyListShows = new List <MyListShows>()
                    });
                    await _context.SaveChangesAsync();

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation(3, "User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }