Exemple #1
0
        public async Task <IActionResult> Create([Bind("Id,UId,ResumeName, ResumeSlug, UserDisplayName, UserAspiration, Summary,SummaryName,Experience,ExperienceName,Education,EducationName,Skills,SkillsName,Contact,ContactName")] Conspectus conspectus)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);


            if (ModelState.IsValid)
            {
                conspectus.Id  = Guid.NewGuid();
                conspectus.UId = user.Id;
                _context.Add(conspectus);

                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Edit", new { id = conspectus.Id }));
                }

                catch (Exception e)
                {
                    ModelState.AddModelError(string.Empty, "Something went wrong, perhaps the resume name has already been taken. Please try a different resume name.");
                    // ViewBag.Error = "Something went wrong, perhaps the resume name has already been taken. Please try a different resume name.";
                    return(View(conspectus));
                }
            }
            return(RedirectToAction(nameof(Index)));
            //return RedirectToAction(nameof(Edit(conspectus.Id)));
        }
Exemple #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            RequirePassword = await _userManager.HasPasswordAsync(user);

            if (RequirePassword)
            {
                if (!await _userManager.CheckPasswordAsync(user, Input.Password))
                {
                    ModelState.AddModelError(string.Empty, "Incorrect password.");
                    return(Page());
                }
            }



            //var query = $"DELETE FROM Conspectus WHERE UId = '{user.Id.ToString().ToUpper()}'";

            //await _context.Conspectus.FromSqlRaw(query).ToListAsync();


            var query           = $"SELECT * FROM Conspectus WHERE UId = '{user.Id.ToString().ToUpper()}'";
            var resumesToDelete = await _context.Conspectus.FromSqlRaw(query).ToListAsync();

            _context.Conspectus.RemoveRange(resumesToDelete);
            await _context.SaveChangesAsync();


            var result = await _userManager.DeleteAsync(user);

            var userId = await _userManager.GetUserIdAsync(user);

            if (!result.Succeeded)
            {
                throw new InvalidOperationException($"Unexpected error occurred deleting user with ID '{userId}'.");
            }

            await _signInManager.SignOutAsync();

            _logger.LogInformation("User with ID '{UserId}' deleted themselves.", userId);

            return(Redirect("~/"));
        }