public BirthdateResponse Create(BirthdateCreateRequest req) { int id = _birthdates.Create(req); BirthdateResponse resp = new BirthdateResponse(); resp.Id = id; resp.FullName = req.FullName; resp.Dob = req.Dob; resp.Dod = req.Dod; resp.Notoriety = req.Notoriety; resp.CreatedAt = DateTime.Now; resp.UpdatedAt = DateTime.Now; return(resp); }
private void CreateRecord() { BirthdateCreateRequest req = new BirthdateCreateRequest(); Console.Write("Full Name: "); req.FullName = Console.ReadLine(); Console.Write("Date of Birth: "); req.Dob = DateTime.Parse(Console.ReadLine()); Console.Write("Date of Death: "); if (DateTime.TryParse(Console.ReadLine(), out var dod)) { req.Dod = dod; } Console.Write("Notoriety: "); req.Notoriety = Console.ReadLine(); _repo.Create(req); }
public int Create(BirthdateCreateRequest req) { int result = 0; using (SqlConnection conn = new SqlConnection(ConnString)) { using (SqlCommand cmd = new SqlCommand("BirthDates_Insert", conn)) { cmd.CommandType = CommandType.StoredProcedure; SqlParameter p = new SqlParameter("@Id", SqlDbType.Int); p.Direction = ParameterDirection.Output; cmd.Parameters.Add(p); cmd.Parameters.AddWithValue("@FulName", req.FullName); cmd.Parameters.AddWithValue("@Dob", req.Dob); cmd.Parameters.AddWithValue("@Dod", req.Dod); cmd.Parameters.AddWithValue("@Notoriety", req.Notoriety); conn.Open(); cmd.ExecuteNonQuery(); result = (int)cmd.Parameters["@Id"].Value; conn.Close(); } } return(result); }
public IActionResult CreateBirthDate([FromBody] BirthdateCreateRequest req) { BirthdateResponse resp = _birthdateRepository.Create(req); return(CreatedAtAction("GetBirthDateById", new { birthDateId = resp.Id }, resp)); }