コード例 #1
0
 public void CreateContact(ContactCreateDbo contact)
 {
     using (var connection = GetConnection())
     {
         connection.Insert("Contact", contact);
     }
 }
コード例 #2
0
        public IActionResult Post(NewContactRequest request, [FromHeader] string authorization)
        {
            UserReadDbo user = _auth.ValidateUser(authorization);

            if (user == null)
            {
                return(_auth.GetError());
            }

            DateTime?birthdate = null;

            if (!string.IsNullOrEmpty(request.Birthdate))
            {
                DateTime dt;
                if (DateTime.TryParse(request.Birthdate, out dt))
                {
                    birthdate = dt;
                }
                else
                {
                    return(Error.BadRequest("Invalid birthdate"));
                }
            }

            DateTime now = DateTime.UtcNow;

            ContactCreateDbo dbo = new ContactCreateDbo
            {
                UserId      = user.Id,
                Name        = request.Name,
                Birthdate   = birthdate,
                Favorite    = request.Favorite,
                GroupId     = request.GroupId,
                Description = request.Description,
                CreatedAt   = now,
                UpdatedAt   = now,
            };

            _repo.CreateContact(dbo);

            return(Ok());
        }