public IActionResult Add(ProjectCategoryAddViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var userId = this.GetCurrentUserId();

                this.projectService.AddProject(viewModel, userId);

                return(this.Redirect("/"));
            }

            return(this.View());
        }
Example #2
0
        public void AddProjectShouldAddSuccessfullyProjects()
        {
            var options = new DbContextOptionsBuilder <TaskPlannerDbContext>()
                          .UseInMemoryDatabase(databaseName: "Projects_AddProjects_Database")
                          .Options;

            var dbContext = new TaskPlannerDbContext(options);

            var user = new ApplicationUser
            {
                Email    = "*****@*****.**",
                FullName = "Pesho Peshev"
            };

            var company = new Company
            {
                Name           = "DataCenter",
                Address        = "asd",
                FieldOfService = "IT"
            };

            dbContext.Users.Add(user);
            dbContext.Companies.Add(company);
            dbContext.SaveChanges();

            var userService = new Mock <IUserService>();

            userService.Setup(u => u.GetCurrentUserFromDb(user.Id))
            .Returns((ApplicationUser)dbContext.Users.FirstOrDefault(x => x.Email == user.Email));

            var companyService = new Mock <ICompanyService>();

            companyService.Setup(c => c.GetCompanyByName(company.Name))
            .Returns(dbContext.Companies.FirstOrDefault(c => c.Name == company.Name));

            var projectService = new ProjectService(dbContext, companyService.Object, userService.Object);

            var projectModel = new ProjectCategoryAddViewModel
            {
                Name = "New Project"
            };

            projectService.AddProject(projectModel, user.Id);

            var project = dbContext.Categories.FirstOrDefault(c => c.Name == projectModel.Name);

            Assert.Equal(projectModel.Name, project.Name);
        }
Example #3
0
        public void AddProject(ProjectCategoryAddViewModel viewModel, string userId)
        {
            var user         = this.userService.GetCurrentUserFromDb(userId);
            var companyName  = user.CompanyName;
            var companyToAdd = this.companyService.GetCompanyByName(companyName);

            var categoryToAdd = new Category
            {
                Name = viewModel.Name
            };

            categoryToAdd.CompanyCategories = new List <CompanyCategory>
            {
                new CompanyCategory
                {
                    Company  = companyToAdd,
                    Category = categoryToAdd
                }
            };

            this.dbContext.Categories.Add(categoryToAdd);
            this.dbContext.SaveChanges();
        }