コード例 #1
0
        public ActionResult Create(Project project)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new ProjectFormViewModel
                {
                    Project = project,
                };

                return(View("Create", viewModel));
            }

            if (project.Id == 0)
            {
                _context.Projects.Add(project);
            }

            else
            {
                var projectInDb = _context.Projects.Single(t => project.Id == project.Id);

                projectInDb.Name        = project.Name;
                projectInDb.Description = project.Description;
            }

            _context.SaveChanges();

            return(RedirectToAction("List", "Projects"));
        }
コード例 #2
0
        public ActionResult Save(Project project)
        {
            if (!this.ModelState.IsValid)
            {
                var viewModel = new ProjectFormViewModel(project);

                return(View("ProjectForm", viewModel));
            }

            var message = "";

            if (project.Id == 0)
            {
                this._context.Projects.Add(project);
                message = "created";
            }
            else
            {
                var projectInDb = this._context.Projects.Single(p => p.Id == project.Id);

                projectInDb.Name = project.Name;
                projectInDb.ProjectInvestment = project.ProjectInvestment;
                projectInDb.ProjectPrice      = project.ProjectPrice;
                projectInDb.ProjectInfo       = project.ProjectInfo;
                message = "edited";
            }
            this._context.SaveChanges();
            this.AddToastMessage("Congratulations", $"Program {project.Name} {message} successfully!", ToastType.Success);

            return(RedirectToAction("Details", "Programs", new { id = project.ProgramId }));
        }
コード例 #3
0
 public ViewResult ProjectDetails(Guid?id)
 {
     if (!id.HasValue)
     {
         var defaultViewModel = new ProjectFormViewModel
         {
             Groups        = _groupService.GetGroup(),
             EmployeesList = GetAllEmployeesNames(_employeeService.GetEmployee())
         };
         return(View("ProjectDetails", defaultViewModel));
     }
     else
     {
         var project = _projectService.GetProjectWithEmployees(id.Value);
         IEnumerable <string> visas = DisplayMembers(project);
         var viewModel = new ProjectFormViewModel
         {
             Project       = project,
             EditMode      = true,
             Groups        = _groupService.GetGroup(),
             EmployeesList = GetAllEmployeesNames(_employeeService.GetEmployee()),
             Members       = visas
         };
         return(View("ProjectDetails", viewModel));
     }
 }
コード例 #4
0
        // GET: Projects/Create
        public async Task <IActionResult> Create(int?clients, int?projects, int?manager_project, int?manager)
        {
            GetSessions();

            if (ViewBag.Email == null)
            {
                return(ExpiredSession());
            }


            try
            {
                int accessLevel = ViewBag.AcessLevel;
                int employeeId  = ViewBag.Id;

                ViewBag.Clients         = clients;
                ViewBag.Projects        = projects;
                ViewBag.Manager         = manager;
                ViewBag.Manager_Project = manager_project;

                var client = await _clientService.FindAllForProjectsAsync(accessLevel, employeeId);

                var employee = await _employeeService.FindAllManagersAsync();

                var viewModel = new ProjectFormViewModel {
                    Client = client, Employee = employee
                };

                return(View(viewModel));
            }
            catch (Exception e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }
コード例 #5
0
        public void If_Project_UserId_Does_Not_Match_Current_User_Do_Not_Add()
        {
            // Spoof an authenticated user by generating a ClaimsPrincipal
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "FIREBASE_USER1"),
            }, "TestAuthentication"));

            // Create a new project
            ProjectFormViewModel projectForm = new ProjectFormViewModel
            {
                Project = new Project()
                {
                    // have a userId coming in that does not match
                    UserId       = 666,
                    Name         = "New stuff",
                    CreationDate = DateTime.Now - TimeSpan.FromDays(10)
                },
                ProjectCollections = new List <ProjectCollection>()
            };

            // Spoof UserController
            var controller = new ProjectController(_fakeUserRepo.Object, _fakeProjectRepo.Object, _fakeProjColRepo.Object);

            controller.ControllerContext             = new ControllerContext(); // Required to create the controller
            controller.ControllerContext.HttpContext = new DefaultHttpContext {
                User = user
            };                                                                                 // Pretend the user is making a request to the controller

            // Attempt to Get this User's projects
            var response = controller.Add(projectForm);

            // Returns Ok
            Assert.IsType <BadRequestResult>(response);
        }
