public async Task TestDeleteImageAsync()
        {
            var projectInputModel = new ProjectInputModel
            {
                Name        = "test",
                Description = "Lorem",
                HeadImage   = this.file,
            };

            var projectId = await this.projectsService.CreateProjectAsync(projectInputModel);

            var imageInputModel = new ImageInputModel
            {
                ProjectId   = projectId,
                Description = "Lorem",
                ImageFile   = this.file,
            };

            var id = await this.projectsGalleryService.AddImageToGalleryAsync(imageInputModel);

            await this.projectsGalleryService.DeleteImageAsync(id);

            var currentGallery = await this.projectsGalleryService.GetGalleryAsync(projectId);

            Assert.Equal(0, currentGallery.Count);
        }
        public async Task TestUpdateProjectAsync()
        {
            var projectInputModel = new ProjectInputModel
            {
                Name        = "test",
                Description = "Lorem",
                HeadImage   = this.file,
            };

            var progectId = await this.projectsService.CreateProjectAsync(projectInputModel);

            var projectInputModelForChange = new ProjectInputModel
            {
                Id          = progectId,
                Name        = "change test",
                Description = "Change Lorem",
                HeadImage   = null,
            };

            await this.projectsService.UpdateProjectAsync(projectInputModelForChange);

            var projects = await this.projectsService.GetProjectByIdAsync(progectId);

            Assert.NotEqual("test", projects.Name);
            Assert.Equal("Change Lorem", projects.Description);
        }
Beispiel #3
0
        public async Task <ActionResult <ProjectModel> > Create(ProjectInputModel model)
        {
            _logger.LogDebug($"Creating a new project with name {model.Name}");

            var client = await _dbContext.Clients.FindAsync(model.ClientId);

            if (client == null)
            {
                return(NotFound());
            }

            var project = new Project {
                Client = client
            };

            model.MapTo(project);

            await _dbContext.Projects.AddAsync(project);

            await _dbContext.SaveChangesAsync();

            var resultModel = ProjectModel.FromProject(project);

            return(CreatedAtAction(nameof(GetById), "projects", new { id = project.Id, version = "1" }, resultModel));
        }
Beispiel #4
0
        public async Task <IActionResult> CreateProject([FromBody] ProjectInputModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }

            var project = new Project()
            {
                Title     = inputModel.Title,
                Location  = inputModel.Location,
                StartDate = inputModel.StartDate,
                EndDate   = inputModel.EndDate,
                Ongoing   = inputModel.Ongoing,
                Summary   = inputModel.Summary
            };

            if (!string.IsNullOrEmpty(inputModel.Image))
            {
                var authority = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}";

                var image = await _uploadImageService.UploadImage(inputModel.Image, authority);

                project.Image = image;
            }

            _unitOfWork.ProjectsRepository.Add(project);

            await _unitOfWork.CompleteAsync();

            return(this.Ok(project));
        }
        public async Task EditProjectAsync()
        {
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                          () =>
            {
                IsEditDisabled = false;
                IsEditEnabled  = true;

                IsTagSearchEnabled = true;
                ProjectInputModel  = new ProjectInputModel
                {
                    Title          = SelectedProject.Title,
                    Description    = SelectedProject.Description,
                    StudyFieldName = SelectedProject.StudyField.Name
                };

                if (SelectedProject.StartDate != null)
                {
                    ProjectInputModel.StartDate = new DateTimeOffset((DateTime)SelectedProject.StartDate);
                }
                if (SelectedProject.EndDate != null)
                {
                    ProjectInputModel.EndDate = new DateTimeOffset((DateTime)SelectedProject.EndDate);
                }

                foreach (var tag in SelectedProject.Tags)
                {
                    ProjectInputModel.TagNames.Add(tag.Name);
                }
            });
        }
Beispiel #6
0
        public async Task <IActionResult> UpdateProject(ProjectInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            await this.projectsService.UpdateProjectAsync(input);

            return(this.RedirectToAction("Index"));
        }
        public async Task TestCreateProject()
        {
            var projectInputModel = new ProjectInputModel
            {
                Name        = "test",
                Description = "Lorem",
                HeadImage   = this.file,
            };

            var projectId = await this.projectsService.CreateProjectAsync(projectInputModel);

            Assert.True(projectId > 0);
        }
Beispiel #8
0
        public ActionResult Add(ProjectInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var project = this.mappingService.Map <Project>(model);

            this.projectsService.AddProject(project);

            return(RedirectToAction(Constants.Index));
        }
Beispiel #9
0
        private async Task LoadProject()
        {
            var url   = $"projects/{Id}";
            var model = await ApiService.GetAsync <ProjectModel>(url);

            project = new ProjectInputModel
            {
                Name     = model.Name,
                ClientId = model.ClientId
            };

            clientId = model.ClientId.ToString();
        }
        public async Task TestGetProjectByIdAsync()
        {
            var projectInputModel = new ProjectInputModel
            {
                Name        = "test",
                Description = "Lorem",
                HeadImage   = this.file,
            };

            var progectId = await this.projectsService.CreateProjectAsync(projectInputModel);

            var projects = this.projectsService.GetProjectByIdAsync(progectId);

            Assert.Equal(progectId, projects.Id);
        }
Beispiel #11
0
        public async Task <IActionResult> CreateProject(ProjectInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            if (input.HeadImage == null)
            {
                return(this.View(input));
            }

            var id = await this.projectsService.CreateProjectAsync(input);

            return(this.RedirectToAction("Index"));
        }
        public async Task TestGetAllProjects()
        {
            var projectInputModel = new ProjectInputModel
            {
                Name        = "test",
                Description = "Lorem",
                HeadImage   = this.file,
            };

            await this.projectsService.CreateProjectAsync(projectInputModel);

            await this.projectsService.CreateProjectAsync(projectInputModel);

            var projects = this.projectsService.GetAllProjects().ToList();

            Assert.NotNull(projects);
        }
