public async Task <IActionResult> CreateProjectFile(string id) { var projectId = new ProjectFileCreateModel { ProjectId = id, }; return(this.View(projectId)); }
public async Task <IActionResult> AddProjectFile(ProjectFileCreateModel model) { if (this.ModelState.IsValid) { await this.projectFileService.AddProjectFile(model); } return(this.Redirect("/Home/IndexLoggedin")); }
public async Task <ProjectFileViewModel> AddProjectFile(ProjectFileCreateModel projectFile) { var project = this.context .Projects .Where(p => p.Id == projectFile.ProjectId) .SingleOrDefault(); var file = projectFile.File; if (this.context.ProjectFiles.Any(p => p.Name == projectFile.Name)) { return(null); } string projectFileUrl = await this.cloudinaryService.UploadProjectFileAsync(projectFile.File, Guid.NewGuid().ToString()); var newFile = new ProjectFile { IsApproved = projectFile.IsApproved, AddedOn = projectFile.AddedOn, ProjectId = project.Id, IsPublic = projectFile.IsPublic, Name = projectFile.Name, Url = projectFileUrl, }; project.ProjectFiles.Add(newFile); await this.context.SaveChangesAsync(); var result = new ProjectFileViewModel { IsApproved = newFile.IsApproved, IsPublic = newFile.IsPublic, Url = newFile.Url, }; return(result); }
private Project AddProject() { var model = new ProjectCreateInputModel { Designer = new ApplicationUser { Id = new Guid("db2bd817-98cd-4cf3-a80a-53ea0cd9c200").ToString(), Email = "*****@*****.**", PasswordHash = 5.GetHashCode().ToString(), }, Customer = new ApplicationUser { Id = new Guid("cb2bd817-98cd-4cf3-a80a-53ea0cd9c200").ToString(), Email = "*****@*****.**", PasswordHash = 5.GetHashCode().ToString(), }, Name = "Test", IsPublic = true, }; var project = new Project { Id = new Guid("bb2bd817-98cd-4cf3-a80a-53ea0cd9c200").ToString(), DesignerId = model.Designer.Id, CustomerId = model.Customer.Id, Name = model.Name, IsPublic = model.IsPublic, }; var projectFile = new ProjectFileCreateModel { File = new Mock <IFormFile>().Object, IsApproved = false, IsPublic = true, Name = "TestProjectFile", ProjectId = project.Id, }; var projectFileResult = new ProjectFile { Id = new Guid("ab2bd817-98cd-4cf3-a80a-53ea0cd9c200").ToString(), IsApproved = projectFile.IsApproved, IsPublic = projectFile.IsPublic, Name = "TestProjectFile.jpg", ProjectId = project.Id, }; var revew = new ProjectReview { ProjectId = project.Id, CustomerId = new Guid("cb2bd817-98cd-4cf3-a80a-53ea0cd9c200").ToString(), Review = "First Review", }; var designBoard = new DesignBoard { ProjectId = project.Id, CustomerId = new Guid("cb2bd817-98cd-4cf3-a80a-53ea0cd9c200").ToString(), Id = new Guid("de2bd817-98cd-4cf3-a80a-53ea0cd9c200").ToString(), Name = "Test Design Board", DesignReferences = new List <DesignReference>(), }; var designRefernce = new DesignReference { CustomerId = new Guid("cb2bd817-98cd-4cf3-a80a-53ea0cd9c200").ToString(), ImageUrl = "https://test.test", DesignBoardId = "de2bd817-98cd-4cf3-a80a-53ea0cd9c200", }; project.ProjectReviews.Add(revew); project.ProjectFiles.Add(projectFileResult); project.DesignBoards.Add(designBoard); project.DesignBoards[0].DesignReferences.Add(designRefernce); return(project); }