コード例 #6
0
        public ActionResult CreateOrUpdateForm(ProjectFormViewModel viewModel)
        {
            //if ProjectId is 0 means its new created project
            if (viewModel.Project.Id == 0)
            {
                Project project = new Project()
                {
                    Name  = viewModel.Project.Name,
                    Users = userHelper.GetAllUsersFromIds(viewModel.SelectedId),
                };

                projectHelper.AddProject(project);
            }
            //Else project need to update
            else
            {
                Project project = new Project()
                {
                    Id    = viewModel.Project.Id,
                    Name  = viewModel.Project.Name,
                    Users = userHelper.GetAllUsersFromIds(viewModel.SelectedId),
                };

                projectHelper.UpdateProject(project);
            }

            return(RedirectToAction("List"));
        }
コード例 #7
0
 public Project(ProjectFormViewModel viewModel)
 {
     DueDate      = viewModel.DueDate;
     StartingDate = DateTime.Now;
     Description  = viewModel.Description.ToString();
     DepartmentId = viewModel.DepartmentId;
     EndDate      = viewModel.EndDate;
 }
コード例 #8
0
        public ActionResult CreateProject(ProjectFormViewModel viewModel)
        {
            var newProject = new Project(viewModel);

            _context.Projects.Add(newProject);
            _context.SaveChanges();
            return(RedirectToAction("Index", "Projects"));
        }
コード例 #9
0
        public ActionResult New(int programId)
        {
            var defaultClientName     = this._context.Clients.FirstOrDefault(c => c.Id == Defaults.ClientId).Name;
            var defaultConsultantName = this._context.Consultants.FirstOrDefault(c => c.Id == Defaults.ConsultantId).Name;
            var viewModel             = new ProjectFormViewModel(programId, defaultClientName, defaultConsultantName);

            return(View("ProjectForm", viewModel));
        }
コード例 #10
0
        //Get All TodayProjects For Today
        public ActionResult GetTodayProjects(ProjectFormViewModel viewModel)
        {
            var indexviewModel = new ProjectFormViewModel
            {
                Departments = _context.Departments.ToList()
            };

            return(View(indexviewModel));
        }
コード例 #11
0
        //Create Get
        public ActionResult CreateProject()
        {
            var viewModel = new ProjectFormViewModel
            {
                Departments = _context.Departments.ToList()
            };

            return(View(viewModel));
        }
コード例 #12
0
        public ActionResult TodayProjectsByDepartment(ProjectFormViewModel viewModel)
        {
            var projects = _context.Projects
                           .Include(p => p.Department)
                           .Where(p => p.EndDate == null && p.StartingDate <= DateTime.Now && p.DepartmentId == viewModel.DepartmentId && p.EndDate == null)
                           .ToList();

            return(View(projects));
        }
コード例 #13
0
        // GET: Projects/Create

        public ActionResult Create()
        {
            var viewModel = new ProjectFormViewModel
            {
                Project = new Project(),
            };

            return(View("Create", viewModel));
        }
コード例 #14
0
        public ActionResult New()
        {
            var viewModel = new ProjectFormViewModel
            {
                Categories = _context.Categories.ToList()
            };


            return(View("ProjectForm", viewModel));
        }
コード例 #15
0
        public ActionResult Create()
        {
            ViewBag.Action = "Create";
            ProjectFormViewModel viewModel = new ProjectFormViewModel()
            {
                Project   = new Project(),
                UsersList = new SelectList(db.Users.ToList(), "Id", "UserName")
            };

            return(View("CreateOrUpdateForm", viewModel));
        }
コード例 #16
0
        public void AddNewProject(string name, string prefix)
        {
            var projectViewModel = new ProjectFormViewModel()
            {
                Name = name, Prefix = prefix
            };
            var project = _mapper.Map <ProjectFormViewModel, Project>(projectViewModel);

            _projectRepository.Add(project);
            _projectRepository.Save();
        }
コード例 #17
0
        public ActionResult Update(int id)
        {
            ViewBag.Action = "Update";
            ProjectFormViewModel viewModel = new ProjectFormViewModel()
            {
                Project    = projectHelper.GetProject(id),
                UsersList  = new SelectList(db.Users.ToList(), "Id", "UserName"),
                SelectedId = projectHelper.GetProjectUserIds(id)
            };

            return(View("CreateOrUpdateForm", viewModel));
        }
