public IActionResult PostNewQuestion(NewQuestionDto question, [FromRoute] string orgId) { try { _unitOfWorkManager.StartUnitOfWork(); Question createdQuestion = _questionnaireManager.AddQuestion( question.Inquiry, question.Required, question.QuestionType, question.QuestionnaireId); _unitOfWorkManager.EndUnitOfWork(); return(CreatedAtAction( "GetQuestion", new { orgId, id = createdQuestion.QuestionId }, _mapper.Map <QuestionMinDto>(createdQuestion))); } catch (ValidationException ve) { return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}")); } catch (Exception e) { return(BadRequest($"Something went wrong in creating the question: {e.Message}.")); } }
public IActionResult PostNewProjectPhase(NewProjectPhaseDto newPhase, [FromRoute] string orgId) { try { _unitOfWorkManager.StartUnitOfWork(); ProjectPhase phase = _projectManager.AddProjectPhase( newPhase.Title, newPhase.Description, newPhase.StartDate, newPhase.EndDate, newPhase.ProjectId); _unitOfWorkManager.EndUnitOfWork(); return(CreatedAtAction( "GetProjectPhase", new { orgId, id = phase.ProjectPhaseId }, _mapper.Map <ProjectPhaseDto>(phase))); } catch (ValidationException ve) { return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}")); } catch (Exception e) { return(BadRequest($"Something went wrong in creating the project phase: {e.Message}.")); } }
public async Task <IActionResult> PostNewProject([FromForm] NewProjectDto newProj, [FromRoute] string orgId) { try { _unitOfWorkManager.StartUnitOfWork(); Project p = _projectManager.AddProject( newProj.Title, newProj.StartDate, newProj.EndDate, newProj.OrganisationId); foreach (var video in newProj.Videos) { string imgLocation = await _fileService.ConvertFileToLocation(video); _ideationManager.AddFieldToProject(FieldType.Video, imgLocation, p.ProjectId); } foreach (var image in newProj.Images) { string imgLocation = await _fileService.ConvertFileToLocation(image); _ideationManager.AddFieldToProject(FieldType.Picture, imgLocation, p.ProjectId); } foreach (var textfield in newProj.Texts) { _ideationManager.AddFieldToProject(FieldType.Text, textfield, p.ProjectId); } foreach (var location in newProj.Locations) { _ideationManager.AddFieldToProject(FieldType.Location, location, p.ProjectId); } foreach (var link in newProj.Links) { _ideationManager.AddFieldToProject(FieldType.Link, link, p.ProjectId); } _unitOfWorkManager.EndUnitOfWork(); return(CreatedAtAction( "GetProject", new { orgId, id = p.ProjectId }, _mapper.Map <ProjectDto>(p))); } catch (ValidationException ve) { return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}")); } catch (Exception e) { return(BadRequest($"Something went wrong in creating the project: {e.Message}.")); } }
public Vote AddVoteToIdea(int value, string userId, string email, int ideaId) { _unitOfWorkManager.StartUnitOfWork(); bool isUserVote = !userId.IsNullOrEmpty(); bool isEmailVote = !email.IsNullOrEmpty(); Vote vote = null; if (isUserVote) { vote = _userManager.GetVoteForIdea(ideaId, userId); } else if (isEmailVote) { vote = _userManager.GetEmailVoteForIdea(ideaId, email); } if (vote == null) { if (isUserVote) { vote = _userManager.AddVoteToUser(value, userId); } else if (isEmailVote) { vote = _userManager.AddVoteWithEmail(value, email); } else { vote = _userManager.AddAnonymousVote(value); } } else { vote = _userManager.ChangeVoteValue(vote.VoteId, value); } _ideationManager.AddVoteToIdea(vote, ideaId); _unitOfWorkManager.EndUnitOfWork(); if (vote == null) { throw new Exception("Something went wrong while creating the vote."); } return(vote); }
public IActionResult PostNewQuestionnaire(NewQuestionnaireDto newQuestionnaire, [FromRoute] string orgId) { try { _unitOfWorkManager.StartUnitOfWork(); Questionnaire questionnaire = _questionnaireManager.AddQuestionnaire(newQuestionnaire.Title, newQuestionnaire.Description, newQuestionnaire.ProjectPhaseId); _unitOfWorkManager.EndUnitOfWork(); return(CreatedAtAction( "GetQuestionnaire", new { orgId, id = questionnaire.QuestionnaireId }, _mapper.Map <QuestionnaireDto>(questionnaire) )); } catch (ValidationException ve) { return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}")); } catch (Exception e) { return(BadRequest($"Something went wrong in creating the questionnaire: {e.Message}.")); } }
public IActionResult PostNewOrganisation(NewOrganisationDto newOrg) { try { _unitOfWorkManager.StartUnitOfWork(); Organisation org = _organisationManager.AddOrganisation(newOrg.Name, newOrg.Identifier, newOrg.Description, newOrg.Color); _unitOfWorkManager.EndUnitOfWork(); return(CreatedAtAction( "GetOrganisation", new { id = org.OrganisationId }, _mapper.Map <OrganisationDto>(org) )); } catch (ValidationException ve) { return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}")); } catch (Exception e) { var msg = e.InnerException != null ? e.InnerException.Message : e.Message; return(BadRequest($"Something went wrong in creating the organisation: {msg}.")); } }
public IActionResult PostNewAnswer(List <NewAnswerDto> answerInputs) { try { // UoW is started here to make sure the request either fails or succeeds fully _unitOfWorkManager.StartUnitOfWork(); List <Answer> answers = new List <Answer>(); answerInputs.ForEach(answer => { Answer createdAnswer = null; if (answer.OptionId != null && answer.OptionId != 0) { createdAnswer = _cityOfIdeasController.AddAnswerToOption(answer.UserId, answer.OptionId.Value); } else if (answer.QuestionId != null && answer.QuestionId != 0) { createdAnswer = _cityOfIdeasController.AddAnswerToQuestion(answer.Content, answer.UserId, answer.QuestionId.Value); } else { throw new Exception("Invalid answer: either option or question id should be given."); } if (createdAnswer != null) { answers.Add(createdAnswer); } }); _unitOfWorkManager.EndUnitOfWork(); return(Ok(_mapper.Map <List <AnswerDto> >(answers))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> PostNewIdea([FromForm] NewIdeaDto idea, [FromRoute] string orgId) { if (idea.Texts.IsNullOrEmpty() && idea.Images.IsNullOrEmpty()) { return(BadRequest("Either images or text content should be provided.")); } try { // UoW is started here to make sure the request either fails or succeeds fully _unitOfWorkManager.StartUnitOfWork(); Idea createdIdea = _ideationManager.AddIdea( idea.Title, idea.IdeationId); _userManager.AddIdeaToUser(createdIdea, idea.UserId); foreach (var video in idea.Videos) { string imgLocation = await _fileService.ConvertFileToLocation(video); _ideationManager.AddFieldToIdea(FieldType.Video, imgLocation, createdIdea.IdeaId); } foreach (var image in idea.Images) { string imgLocation = await _fileService.ConvertFileToLocation(image); _ideationManager.AddFieldToIdea(FieldType.Picture, imgLocation, createdIdea.IdeaId); } foreach (var textfield in idea.Texts) { _ideationManager.AddFieldToIdea(FieldType.Text, textfield, createdIdea.IdeaId); } foreach (var location in idea.Locations) { _ideationManager.AddFieldToIdea(FieldType.Location, location, createdIdea.IdeaId); } foreach (var link in idea.Links) { _ideationManager.AddFieldToIdea(FieldType.Link, link, createdIdea.IdeaId); } _unitOfWorkManager.EndUnitOfWork(); return(CreatedAtAction( "GetIdea", new { orgId, id = createdIdea.IdeaId }, _mapper.Map <IdeaMinDto>(createdIdea))); } catch (ValidationException ve) { return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}")); } catch (Exception e) { return(BadRequest($"Something went wrong in creating the idea: {e.Message}.")); } }
public async Task <IActionResult> PostNewIdeaComment([FromForm] NewIdeaCommentDto comment, [FromRoute] string orgId) { if (comment.Texts.IsNullOrEmpty() && comment.Images.IsNullOrEmpty()) { return(BadRequest("Either images or text content should be provided.")); } try { // UoW is started here to make sure the request either fails or succeeds fully _unitOfWorkManager.StartUnitOfWork(); Comment createdComment = _coiCtrl.AddCommentToIdea( comment.UserId, comment.IdeaId); foreach (var video in comment.Videos) { string imgLocation = await _fileService.ConvertFileToLocation(video); _ideationManager.AddFieldToComment(FieldType.Video, imgLocation, createdComment.CommentId); } foreach (var image in comment.Images) { string imgLocation = await _fileService.ConvertFileToLocation(image); _ideationManager.AddFieldToComment(FieldType.Picture, imgLocation, createdComment.CommentId); } foreach (var textfield in comment.Texts) { _ideationManager.AddFieldToComment(FieldType.Text, textfield, createdComment.CommentId); } foreach (var location in comment.Locations) { _ideationManager.AddFieldToComment(FieldType.Location, location, createdComment.CommentId); } foreach (var link in comment.Links) { _ideationManager.AddFieldToComment(FieldType.Link, link, createdComment.CommentId); } _unitOfWorkManager.EndUnitOfWork(); return(CreatedAtAction( "GetComment", new { orgId, id = createdComment.CommentId }, _mapper.Map <CommentDto>(createdComment))); } catch (ValidationException ve) { return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}")); } catch (ArgumentException e) { switch (e.ParamName) { case "ideaId": return(UnprocessableEntity(e.Message)); case "userId": return(UnprocessableEntity(e.Message)); default: return(BadRequest(e.Message)); } } }
public IActionResult UpdateField(int id, NewFieldDto updatedValues) { try { // UoW is started here to make sure the request either fails or succeeds fully _unitOfWorkManager.StartUnitOfWork(); Field updatedField = null; if (updatedValues.IdeaId.HasValue && updatedValues.IdeaId != 0) { updatedField = _ideationManager.ChangeIdeaField(id, updatedValues.FieldType, updatedValues.Content, updatedValues.IdeaId.Value); } else if (updatedValues.IdeationId.HasValue && updatedValues.IdeationId != 0) { updatedField = _ideationManager.ChangeIdeationField(id, updatedValues.FieldType, updatedValues.Content, updatedValues.IdeationId.Value); } else if (updatedValues.CommentId.HasValue && updatedValues.CommentId != 0) { updatedField = _ideationManager.ChangeCommentField(id, updatedValues.FieldType, updatedValues.Content, updatedValues.CommentId.Value); } else if (updatedValues.ProjectId.HasValue && updatedValues.ProjectId != 0) { updatedField = _ideationManager.ChangeProjectField(id, updatedValues.FieldType, updatedValues.Content, updatedValues.ProjectId.Value); } else { return(BadRequest("Idea, ideation or comment ID should be given.")); } _unitOfWorkManager.EndUnitOfWork(); if (updatedField == null) { return(BadRequest("Something went wrong while updating the field.")); } return(Ok(_mapper.Map <FieldDto>(updatedField))); } catch (ValidationException ve) { return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}")); } catch (ArgumentException e) { switch (e.ParamName) { case "id": return(NotFound(e.Message)); case "ideaId": return(UnprocessableEntity(e.Message)); case "ideationId": return(UnprocessableEntity(e.Message)); case "commentId": return(UnprocessableEntity(e.Message)); default: return(BadRequest(e.Message)); } } }