public IHttpActionResult Post([FromBody] ProjectRequestModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var currentUserId = User.Identity.GetUserId(); var user = this.data.Clients.Find(x => x.Id == currentUserId).FirstOrDefault(); if (user == null) { return(this.BadRequest("Only clients can post projects!")); } var projectToAdd = Mapper.Map <Project>(model); projectToAdd.Client = user; projectToAdd.TimePublished = DateTime.Now; this.data.Projects.Add(projectToAdd); this.data.SaveChanges(); var message = string.Format("Post activity: User {0} created project {1} | {2}", user.Email, projectToAdd.Name, "/projects"); pubnubClient.Broadcast(Constants.PubnubChannelActivityFeed, message, str => { }, s => { }); return(this.Ok(projectToAdd.Id)); }
public async Task <IHttpActionResult> Post(ProjectRequestModel project) { var collaborators = await this.UsersService.CollaboratorsFromCommaSeparatedValues(project.Collaborators, this.CurrentUser.UserName); var tags = await this.tagsService.TagsFromCommaSeparatedValues(project.Tags); var processedImages = await this.imagesService.ProcessImages(project.Images.Select(FileRequestModel.ToRawFile)); var downloadableFiles = await this.downloadableFilesService.AddNew( project.Files != null ?project.Files.Select(FileRequestModel.ToRawFile) : new List <RawFile>()); await this.fileSystemService.SaveImages(processedImages); await this.fileSystemService.SaveDownloadableFiles(downloadableFiles); var addedProject = await this.projectsService.AddNew( this.mappingService.Map <Project>(project), collaborators, tags, processedImages, project.MainImage, downloadableFiles); return(this.Ok(this.mappingService.Map <PostProjectResponseModel>(addedProject))); }
public static ProjectRequestModel GetProjectWithoutName(ProjectRequestModel project) { return(new ProjectRequestModel { Announcement = project.Announcement, ShowAnnouncement = project.ShowAnnouncement, SuiteMode = project.SuiteMode }); }
public static ProjectRequestModel CreateInvalid() { var model = new ProjectRequestModel { Name = "", Description = "TestDescription", PricePerHour = -10, Attachments = new List <AttachmentRequestModel> { new AttachmentRequestModel() } }; return(model); }
public static ProjectRequestModel CreateInvalid() { var model = new ProjectRequestModel { Name = "", Description = "TestDescription", PricePerHour = -10, Attachments = new List<AttachmentRequestModel> { new AttachmentRequestModel() } }; return model; }
public static ProjectRequestModel Create() { var model = new ProjectRequestModel { Name = "This is another fake project", Description = "TestDescriptionTestDescriptionTestDescription TestDescription TestDescription TestDescription TestDescription TestDescriptionTestDescriptionTestDescription TestDescription", CategoryId = 1, PricePerHour = 60, Attachments = new List <AttachmentRequestModel> { new AttachmentRequestModel { Name = "Test name", Url = "http://example.com" } } }; return(model); }
public static ProjectRequestModel Create() { var model = new ProjectRequestModel { Name = "This is another fake project", Description = "TestDescriptionTestDescriptionTestDescription TestDescription TestDescription TestDescription TestDescription TestDescriptionTestDescriptionTestDescription TestDescription", CategoryId = 1, PricePerHour = 60, Attachments = new List<AttachmentRequestModel> { new AttachmentRequestModel { Name = "Test name", Url = "http://example.com" } } }; return model; }
public IHttpActionResult Post(ProjectRequestModel projectForDb) { if (projectForDb == null) { return this.BadRequest("The body of the POST method should not be empty"); } if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var result = this.projectService.Add( projectForDb.Title, projectForDb.Description, projectForDb.StartDate, projectForDb.Deadline, projectForDb.Creator ); return this.Ok(result); }
public async Task<IHttpActionResult> Post(ProjectRequestModel project) { var collaborators = await this.UsersService.CollaboratorsFromCommaSeparatedValues(project.Collaborators, this.CurrentUser.UserName); var tags = await this.tagsService.TagsFromCommaSeparatedValues(project.Tags); var processedImages = await this.imagesService.ProcessImages(project.Images.Select(FileRequestModel.ToRawFile)); var downloadableFiles = await this.downloadableFilesService.AddNew( project.Files != null ? project.Files.Select(FileRequestModel.ToRawFile) : new List<RawFile>()); await this.fileSystemService.SaveImages(processedImages); await this.fileSystemService.SaveDownloadableFiles(downloadableFiles); var addedProject = await this.projectsService.AddNew( this.mappingService.Map<Project>(project), collaborators, tags, processedImages, project.MainImage, downloadableFiles); return this.Ok(this.mappingService.Map<PostProjectResponseModel>(addedProject)); }