Beispiel #1
0
        public async Task <IActionResult> Delete([FromForm] DeleteProjectViewModel model)
        {
            var command = this.unitOfWork.Create <DeleteProjectCommand>();
            await command.ExecuteAsync(model);

            return(Redirect("/Projects/Index"));
        }
Beispiel #2
0
        public IActionResult DeleteProject(Guid projectId, DeleteProjectViewModel model)
        {
            ViewData["Section"] = "Admin";
            if (!model.ConfirmDelete)
            {
                ModelState.AddModelError(nameof(model.ConfirmDelete), "Please confirm the deletion by checking the checkbox.");
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var documentationProject = _context.DocumentationProjects.FirstOrDefault(project => project.Id == model.ProjectId);

            if (documentationProject == null)
            {
                return(NotFound());
            }
            if (documentationProject.FolderGuid != Guid.Empty)
            {
                // Check if physical files present and if yes, delete them
                var physicalDirectory = Path.Combine(_hostingEnvironment.WebRootPath, "App_Data/" + documentationProject.FolderGuid);
                if (Directory.Exists(physicalDirectory))
                {
                    Directory.Delete(physicalDirectory, true);
                }
            }
            _context.DocumentationProjects.Remove(documentationProject);
            _context.SaveChanges();
            ViewBag.SuccessMessage = $"Deleted project {documentationProject.Name}.";
            return(RedirectToAction(nameof(Index)));
        }
 public IActionResult Delete(DeleteProjectViewModel project)
 {
     if (ModelState.IsValid)
     {
         projectService.DeleteProject(project.ID);
         return(RedirectToAction("Index"));
     }
     return(View(project));
 }
Beispiel #4
0
        public async Task DeleteProject_WithCorrectData_ShouldSuccessfullyDelete()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository   = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository = new EfDeletableEntityRepository <Product>(context);
            var projectRepository = new EfDeletableEntityRepository <Project>(context);

            var groupService      = new GroupService(groupRepository);
            var prodcutService    = new ProductService(productRepository, groupService);
            var cloudinaryService = new FakeCloudinary();
            var projectService    = new ProjectService(projectRepository, cloudinaryService, prodcutService, groupService);

            var user = new ApplicationUser
            {
                Id             = "abc",
                FirstName      = "Nikolay",
                LastName       = "Doychev",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
            };

            var       fileName = "Img";
            IFormFile file     = new FormFile(
                new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")),
                0,
                0,
                fileName,
                "dummy.png");

            var project = new DeleteProjectViewModel
            {
                Id           = "abc1",
                Description  = "Some description test 1",
                TypeProject  = TypeProject.Classic.ToString(),
                TypeLocation = TypeLocation.Corner.ToString(),
                Name         = "Проект 1",
            };

            var seeder = new DbContextTestsSeeder();
            await seeder.SeedUsersAsync(context);

            await seeder.SeedGroupAsync(context);

            await seeder.SeedProjectAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(DeleteProjectViewModel).Assembly);
            await projectService.DeleteAsync <DeleteProjectViewModel>(project);

            int actual = context.Projects.Count();

            // Assert
            Assert.True(actual == 1, string.Format(ErrorMessage, "DeleteProject method"));
        }
        public async Task <IActionResult> DeleteProject(DeleteProjectViewModel model)
        {
            if (ModelState.IsValid)
            {
                await service.DeleteProject(model);

                return(RedirectToAction("DisplayAllProjects"));
            }
            return(View());
        }
Beispiel #6
0
        public async Task DeleteProject_WithNonExistingProject_ShouldThrowException()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository   = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository = new EfDeletableEntityRepository <Product>(context);
            var projectRepository = new EfDeletableEntityRepository <Project>(context);

            var groupService      = new GroupService(groupRepository);
            var prodcutService    = new ProductService(productRepository, groupService);
            var cloudinaryService = new FakeCloudinary();
            var projectService    = new ProjectService(projectRepository, cloudinaryService, prodcutService, groupService);

            var user = new ApplicationUser
            {
                Id             = "abc",
                FirstName      = "Nikolay",
                LastName       = "Doychev",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
            };

            var       fileName = "Img";
            IFormFile file     = new FormFile(
                new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")),
                0,
                0,
                fileName,
                "dummy.png");

            var project = new DeleteProjectViewModel
            {
                Id           = "Test Id",
                Description  = "Some description test 1",
                ImagePath    = "Some dummy data",
                TypeProject  = TypeProject.Classic.ToString(),
                TypeLocation = TypeLocation.Corner.ToString(),
                Name         = "Проект 1",
            };

            var seeder = new DbContextTestsSeeder();
            await seeder.SeedUsersAsync(context);

            await seeder.SeedGroupAsync(context);

            await seeder.SeedProjectAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(DeleteProjectViewModel).Assembly);
            await Assert.ThrowsAsync <NullReferenceException>(() => projectService.DeleteAsync <DeleteProjectViewModel>(project));
        }
