Esempio n. 1
0
        public IActionResult Delete(int id)
        {
            Project projectFromDb        = _context.GetProject(id);
            ProjectDeleteViewModel model = new ProjectDeleteViewModel()
            {
                Titel = projectFromDb.Titel,
                Id    = projectFromDb.Id
            };

            return(View(model));
        }
Esempio n. 2
0
        public async Task <IActionResult> Delete(int id)
        {
            Project projectFromDb = await _projectDbContext.Projects.FirstOrDefaultAsync(p => p.Id == id);

            ProjectDeleteViewModel deleteView = new ProjectDeleteViewModel()
            {
                Id    = projectFromDb.Id,
                Title = projectFromDb.Title
            };

            return(View(deleteView));
        }
        public async Task <IActionResult> Delete(int id)
        {
            string userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            var project = await _portfolioDbContext.Projects
                          .Include(proj => proj.ProjectTags)
                          .FirstOrDefaultAsync(item => item.Id == id && item.PortfolioUserId == userId);

            var vm = new ProjectDeleteViewModel
            {
                Id   = id,
                Name = project.Name
            };

            return(View(vm));
        }
Esempio n. 4
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            Project project = await _db.Projects.FindAsync(id);

            if (project == null)
            {
                return(HttpNotFound("Project not found."));
            }

            //Ensure user is allowed access to this project
            var currentUser = await _userManager.FindByIdAsync(User.Identity.GetUserId());

            if (currentUser == null)
            {
                return(RedirectToAction("LogOff", "Account")); //If the user is here without a found user then it must be an old cookie
            }
            //Check if user owns this project
            if (!currentUser.Projects.Contains(project))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest,
                                                "You do not have permission to delete this project"));
            }

            try
            {
                _db.Sprints.RemoveRange(project.Sprints);
                _db.Projects.Remove(project);

                await _db.SaveChangesAsync();
            }
            catch (Exception exception)
            {
                var model = new ProjectDeleteViewModel()
                {
                    Title       = project.Title,
                    Description = project.Description,
                    Error       = exception.Message
                };
                return(PartialView("_Delete", model));
            }

            return(Json(new { success = true }));
        }
Esempio n. 5
0
        // GET: Projects/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Invalid id"));
            }

            Project project = await _db.Projects.FindAsync(id);

            if (project == null)
            {
                return(HttpNotFound("Project not found."));
            }

            //Ensure user is allowed access to this project
            var currentUser = await _userManager.FindByIdAsync(User.Identity.GetUserId());

            if (currentUser == null)
            {
                return(RedirectToAction("LogOff", "Account")); //If the user is here without a found user then it must be an old cookie
            }
            //Check if user owns this project
            if (!currentUser.Projects.Contains(project))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest,
                                                "You do not have permission to delete this project"));
            }

            var model = new ProjectDeleteViewModel()
            {
                Title       = project.Title,
                Description = project.Description
            };

            return(PartialView("_Delete", model));
        }