Exemplo n.º 1
0
        public async Task <int> Add(Core.Entities.Book entity)
        {
            var status_aux = "'Disponivel'";

            if (entity.Status == Core.Enums.BookStatus.Indisponivel)
            {
                status_aux = "'Indisponivel'";
            }

            string script = @"INSERT INTO Books (Category, Name, Author, Pages, Status)
                            Values (@Category, @Name, @Author, @Pages, " + status_aux + @");";

            using (var connection = new SqlConnection(_configuration.GetConnectionString("DefaultConnection")))
            {
                connection.Open();
                var response = await connection.ExecuteAsync(script, entity);

                connection.Close();
                return(response);
            }
        }
Exemplo n.º 2
0
        public async Task <int> Update(Core.Entities.Book entity)
        {
            var id = entity.Id;

            var status_aux = "'Disponivel'";

            if (entity.Status == Core.Enums.BookStatus.Indisponivel)
            {
                status_aux = "'Indisponivel'";
            }

            string script = @"UPDATE Books SET Category = @Category, Name = @Name, Author = @Author,
                              Pages = @Pages, Status = " + status_aux + " WHERE Id = " + id + ";";

            using (var connection = new SqlConnection(_configuration.GetConnectionString("DefaultConnection")))
            {
                connection.Open();
                var result = await connection.ExecuteAsync(script, entity);

                connection.Close();
                return(result);
            }
        }