Beispiel #13
0
        public async Task <int> CreateProjectAsync(ProjectInputModel input)
        {
            var imageId = await this.filesService.UploadToFileSystemAsync(input.HeadImage, "images\\projectImages", "Project Hade Image");

            var newProject = new Project
            {
                Name        = input.Name,
                Description = input.Description,
                HeadImageId = imageId,
            };

            await this.dbProject.AddAsync(newProject);

            await this.dbProject.SaveChangesAsync();

            return(newProject.Id);
        }
        public async Task TestDeleteProject()
        {
            var projectInputModel = new ProjectInputModel
            {
                Name        = "test",
                Description = "Lorem",
                HeadImage   = this.file,
            };

            var projectId = await this.projectsService.CreateProjectAsync(projectInputModel);

            await this.projectsService.DeleteProjectAsync(projectId);

            var project = await this.projectsService.GetProjectByIdAsync(projectId);

            Assert.Null(project);
        }
Beispiel #15
0
        public async void SaveProject()
        {
            if (RequiredProjectFieldsFilled())
            {
                Project project = ProjectInputModel.ToProject(ProjectInputModel);
                await((App)App.Current).projects.CreateAsync(project);

                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                              () =>
                {
                    AddedTags.Clear();
                });

                ProjectInputModel              = new ProjectInputModel();
                StudentProfileInputModel       = new StudentProfileInputModel();
                FacultyMemberProfileInputModel = new FacultyMemberProfileInputModel();
            }
        }
Beispiel #16
0
        public async Task <IActionResult> Post([FromBody] ProjectInputModel request)
        {
            var project = new Project(
                name: request.Name,
                description: request.Description,
                budget: request.Budget,
                idClient: request.IdClient
                );

            _apiContext.Projects.Add(project);
            var success = await _apiContext.SaveChangesAsync() > 0;

            if (success)
            {
                return(CreatedAtAction(nameof(GetById), project, new { id = project.Id }));
            }
            throw new Exception("Ocorreu um problema ao salvar os dados");
        }
Beispiel #17
0
        public async Task <ActionResult <ProjectModel> > Update(long id, ProjectInputModel model)
        {
            _logger.LogDebug($"Updating project with id {id}");

            var project = await _dbContext.Projects.FindAsync(id);

            var client = await _dbContext.Clients.FindAsync(model.ClientId);

            if (project == null || client == null)
            {
                return(NotFound());
            }

            project.Client = client;
            model.MapTo(project);

            _dbContext.Projects.Update(project);
            await _dbContext.SaveChangesAsync();

            return(ProjectModel.FromProject(project));
        }
        public async Task TestAddImageToGallery()
        {
            var projectInputModel = new ProjectInputModel
            {
                Name        = "test",
                Description = "Lorem",
                HeadImage   = this.file,
            };

            var projectId = await this.projectsService.CreateProjectAsync(projectInputModel);

            var imageInputModel = new ImageInputModel
            {
                ProjectId   = projectId,
                Description = "Lorem",
                ImageFile   = this.file,
            };

            var id = await this.projectsGalleryService.AddImageToGalleryAsync(imageInputModel);

            Assert.NotEqual(0, id);
        }
Beispiel #19
0
        public async Task UpdateProjectAsync(ProjectInputModel input)
        {
            var currentProject = this.dbProject.All().Where(p => p.Id == input.Id).FirstOrDefault();

            if (input.HeadImage != null)
            {
                var imageId = await this.filesService.UploadToFileSystemAsync(input.HeadImage, "images/projecImages");

                currentProject.HeadImageId = imageId;
            }

            if (currentProject.Name != input.Name)
            {
                currentProject.Name = input.Name;
            }

            if (currentProject.Description != input.Description)
            {
                currentProject.Description = input.Description;
            }

            this.dbProject.Update(currentProject);
            await this.dbProject.SaveChangesAsync();
        }
        public async Task <ActionResult <ResponseModel <ProjectModel> > > CreateClientProjectAsync([FromBody] ProjectInputModel inputModel, int id)
        {
            var project = await _projectManager.CreateAsync(
                inputModel.Name,
                inputModel.Budget,
                inputModel.Currency,
                inputModel.HourlyRate,
                id,
                CurrentUser.Id
                );

            if (project != null)
            {
                return(Ok(new ResponseModel <ProjectModel>(new ProjectModel(project))));
            }
            else
            {
                return(BadRequest(new ErrorModel("Unable to create a Project for this Client.")));
            }
        }
Beispiel #21
0
 public void Cancel()
 {
     ProjectInputModel              = new ProjectInputModel();
     StudentProfileInputModel       = new StudentProfileInputModel();
     FacultyMemberProfileInputModel = new FacultyMemberProfileInputModel();
 }
Beispiel #22
0
        public async Task <ActionResult <ResponseModel <ProjectModel> > > UpdateAsync([FromBody] ProjectInputModel input, int id)
        {
            var project = await _projectManager.UpdateAsync(
                id,
                input.Name,
                input.Budget,
                input.Currency,
                input.HourlyRate,
                CurrentUser.Id
                );

            if (project != null)
            {
                return(Ok(new ResponseModel <ProjectModel>(new ProjectModel(project))));
            }
            else
            {
                return(BadRequest(new ErrorModel("Unable to update Project.")));
            }
        }