Exemplo n.º 1
0
        public async Task <Project> CreateProject(CreateProjectModel model)
        {
            using (var connection = _connectionHelper.GetConnection())
            {
                var id = await connection
                         .ExecuteScalarAsync <int>(
                    "INSERT INTO [PROJECT] ([Name], [Description]) VALUES (@Name, @Description) SELECT SCOPE_IDENTITY()",
                    model).ConfigureAwait(false);

                return(await connection
                       .QuerySingleOrDefaultAsync <Project>("SELECT * FROM [PROJECT] WHERE [Id] = @Id", new { Id = id })
                       .ConfigureAwait(false));
            }
        }
Exemplo n.º 2
0
        public async Task<Plan> CreatePlan(CreatePlanModel model)
        {
            using (var connection = _connectionHelper.GetConnection())
            {
                var projectId = await connection
                    .ExecuteScalarAsync<int>("SELECT [ID] FROM [Project] WHERE [Guid] = @Guid",
                        new {Guid = model.ProjectGuid}).ConfigureAwait(false);

                if (projectId == default(int))
                    throw new EntityNotFoundException($"Unable to find the project with the guid: {model.ProjectGuid}");

                var id = await connection.ExecuteScalarAsync<int>(@"
                    INSERT INTO [Plan] ([Name], [Description], [ProjectId], [ProjectGuid], [Enabled])
                    VALUES (@Name, @Description, @ProjectId, @ProjectGuid, @Enabled)
                    SELECT SCOPE_IDENTITY()",
                    new
                    {
                        ProjectId = projectId,
                        model.Name,
                        model.Description,
                        model.ProjectGuid,
                        model.Enabled
                    }
                ).ConfigureAwait(false);

                return await connection
                    .QuerySingleOrDefaultAsync<Plan>(@"SELECT * FROM [Plan] WHERE [Id] = @Id", new {Id = id})
                    .ConfigureAwait(false);
            }
        }