public async Task <IActionResult> OnPostAsync(string returnURL = null)
        {
            if (User.Identity.IsAuthenticated)
            {
                string emaiID = User.FindFirst(ClaimTypes.Email).Value;
                var    user   = await _userContext.UserAccount.SingleOrDefaultAsync(m => (m.EmailID == emaiID));

                if (user != null)
                {
                    if (user.Password != Password)
                    {
                        ModelState.AddModelError(string.Empty, "Password is Wrong!");
                        return(Page());
                    }
                    else
                    {
                        _userContext.UserAccount.Remove(user);
                        await _userContext.SaveChangesAsync();

                        await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

                        return(RedirectToPage("/Index"));
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "User Already Deleted!!");
                    return(Page());
                }
            }
            return(Page());
        }
示例#2
0
        public async Task <string> SignUpUser(string UserName, string FullName, string EmailID, string Password)
        {
            var user = _userContext.UserAccount.FirstOrDefault(m => m.UserName == UserName);

            if (user != null)
            {
                return("UserNameExists");
            }
            else
            {
                user = _userContext.UserAccount.FirstOrDefault(m => m.EmailID == EmailID);
                if (user != null)
                {
                    return("EmailIDExists");
                }
                else
                {
                    UserAccount newUser = new UserAccount
                    {
                        UserName        = UserName,
                        FullName        = FullName,
                        EmailID         = EmailID,
                        Password        = Password,
                        ConfirmPassword = Password,
                        SingleEasyLoses = 0,
                        SingleEasyTies  = 0,
                        SingleEasyWins  = 0,
                        SingleHardLoses = 0,
                        SingleHardTies  = 0,
                        SingleHardWins  = 0,
                        DoubleLoses     = 0,
                        DoubleTies      = 0,
                        DoubleWins      = 0
                    };
                    _userContext.UserAccount.Add(newUser);
                    var result = await _userContext.SaveChangesAsync();

                    return("Success");
                }
            }
        }
示例#3
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            ReturnUrl = returnUrl;

            if (ModelState.IsValid)
            {
                var Accounts = await _context.UserAccount.ToListAsync();

                foreach (var item in Accounts)
                {
                    if (item.UserName == InputUser.UserName.ToLower())
                    {
                        ModelState.AddModelError(string.Empty, "Username Not Available.");
                        return(Page());
                    }
                    if (item.EmailID == InputUser.EmailID.ToLower())
                    {
                        ModelState.AddModelError(string.Empty, "Email ID already registered.");
                        return(Page());
                    }
                }

                UserAccount NewUser = new UserAccount
                {
                    FullName        = InputUser.FullName,
                    UserName        = InputUser.UserName.ToLower(),
                    EmailID         = InputUser.EmailID.ToLower(),
                    Password        = InputUser.Password,
                    ConfirmPassword = InputUser.ConfirmPassword,
                    SingleEasyLoses = 0,
                    SingleEasyTies  = 0,
                    SingleEasyWins  = 0,
                    SingleHardLoses = 0,
                    SingleHardTies  = 0,
                    SingleHardWins  = 0,
                    DoubleLoses     = 0,
                    DoubleTies      = 0,
                    DoubleWins      = 0
                };

                try
                {
                    var result = await _context.UserAccount.AddAsync(NewUser);

                    await _context.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    return(RedirectToPage("/Error"));
                }

                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, NewUser.FullName),
                    new Claim(ClaimTypes.Email, NewUser.EmailID),
                };

                var claimsIdentity = new ClaimsIdentity(
                    claims, CookieAuthenticationDefaults.AuthenticationScheme);

                var authProperties = new AuthenticationProperties
                {
                };
                authProperties.IsPersistent = true;
                authProperties.ExpiresUtc   = DateTimeOffset.UtcNow.AddMonths(1);

                await HttpContext.SignInAsync(
                    CookieAuthenticationDefaults.AuthenticationScheme,
                    new ClaimsPrincipal(claimsIdentity),
                    authProperties);

                return(RedirectToPage("/Index"));
            }
            // Something failed. Redisplay the form.
            return(Page());
        }
        public async Task <string> UpdateStatsWeb(UpdateModelWeb model)
        {
            if (ModelState.IsValid)
            {
                if (User.Identity.IsAuthenticated)
                {
                    string emaiID = User.FindFirst(ClaimTypes.Email).Value;
                    var    user   = await _userContext.UserAccount.SingleOrDefaultAsync(m => (m.EmailID == emaiID));

                    if (user == null)
                    {
                        return("False");
                    }
                    else
                    {
                        if (model.Type == "SingleEasyWin")
                        {
                            user.SingleEasyWins = user.SingleEasyWins + long.Parse(model.Counts);
                        }
                        else if (model.Type == "SingleEasyTie")
                        {
                            user.SingleEasyTies = user.SingleEasyTies + long.Parse(model.Counts);
                        }
                        else if (model.Type == "SingleEasyLoss")
                        {
                            user.SingleEasyLoses = user.SingleEasyLoses + long.Parse(model.Counts);
                        }
                        else if (model.Type == "SingleHardWin")
                        {
                            user.SingleHardWins = user.SingleHardWins + long.Parse(model.Counts);
                        }
                        else if (model.Type == "SingleHardTie")
                        {
                            user.SingleHardTies = user.SingleHardTies + long.Parse(model.Counts);
                        }
                        else if (model.Type == "SingleHardLoss")
                        {
                            user.SingleHardLoses = user.SingleHardLoses + long.Parse(model.Counts);
                        }
                        else if (model.Type == "DoubleWin")
                        {
                            user.DoubleWins = user.DoubleWins + long.Parse(model.Counts);
                        }
                        else if (model.Type == "DoubleTie")
                        {
                            user.DoubleTies = user.DoubleTies + long.Parse(model.Counts);
                        }
                        else if (model.Type == "DoubleLoss")
                        {
                            user.DoubleLoses = user.DoubleLoses + long.Parse(model.Counts);
                        }

                        try
                        {
                            _userContext.UserAccount.Update(user);
                            await _userContext.SaveChangesAsync();

                            return("True");
                        }
                        catch (Exception ex)
                        {
                            return("False");
                        }
                    }
                }
                return("False");
            }
            return("False");
        }