Beispiel #7
0
        public IActionResult Delete(long Id)
        {
            var project = _unityOfWork.Project.GetById(Id);
            DeleteProjectViewModel projectToDelete = new DeleteProjectViewModel()
            {
                ID          = project.ID,
                customer    = project.Customer,
                Description = project.Description,
                Title       = project.Title
            };

            return(View(projectToDelete));
        }
Beispiel #8
0
        public async Task DeleteProject(DeleteProjectViewModel model)
        {
            var projectToDelete = await FindProject(model.Id);

            if (projectToDelete == null)
            {
                throw new NullReferenceException($"No project with id:{model.Id} exists.");
            }
            projectToDelete.IsDeleted = true;

            dbContext.Projects.Update(projectToDelete);
            await dbContext.SaveChangesAsync();
        }
Beispiel #9
0
        public IActionResult DeleteProject(Guid projectId)
        {
            ViewData["Section"] = "Admin";
            var project = _context.DocumentationProjects.FirstOrDefault(p => p.Id == projectId);

            if (project == null)
            {
                return(NotFound());
            }
            var model = new DeleteProjectViewModel();

            model.ProjectName = project.Name;
            model.ProjectId   = project.Id;
            return(View(model));
        }
Beispiel #10
0
        public async Task <IActionResult> Delete(DeleteProjectViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var typeOfProject     = this.projectService.GetById <DeleteProjectViewModel>(model.Id).TypeProject;
            var getTypeOfLoaction = this.projectService.GetById <DeleteProjectViewModel>(model.Id).TypeLocation;

            await this.projectService.DeleteAsync <DeleteProjectViewModel>(model);

            var type         = Enum.Parse <TypeProject>(typeOfProject);
            var typeLocation = Enum.Parse <TypeLocation>(getTypeOfLoaction);

            return(this.RedirectToAction("All", "Project", new { typeLocation = typeLocation, type = typeOfProject, area = string.Empty }));
        }
Beispiel #11
0
        public async Task DeleteAsync <T>(DeleteProjectViewModel deleteModel)
        {
            var projectModel = this.projectRepository.All().Where(f => f.Id == deleteModel.Id).FirstOrDefault();

            if (projectModel == null)
            {
                throw new NullReferenceException(string.Format(ExceptionsServices.Null_Project_Id_ErrorMessage, deleteModel.Id));
            }

            projectModel.IsDeleted = true;
            projectModel.DeletedOn = DateTime.UtcNow;

            await this.productService.DeleteAsync(projectModel.ProductId);

            this.projectRepository.Update(projectModel);

            await this.projectRepository.SaveChangesAsync();
        }
Beispiel #12
0
        public IActionResult Delete(DeleteProjectViewModel project)
        {
            ProjectModel projectToDelete = new ProjectModel()
            {
                ID          = project.ID,
                CustomerID  = project.CustomerID,
                Description = project.Description,
                Title       = project.Title
            };

            if (project.decisionControll)
            {
                _unityOfWork.Project.Delete(projectToDelete);
                _unityOfWork.Save();
            }
            LoggingController.writeLog(projectToDelete, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString());

            return(RedirectToAction("Index"));
        }
Beispiel #13
0
        public ActionResult DeleteProject(DeleteProjectViewModel model)
        {
            if (ProjectService.Get(model.ProjectId) == null)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    ProjectService.Delete(model.ProjectId);
                }
                catch (Exception ex)
                {
                    var message = "Something went wrong with project delete, please try again later";
                    Log.Error(ex, message);
                }
            }
            // TODO: pass success message
            return(RedirectToAction(nameof(Projects)));
        }
        public async Task <IActionResult> DeleteProject(string id)
        {
            var findToDelete = await service.FindProject(id);

            var projectToDelete = new DeleteProjectViewModel();

            if (findToDelete == null)
            {
                return(NotFound());
            }
            else if (findToDelete.IsDeleted)
            {
                return(RedirectToAction("DisplayAllProjects"));
            }
            projectToDelete.Id          = findToDelete.Id;
            projectToDelete.Title       = findToDelete.Title;
            projectToDelete.Description = findToDelete.Description;
            projectToDelete.CompanyId   = findToDelete.CompanyId;
            projectToDelete.WorkTime    = findToDelete.WorkTime;
            projectToDelete.IsDelete    = findToDelete.IsDeleted;
            return(View(projectToDelete));
        }
Beispiel #15
0
        public async Task <IActionResult> DeleteProject([FromBody] DeleteProjectViewModel model)
        {
            await projectService.DeleteProject(model.ProjectId);

            return(new OkResult());
        }
 public ActionResult Delete(int ID, DeleteProjectViewModel pvm)
 {
     this.ps.DeleteProjects(ID);
     return RedirectToAction("Index", "Projects", new { area = "admin" });
 }