コード例 #18
0
        public void User_Can_Not_Update_Projects_With_Duplicate_Names()
        {
            // Make a new project to pass in to update
            var projectForm = new ProjectFormViewModel
            {
                Project = new Project()
                {
                    Id           = 2,
                    UserId       = 1,
                    Name         = "It",
                    CreationDate = DateTime.Now - TimeSpan.FromDays(15)
                },

                ProjectCollections = new List <ProjectCollection>()
                {
                    new ProjectCollection()
                    {
                        ProjectId    = 2, // I won't know this until it's made
                        CollectionId = 2
                    },
                    new ProjectCollection()
                    {
                        ProjectId    = 2, // I won't know this until it's made
                        CollectionId = 1
                    }
                }
            };

            // Spoof an authenticated user by generating a ClaimsPrincipal
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "FIREBASE_ID_1"),
            }, "TestAuthentication"));

            // Instantiate a real repos
            var projectRepo = new ProjectRepository(_context);
            var userRepo    = new UserRepository(_context);
            var projColRepo = new ProjectCollectionRepository(_context);

            // Instantiate a real ProjectController, passing in ProjectRepo
            var controller = new ProjectController(userRepo, projectRepo, projColRepo);

            controller.ControllerContext             = new ControllerContext(); // Required to create the controller
            controller.ControllerContext.HttpContext = new DefaultHttpContext {
                User = user
            };                                                                                 // Pretend the user is making a request to the controller

            // Attempt to Update project
            var response = controller.Put(projectForm.Project.Id, projectForm);

            // Should return created result
            Assert.IsType <NotFoundResult>(response);
        }
コード例 #19
0
        public ActionResult Edit(int id)
        {
            var project = this._context.Projects.Include(p => p.Client).Include(p => p.Consultant).SingleOrDefault(p => p.Id == id);

            if (project == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new ProjectFormViewModel(project);

            return(View("ProjectForm", viewModel));
        }
コード例 #20
0
        private ActionResult CatchException(ProjectFormViewModel viewModel)
        {
            if (!viewModel.EditMode)
            {
                ModelState.Remove("Project.ID");
            }

            var errViewModel = new ProjectFormViewModel
            {
                Groups        = _groupService.GetGroup(),
                Project       = viewModel.Project,
                Members       = viewModel.Members,
                EditMode      = viewModel.EditMode,
                EmployeesList = GetAllEmployeesNames(_employeeService.GetEmployee())
            };

            //Step1: Check for data annotation attribute client side validation
            if (!ModelState.IsValid)
            {
                return(View("ProjectDetails", errViewModel));
            }

            try
            {
                if (viewModel.EditMode)
                {
                    _projectService.Update(viewModel.Project, viewModel.Members);
                }
                else
                {
                    _projectService.Create(viewModel.Project, viewModel.Members);
                }
            }
            catch (BusinessException ex)
            {
                errViewModel.Exception = ex;
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View("ProjectDetails", errViewModel));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                errViewModel.Exception = ex;
                return(View("ProjectDetails", errViewModel));
            }

            return(RedirectToAction("Index", "Projects"));
        }
