public DatabaseResult Add(CreateProblem createProblem) { var databaseResult = new DatabaseResult { Success = false }; var result = _problemRepository.Add(createProblem); if (result != 0) { databaseResult.Key = result; databaseResult.Success = true; if (createProblem.Tags != null && createProblem.Tags.Any()) { var tags = createProblem.Tags.Select(x => new CreateTagDto { Name = x }); foreach (var createTagDto in tags) { _tagRepository.AddProblemTag(createTagDto, result); } } if (!string.IsNullOrEmpty(createProblem.AssignedUser)) { _notificationService.SendNotification(createProblem.AssignedUser, result, $"Jums priskirta problema: {createProblem.Name}"); } } return(databaseResult); }
public IActionResult Post([FromBody] CreateProblem value) { if (ModelState.IsValid) { var result = _problemService.Add(value); if (result.Success) { return(Ok(result.Key)); } } return(BadRequest()); }
public int Add(CreateProblem problem) { using (IDbConnection dbConnection = Connection) { dbConnection.Open(); using (var transaction = dbConnection.BeginTransaction()) { var createdId = dbConnection.ExecuteScalar <int>(ProblemQueries.Add, problem, transaction); dbConnection.Execute(ProblemCategoryQueries.Add, new { CategoryId = problem.Category, ProblemId = createdId }, transaction); transaction.Commit(); return(createdId); } } }