Ejemplo n.º 1
0
        public async Task <ProfileConfirmation> CreateAsync(ProfileConfirmation profileConfirmation)
        {
            var command = "INSERT INTO public.\"ProfileConfirmation\" " +
                          " (" +
                          $"\"{nameof(ProfileConfirmation.Id)}\", " +
                          $"\"{nameof(ProfileConfirmation.UserId)}\", " +
                          $"\"{nameof(ProfileConfirmation.CreationDate)}\", " +
                          $"\"{nameof(ProfileConfirmation.LastModified)}\", " +
                          $"\"{nameof(ProfileConfirmation.IsDeleted)}\", " +
                          $"\"{nameof(ProfileConfirmation.Description)}\") " +
                          "VALUES (@Id, @UserId, @CreationDate, @LastModified, @IsDeleted, @Description);";

            int rowsInserted;

            using (var sqlConnection = await _context.CreateConnectionAsync())
            {
                rowsInserted = await sqlConnection.ExecuteAsync(command, new
                {
                    profileConfirmation.Id,
                    profileConfirmation.UserId,
                    profileConfirmation.CreationDate,
                    profileConfirmation.LastModified,
                    profileConfirmation.IsDeleted,
                    profileConfirmation.Description
                });
            }

            if (rowsInserted != 1)
            {
                throw new ApplicationApiException(HttpStatusCode.BadRequest, $"Unable to create {nameof(ProfileConfirmation)} object");
            }

            return(profileConfirmation);
        }
Ejemplo n.º 2
0
        public async Task <PersonPhoto> CreateAsync(PersonPhoto personPhoto)
        {
            var command = "INSERT INTO public.\"PersonPhoto\" " +
                          " (" +
                          $"\"{nameof(PersonPhoto.Id)}\", " +
                          $"\"{nameof(PersonPhoto.UserId)}\"," +
                          $"\"{nameof(PersonPhoto.FileName)}\", " +
                          $"\"{nameof(PersonPhoto.CreationDate)}\", " +
                          $"\"{nameof(PersonPhoto.LastModified)}\")" +
                          "VALUES (@Id, @UserId, @FileName, @CreationDate, @LastModified);";

            int rowsInserted;

            using (var sqlConnection = await _context.CreateConnectionAsync())
            {
                rowsInserted = await sqlConnection.ExecuteAsync(command, new
                {
                    personPhoto.Id,
                    personPhoto.UserId,
                    personPhoto.FileName,
                    personPhoto.CreationDate,
                    personPhoto.LastModified
                });
            }

            if (rowsInserted != 1)
            {
                throw new ApplicationApiException(HttpStatusCode.BadRequest, $"Unable to create {nameof(PersonPhoto)} object");
            }

            return(personPhoto);
        }