コード例 #21
0
        public ActionResult Edit(int id)
        {
            var project = _context.Projects.SingleOrDefault(t => t.Id == id);

            if (project == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new ProjectFormViewModel
            {
                Project = project,
            };

            return(View("Create", viewModel));
        }
コード例 #22
0
        public ProjectWindow(IViewManager viewManager)
        {
            InitializeComponent();
            //ProjectTabs.ItemContainerStyle = this.FindResource("Right90") as Style;

            ProjectFormViewModel vm = (ProjectFormViewModel)this.DataContext; // this creates an instance of the ViewModel

            if (vm.CloseAction == null)
            {
                vm.CloseAction = new Action(() => this.Close());
            }
            if (vm.OpenTab == null)
            {
                vm.OpenTab = new Action(() => this.ProjectTabs.SelectedIndex = 0);
            }
            vm.ViewManager = viewManager;
        }
コード例 #23
0
        public dynamic ProjectSave()
        {
            ProjectFormViewModel model   = this.Bind <ProjectFormViewModel>();
            ProjectModel         project = Mapper.Map <ProjectFormViewModel, ProjectModel>(model);

            ValidationResult validationResult = _projectValidator.Validate(project);

            if (validationResult.Success)
            {
                _dbContext.BeginTransaction();
                project = _createProjectCommand.Execute(project);
                _dbContext.Commit();
            }

            SaveResultModel result = new SaveResultModel(project.Id.ToString(), validationResult.Success, validationResult.Messages.ToArray());

            return(this.Response.AsJson(result));
        }
コード例 #24
0
        public ActionResult Edit(int id)
        {
            var project = _context.Projects.Include(p => p.Category).SingleOrDefault(p => p.Id == id);


            if (project == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new ProjectFormViewModel
            {
                Project    = project,
                Categories = _context.Categories.ToList()
            };


            return(View("ProjectForm", viewModel));
        }
コード例 #25
0
        // GET: Projects
        public async Task <IActionResult> Index(int?accessLevel, int?employeeId, int?clients, int?projects, int?manager_project, int?manager)
        {
            GetSessions();

            if (ViewBag.Email == null)
            {
                return(ExpiredSession());
            }


            try
            {
                accessLevel = ViewBag.AcessLevel;
                employeeId  = ViewBag.Id;

                ViewBag.Clients         = clients;
                ViewBag.Projects        = projects;
                ViewBag.Manager         = manager;
                ViewBag.Manager_Project = manager_project;

                var Listprojects = await _projectService.FindAllToListAsync(accessLevel, employeeId, clients, projects, manager_project, manager);

                var clientes = await _clientService.FindAllForProjectsAsync(accessLevel, employeeId);

                var projetos = await _projectService.FindProjectAsync((int)accessLevel, (int)employeeId);

                var funcionarios = await _employeeService.FindAllManagersAsync();

                var viewModel = new ProjectFormViewModel {
                    ListProject = Listprojects, Client = clientes, Projects = projetos, Employee = funcionarios
                };
                return(View(viewModel));
            }
            catch (Exception e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }
コード例 #26
0
        public void If_Project_To_Update_Is_Not_Mine_Do_Not_Update()
        {
            // Spoof an authenticated user by generating a ClaimsPrincipal
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "FIREBASE_USER2"),
            }, "TestAuthentication"));

            // Make a fake project to update
            ProjectFormViewModel projectForm = new ProjectFormViewModel
            {
                Project = new Project()
                {
                    Id           = 1,
                    UserId       = 1,
                    Name         = "New PROJECT!!!!",
                    CreationDate = DateTime.Now - TimeSpan.FromDays(10)
                },
                ProjectCollections = new List <ProjectCollection>()
            };

            // Use a matching Id
            var projectParamId = 1;

            // Spoof UserController
            var controller = new ProjectController(_fakeUserRepo.Object, _fakeProjectRepo.Object, _fakeProjColRepo.Object);

            controller.ControllerContext             = new ControllerContext(); // Required to create the controller
            controller.ControllerContext.HttpContext = new DefaultHttpContext {
                User = user
            };                                                                                 // Pretend the user is making a request to the controller

            // Attempt to Get this User's projects
            var response = controller.Put(projectParamId, projectForm);

            // Returns Ok
            Assert.IsType <NotFoundResult>(response);
        }
コード例 #27
0
        public ActionResult Save(ProjectFormViewModel projectFormViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("AddProject", projectFormViewModel));
            }

            var path = "~/images/" + Path.GetFileName(projectFormViewModel.File.FileName);


            var project = new Project

            {
                Name        = projectFormViewModel.Name,
                Description = projectFormViewModel.Description,
                Image       = path
            };

            _context.Projects.Add(project);
            projectFormViewModel.File.SaveAs(Server.MapPath(path));
            _context.SaveChanges();

            return(View("index"));
        }
コード例 #28
0
        public void Anonymous_User_Can_Not_Add_Project()
        {
            // Spoof an authenticated user by generating a ClaimsPrincipal
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "FIREBASE_USER666"),
            }, "TestAuthentication"));

            // Create a new project
            ProjectFormViewModel projectForm = new ProjectFormViewModel
            {
                Project = new Project()
                {
                    Id           = 1,
                    UserId       = 1,
                    Name         = "New stuff",
                    CreationDate = DateTime.Now - TimeSpan.FromDays(10)
                },
                ProjectCollections = new List <ProjectCollection>()
            };

            // Spoof UserController
            var controller = new ProjectController(_fakeUserRepo.Object, _fakeProjectRepo.Object, _fakeProjColRepo.Object);

            controller.ControllerContext             = new ControllerContext(); // Required to create the controller
            controller.ControllerContext.HttpContext = new DefaultHttpContext {
                User = user
            };                                                                                 // Pretend the user is making a request to the controller

            // Attempt to Get this User's projects
            var response = controller.Add(projectForm);

            // Returns Ok
            Assert.IsType <NotFoundResult>(response);
            // Verify we never called the repo method
            _fakeProjectRepo.Verify(r => r.Add(It.IsAny <Project>()), Times.Never());
        }
