Skip to content

Commit

Permalink
add listview and editor config + CRUD repository methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jemayn committed Nov 21, 2023
1 parent caf363a commit bfcbacc
Show file tree
Hide file tree
Showing 77 changed files with 2,184 additions and 11 deletions.
102 changes: 100 additions & 2 deletions TwentyFourDays.Persistence/Repositories/MovieRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Linq.Expressions;
using System.Collections;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;
using TwentyFourDays.Persistence.DbContexts;
using TwentyFourDays.Persistence.Models;
using Umbraco.Cms.Persistence.EFCore.Scoping;
Expand Down Expand Up @@ -47,8 +49,87 @@ await scope.ExecuteWithContextAsync<Task>(async db =>

scope.Complete();
}

public async Task<Movie?> GetById(int id)
{
using var scope = _scopeProvider.CreateScope();

var movie = await scope.ExecuteWithContextAsync(async db =>
{
return db.Movies.Include(x => x.Genres).FirstOrDefault(x => x.Id == id);
});

scope.Complete();

return movie;
}

public async Task<IEnumerable<Movie>?> GetAll(
public async Task<Movie?> InsertOrUpdate(Movie movie)
{
using var scope = _scopeProvider.CreateScope();

var result = await scope.ExecuteWithContextAsync<Movie>(async db =>
{
var movieGenresFromDb = db.MovieGenres.ToList();
var moviesFromDb = db.Movies.Include(x => x.Genres).ToList();
var movieFromDb = moviesFromDb.FirstOrDefault(x => x.Id == movie.Id);
var movieGenres = new List<MovieGenre>();

if (movieFromDb is not null)
{
// Set all property values to those of the incoming movie instead.
// Can't just save movie as it counts as a "new object", need to instead update the corresponding obj from the db
db.Entry(movieFromDb).CurrentValues.SetValues(movie);

foreach (var genre in movie.Genres)
{
// We need to add the genre objs from the database otherwise it will insert duplicates with different ids
var genreFromDb = movieGenresFromDb.FirstOrDefault(x => x.Id.ToString() == genre.Name);
movieGenres.Add(genreFromDb ?? genre);
}

movieFromDb.Genres = movieGenres;

db.Movies.Update(movieFromDb);
await db.SaveChangesAsync();
return movieFromDb;
}
else
{
foreach (var genre in movie.Genres)
{
// We need to add the genre objs from the database otherwise it will insert duplicates with different ids
var genreFromDb = movieGenresFromDb.FirstOrDefault(x => x.Id.ToString() == genre.Name);
movieGenres.Add(genreFromDb ?? genre);
}

movie.Genres = movieGenres;

db.Movies.Update(movie);
await db.SaveChangesAsync();
return movie;
}
});

scope.Complete();

return result;
}

public async Task Delete(Movie movie)
{
using var scope = _scopeProvider.CreateScope();

await scope.ExecuteWithContextAsync<Task>(async db =>
{
db.Movies.Remove(movie);
await db.SaveChangesAsync();
});

scope.Complete();
}

public async Task<(int TotalResults, IEnumerable<Movie>? Movies)> GetAll(
Expression<Func<Movie, bool>>? whereClause,
Expression<Func<Movie, object>>? orderBy,
bool ascending,
Expand All @@ -57,6 +138,8 @@ await scope.ExecuteWithContextAsync<Task>(async db =>
{
using var scope = _scopeProvider.CreateScope();

var totalResults = 0;

var items = await scope.ExecuteWithContextAsync(async db =>
{
var movies = db.Movies.AsQueryable();
Expand All @@ -70,6 +153,8 @@ await scope.ExecuteWithContextAsync<Task>(async db =>
{
movies = ascending ? movies.OrderBy(orderBy) : movies.OrderByDescending(orderBy);
}

totalResults = movies.Count();

if (skip is not null && take is not null)
{
Expand All @@ -81,6 +166,19 @@ await scope.ExecuteWithContextAsync<Task>(async db =>

scope.Complete();

return (totalResults, items.ToList());
}

public async Task<IEnumerable<MovieGenre>> GetAllGenres()
{
using var scope = _scopeProvider.CreateScope();

var items = await scope.ExecuteWithContextAsync(async db => db.MovieGenres);

scope.Complete();

return items.ToList();
}


}
41 changes: 41 additions & 0 deletions TwentyFourDays/App_Plugins/Contentment/Lang/da.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<language alias="da" intName="Danish" localName="Dansk" lcid="" culture="da-DK">
<creator>
<name>Chriztian Steinmeier</name>
<link>https://greystate.dk</link>
</creator>
<area alias="contentment">
<key alias="name">Contentment</key>

<!-- General -->
<key alias="removeItemMessage">Er du sikker på, at du vil fjerne denne element?</key>
<key alias="removeItemButton">Ja, fjern</key>

<!-- Configuration Editor -->
<key alias="missingItemName">Dette element er ikke længere tilgængeligt</key>
<key alias="missingItemDescription">Fjern venligst konfigurationen og vælg et andet element.</key>

<!-- Content Blocks -->
<key alias="configureDisplayMode">Vælg og konfigurer en visningstype</key>
<key alias="configureElementType">Vælg og konfigurer en elementtype</key>

<key alias="copyAllBlocks">Kopier alle blokke</key>
<key alias="editRawValue">Rediger værdi</key>

<key alias="copyContentBlock">Kopier indholdselement</key>
<key alias="createContentTemplate">Opret indholdsskabelon...</key>

<!-- Data List -->
<key alias="configureDataSource">Vælg og konfigurer en datakilde</key>
<key alias="configureListEditor">Vælg og konfigurer en liste</key>
<key alias="configurePreviewInit">Vælg og konfigurer en datakilde og en listeeditor, tak.</key>
<key alias="configurePreviewDataSource">Vælg og konfigurer en datakilde, tak.</key>
<key alias="configurePreviewListEditor">Vælg og konfigurer en liste, tak.</key>
<key alias="configurePreviewNoItems">Datakilden returnerede ingen elementer til forhåndsvisning.</key>

<key alias="checkboxListCheckAll">Tjek alle</key>
<key alias="checkboxListUncheckAll">Fjern markeringen af ​​alle</key>

<key alias="tagsType">Indtast nøgleord (tryk på Enter efter hvert nøgleord)...</key>
</area>
</language>
45 changes: 45 additions & 0 deletions TwentyFourDays/App_Plugins/Contentment/Lang/en.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<language alias="en" intName="English (UK)" localName="English (UK)" lcid="" culture="en-GB">
<creator>
<name>Lee Kelleher</name>
<link>https://leekelleher.com</link>
</creator>
<area alias="contentment">
<key alias="name">Contentment</key>

<!-- General -->
<key alias="removeItemMessage">Are you sure you want to remove this item?</key>
<key alias="removeItemButton">Yes, remove</key>

<!-- Configuration Editor -->
<key alias="missingItemName">This item is no longer available</key>
<key alias="missingItemDescription">Please remove this configuration and select another item.</key>

<!-- Content Blocks -->
<key alias="configureDisplayMode">Select and configure a display mode</key>
<key alias="configureElementType">Select and configure an element type</key>

<key alias="copyAllBlocks">Copy all blocks</key>
<key alias="editRawValue">Edit raw value</key>

<key alias="copyContentBlock">Copy content block</key>
<key alias="createContentTemplate">Create content template...</key>

<key alias="missingElementType">This content is not supported for this configuration.</key>

<!-- Data List -->
<key alias="labelDataSource">Data source</key>
<key alias="labelListEditor">List editor</key>
<key alias="configureDataSource">Select and configure a data source</key>
<key alias="configureListEditor">Select and configure a list editor</key>
<key alias="configurePreviewInit">Please select and configure a data source and list editor.</key>
<key alias="configurePreviewDataSource">Please select and configure a data source.</key>
<key alias="configurePreviewListEditor">Please select and configure a list editor.</key>
<key alias="configurePreviewNoItems">The data source returned no items to preview.</key>

<key alias="checkboxListCheckAll">Check all</key>
<key alias="checkboxListUncheckAll">Uncheck all</key>

<key alias="tagsType">Type to select an item...</key>
</area>
</language>
41 changes: 41 additions & 0 deletions TwentyFourDays/App_Plugins/Contentment/Lang/es.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<language alias="es" intName="Spanish (ES)" localName="Español (ES)" lcid="" culture="es-ES">
<creator>
<name>Alex Freire</name>
<link>https://github.com/Happy-reindeer007</link>
</creator>
<area alias="contentment">
<key alias="name">Contentment</key>

<!-- General -->
<key alias="removeItemMessage">¿Estás seguro de que quieres eliminar este elemento?</key>
<key alias="removeItemButton">Sí, eliminar</key>

<!-- Configuration Editor -->
<key alias="missingItemName">Este elemento ya no está disponible</key>
<key alias="missingItemDescription">Por, favor, elimina esta configuración y selecciona otro elemento.</key>

<!-- Content Blocks -->
<key alias="configureDisplayMode">Selecciona y configura un modo de visualización</key>
<key alias="configureElementType">Selecciona y configura un tipo de elemento</key>

<key alias="copyAllBlocks">Copiar todos los bloques</key>
<key alias="editRawValue">Editar valor original</key>

<key alias="copyContentBlock">Copiar bloque de contenido</key>
<key alias="createContentTemplate">Crear plantilla de contenido...</key>

<!-- Data List -->
<key alias="configureDataSource">Selecciona y configura una fuente de datos</key>
<key alias="configureListEditor">Selecciona y configura un editor de listas</key>
<key alias="configurePreviewInit">Por favor, selecciona y configura una fuente de datos y un editor de listas.</key>
<key alias="configurePreviewDataSource">Por favor, selecciona y configura una fuente de datos.</key>
<key alias="configurePreviewListEditor">Por favor, selecciona y configura un editor de listas.</key>
<key alias="configurePreviewNoItems">La fuente de datos no devolvió ningún elemento que previsualizar.</key>

<key alias="checkboxListCheckAll">Seleccionar todo</key>
<key alias="checkboxListUncheckAll">Deseleccionar todo</key>

<key alias="tagsType">Escribe para seleccionar un elemento...</key>
</area>
</language>
41 changes: 41 additions & 0 deletions TwentyFourDays/App_Plugins/Contentment/Lang/fr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<language alias="fr" intName="French" localName="Français" lcid="" culture="fr">
<creator>
<name>Michaël Latouche</name>
<link>https://github.com/mikecp</link>
</creator>
<area alias="contentment">
<key alias="name">Contentment</key>

<!-- General -->
<key alias="removeItemMessage">Etes-vous certain.e de vouloir supprimer cet élément?</key>
<key alias="removeItemButton">Oui, supprimer</key>

<!-- Configuration Editor -->
<key alias="missingItemName">Cet élément n'est plus disponible</key>
<key alias="missingItemDescription">Veuillez supprimer cette configuration et sélectionner un autre élément.</key>

<!-- Content Blocks -->
<key alias="configureDisplayMode">Sélectionnez et configurez un mode d'affichage</key>
<key alias="configureElementType">Sélectionnez et configurez un type d'élément</key>

<key alias="copyAllBlocks">Copier tous les blocs</key>
<key alias="editRawValue">Modifier la valeur brute</key>

<key alias="copyContentBlock">Copier le bloc de contenu</key>
<key alias="createContentTemplate">Créer un modèle de contenu...</key>

<!-- Data List -->
<key alias="configureDataSource">Sélectionnez et configurez une source de données</key>
<key alias="configureListEditor">Sélectionnez et configurez un éditeur de liste</key>
<key alias="configurePreviewInit">Veuillez sélectionner et configurer une source de données et un éditeur de liste.</key>
<key alias="configurePreviewDataSource">Veuillez sélectionner et configurer une source de données.</key>
<key alias="configurePreviewListEditor">Veuillez sélectionner et configurer un éditeur de liste.</key>
<key alias="configurePreviewNoItems">La source de données n'a retourné aucun élément à prévisualiser.</key>

<key alias="checkboxListCheckAll">Tout sélectionner</key>
<key alias="checkboxListUncheckAll">Tout désélectionner</key>

<key alias="tagsType">Ecrivez pour sélectionner un élément...</key>
</area>
</language>
41 changes: 41 additions & 0 deletions TwentyFourDays/App_Plugins/Contentment/Lang/nl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<language alias="nl" intName="Dutch" localName="Nederlands" lcid="19" culture="nl-NL">
<creator>
<name>Erik-Jan Westendorp</name>
<link>https://twitter.com/ewestendorp</link>
</creator>
<area alias="contentment">
<key alias="name">Contentment</key>

<!-- General -->
<key alias="removeItemMessage">Weet je zeker dat je dit item wilt verwijderen?</key>
<key alias="removeItemButton">Ja, verwijder</key>

<!-- Configuration Editor -->
<key alias="missingItemName">Dit item is niet langer beschikbaar</key>
<key alias="missingItemDescription">Verwijder deze configuratie en selecteer een ander item.</key>

<!-- Content Blocks -->
<key alias="configureDisplayMode">Selecteer en configureer een weergavemodus</key>
<key alias="configureElementType">Selecteer en configureer een elementtype</key>

<key alias="copyAllBlocks">Kopieer alle blokken</key>
<key alias="editRawValue">Ruwe waarde bewerken</key>

<key alias="copyContentBlock">Inhoudsblok kopiëren</key>
<key alias="createContentTemplate">Inhoudssjabloon maken...</key>

<!-- Data List -->
<key alias="configureDataSource">Selecteer en configureer een gegevensbron</key>
<key alias="configureListEditor">Selecteer en configureer een lijsteditor</key>
<key alias="configurePreviewInit">Selecteer en configureer een gegevensbron en lijsteditor.</key>
<key alias="configurePreviewDataSource">Selecteer en configureer een gegevensbron.</key>
<key alias="configurePreviewListEditor">Selecteer en configureer een lijsteditor.</key>
<key alias="configurePreviewNoItems">De gegevensbron heeft geen items geretourneerd om te bekijken.</key>

<key alias="checkboxListCheckAll">Alles selecteren</key>
<key alias="checkboxListUncheckAll">Alles deselecteren</key>

<key alias="tagsType">Typ om een item te selecteren...</key>
</area>
</language>
41 changes: 41 additions & 0 deletions TwentyFourDays/App_Plugins/Contentment/Lang/pt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<language alias="pt" intName="Portuguese" localName="Português" lcid="" culture="pt">
<creator>
<name>Renan Domingues, Leonardo Bottaro</name>
<link>https://github.com/RenanOD</link>
</creator>
<area alias="contentment">
<key alias="name">Contentment</key>

<!-- General -->
<key alias="removeItemMessage">Tem certeza que deseja remover este item?</key>
<key alias="removeItemButton">Sim, remover</key>

<!-- Configuration Editor -->
<key alias="missingItemName">Este item não está mais disponível</key>
<key alias="missingItemDescription">Por favor remova esta configuração e selecione outro item.</key>

<!-- Content Blocks -->
<key alias="configureDisplayMode">Selecionar e configurar o modo de exibição</key>
<key alias="configureElementType">Selecionar e configurar o tipo de elemento</key>

<key alias="copyAllBlocks">Copiar todos os blocos</key>
<key alias="editRawValue">Alterar o valor original</key>

<key alias="copyContentBlock">Copiar o conteúdo do bloco</key>
<key alias="createContentTemplate">Criar modelo de conteúdo...</key>

<!-- Data List -->
<key alias="configureDataSource">Selecionar e configurar uma origem de dados</key>
<key alias="configureListEditor">Selecionar e configurar um editor de lista</key>
<key alias="configurePreviewInit">Por favor selecione e configure uma origem de dados e um editor de lista.</key>
<key alias="configurePreviewDataSource">Por favor selecione e configure uma origem de dados.</key>
<key alias="configurePreviewListEditor">Por favor selecione e configure um editor de lista.</key>
<key alias="configurePreviewNoItems">A fonte de dados não retornou nenhum item para visualização.</key>

<key alias="checkboxListCheckAll">Marcar todos</key>
<key alias="checkboxListUncheckAll">Desmarcar todos</key>

<key alias="tagsType">Digite para selecionar um item...</key>
</area>
</language>
Loading

0 comments on commit bfcbacc

Please sign in to comment.