public HistoryResponse Create(HistoryCreateRequest req) { int id = _history.Create(req); HistoryResponse resp = new HistoryResponse(); resp.Id = id; resp.Date = req.Date; resp.Title = req.Title; resp.Description = req.Description; resp.CreatedAt = DateTime.Now; resp.UpdatedAt = DateTime.Now; return(resp); }
public int Create(HistoryCreateRequest req) { int result = 0; using (SqlConnection conn = new SqlConnection(ConnString)) { using (SqlCommand cmd = new SqlCommand("TechHistory_Insert", conn)) { cmd.CommandType = CommandType.StoredProcedure; SqlParameter p = new SqlParameter("@Id", SqlDbType.Int); p.Direction = ParameterDirection.Output; cmd.Parameters.Add(p); cmd.Parameters.AddWithValue("@Date", req.Date); cmd.Parameters.AddWithValue("@Title", req.Title); cmd.Parameters.AddWithValue("@Description", req.Description); conn.Open(); cmd.ExecuteNonQuery(); result = (int)cmd.Parameters["@Id"].Value; conn.Close(); } } return(result); }
public IActionResult CreateHistory([FromBody] HistoryCreateRequest req) { HistoryResponse resp = _historyRepository.Create(req); return(CreatedAtAction("GetHistoryById", new { historyId = resp.Id }, resp)); }