コード例 #29
0
        public IActionResult Add(ProjectFormViewModel projectForm)
        {
            // For the Add, do not need to check for if the projectCollections are in the db
            // because this Project is unique, there can be no duplicates.

            var firebaseUser = _utils.GetCurrentUser(User);

            // Check to ensure an unauthorized user (anonymous account) can not add a project
            if (firebaseUser == null)
            {
                return(NotFound());
            }

            // Ensure the userId on the incoming project matches the person making the request
            if (projectForm.Project.UserId != firebaseUser.Id)
            {
                return(BadRequest());
            }

            // Get all of this user's projects
            var allProjects = _projectRepo.Get(firebaseUser.Id);

            // see if the name of the incoming collection is in the db
            var projectWithThatName = allProjects.Find(c => c.Name == projectForm.Project.Name);

            // if there is a returned project, we can't add because name isn't unique for this user
            if (projectWithThatName != null)
            {
                return(NotFound());
            }

            // Need to add the default requirement for the project here
            projectForm.Project.CreationDate = DateTime.Now;

            try
            {
                _projectRepo.Add(projectForm.Project);

                try
                {
                    // After we add the project, assign the project id to each projectCollection
                    foreach (var projectCollection in projectForm.ProjectCollections)
                    {
                        projectCollection.ProjectId = projectForm.Project.Id;
                    }
                }
                // The user attempted to enter Null for their ProjectCollecitons
                catch (NullReferenceException e)
                {
                    // Make a CollectionDetailsViewModel to pass the created collection into for deletion
                    var projectDetails = new ProjectDetailsViewModel
                    {
                        Project            = projectForm.Project,
                        ProjectCollections = new List <ProjectCollection>()
                    };
                    // Remove the just entered collection from db
                    _projectRepo.Delete(projectDetails);

                    // Return a BadRequest
                    return(BadRequest());
                }

                // Add ProjectCollections
                _projColRepo.Add(projectForm.ProjectCollections);

                return(Ok(projectForm));
            }
            catch (DbUpdateException e)
            {
                return(NotFound());
            }
        }
コード例 #30
0
        public IActionResult Put(int id, ProjectFormViewModel incomingProjectForm)
        {
            // Get current user
            var firebaseUser = _utils.GetCurrentUser(User);

            // Ensure an unauthorized user (anonymous account) can not update
            if (firebaseUser == null)
            {
                return(NotFound());
            }

            // Project Id coming from URL must match the Project object's Id
            if (id != incomingProjectForm.Project.Id)
            {
                return(BadRequest());
            }

            // Get Project by Id to ensure it's in db
            ProjectDetailsViewModel projectDetailsToUpdate;

            try
            {
                // If a user attempts to get an Id not in the db, causes a NullReferenceException error
                projectDetailsToUpdate = _projectRepo.GetByProjectId(id);
            }
            catch (NullReferenceException e)
            {
                return(NotFound());
            }

            // If it wasn't in the db don't let them update
            if (projectDetailsToUpdate == null)
            {
                return(NotFound());
            }

            // Get all of this user's projects
            var allProjects = _projectRepo.Get(firebaseUser.Id);

            // see if the name of the incoming collection is in the db
            var projectWithThatName = allProjects.Where(c => c.Name == incomingProjectForm.Project.Name).ToList();

            // If the count is greater than 1, so it's in the db, check to see what the Id is
            if (projectWithThatName.Count > 0)
            {
                // If the Ids match, we can update, otherwise, it's already in db and not the current item
                if (projectWithThatName[0].Id != incomingProjectForm.Project.Id)
                {
                    return(NotFound());
                }
            }

            // Get Project's owner to ensure this is current user's project
            var projectOwnerId = incomingProjectForm.Project.UserId;

            // Check if incoming user is the same one requesting deletion
            if (projectOwnerId != firebaseUser.Id)
            {
                return(NotFound());
            }

            // ** At this point, we know the person is able to update the project.

            // By using the projectDetailsToUpdate we retrieved from the db,
            // we re-assign its values that are editable, based on the incoming project
            projectDetailsToUpdate.Project.Name = incomingProjectForm.Project.Name;

            try
            {
                // When updating a Project, we DELETE all current ProjCols then ADD all incoming
                // Delete all the ProjectCollections from collectionToUpdate
                _projColRepo.Delete(projectDetailsToUpdate.ProjectCollections);

                // Add all incoming ProjectCollections
                _projColRepo.Add(incomingProjectForm.ProjectCollections);

                _projectRepo.Update(projectDetailsToUpdate.Project);
                return(NoContent());
            }
            catch (DbUpdateException e)
            {
                return(Unauthorized()); // When I get this error message in frontend, tell user the Name was already in db
            }
        }