public async Task <IActionResult> GetUserStory(int projectId, int UserStoryId) // userStoryId { if (!IsCurrentUserInProject(projectId)) { return(Unauthorized()); } var workItem = new UserStoryUpdateViewModel() { PrioritiesDropDown = this.mapper.Map <ICollection <BacklogPriorityDropDownModel> > (await this.backlogPrioritiesService.GetAllAsync()), SprintDropDownModel = (await this.sprintsService.GetSprintDropDownAsync(projectId)), ViewModel = this.mapper.Map <UserStoryViewModel>(await userStoryService.GetAsync(UserStoryId)), }; if (workItem.ViewModel == null) { return(NotFound()); } return(View(workItem)); }
public async Task <IActionResult> GetUserStory(UserStoryUpdateViewModel model, int projectId) { if (!IsCurrentUserInProject(projectId)) { return(Unauthorized()); } if (!ModelState.IsValid) { // If model is not valid prioritiesDropDown will be null so we need do populated it. model.PrioritiesDropDown = this.mapper.Map <ICollection <BacklogPriorityDropDownModel> > (await this.backlogPrioritiesService.GetAllAsync()); model.SprintDropDownModel = await this.sprintsService.GetSprintDropDownAsync(projectId); return(View(model)); } var userStory = this.mapper.Map <UserStoryUpdateModel>(model.ViewModel); userStory.AcceptanceCriteria = model.ViewModel.SanitizedAcceptanceCriteria; userStory.Description = model.ViewModel.SanitizedDescription; if (!string.IsNullOrEmpty(model.Comment.Description)) { var userId = int.Parse(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); userStory.Comment = model.Comment; userStory.Comment.UserStoryId = model.ViewModel.Id; userStory.Comment.AddedById = userId; } try { var savedFilepaths = new List <string>(); if (model.ViewModel.MockupFiles?.Count > 0) { Account account = new Account( config["Cloudinary:CloudName"], config["Cloudinary:ApiKey"], config["Cloudinary:ApiSecret"] ); Cloudinary cloudinary = new Cloudinary(account); foreach (var file in model.ViewModel.MockupFiles) { string filePath = Guid.NewGuid().ToString(); var uploadParams = new ImageUploadParams() { File = new FileDescription(filePath + ".png", file.OpenReadStream()), Overwrite = true, }; var uploadResult = cloudinary.Upload(uploadParams); savedFilepaths.Add(uploadResult.SecureUrl.AbsoluteUri); } } userStory.MockupPaths = savedFilepaths; await this.userStoryService.UpdateAsync(userStory); return(RedirectToAction(nameof(GetAll), new { projectId = projectId })); } catch (Exception) { return(RedirectToAction("Error", "Error")); } }