using System; using Luticate2.Auth.DataAccess.Models; using Luticate2.Auth.Dbo.Groups; using Luticate2.Utils.DataAccess; using Luticate2.Utils.Dbo.Result; using Microsoft.EntityFrameworkCore; using Npgsql; namespace Luticate2.Auth.DataAccess { public class LuGroupsDataAccess : LuEfCrudDataAccess { public LuGroupsDataAccess(IServiceProvider serviceProvider) : base(serviceProvider) { } protected override LuResult HandleError(Exception e) { if (e is DbUpdateException && e.InnerException is PostgresException) { var pge = (PostgresException) e.InnerException; if (pge.ConstraintName == "lu_groups_name_key") { return LuResult.Error(LuStatus.InputError, e, "Group name already exists"); } } return null; } protected override DbSet GetTable(LuAuthDatabaseContext db) { return db.lu_groups; } protected override lu_groups GetModelFromTCreate(LuGroupsAddDbo obj) { return GetModelFromTUpdate(obj, new lu_groups()); } protected override void EditModelFromTUpdate(LuGroupsAddDbo obj, lu_groups model) { model.name = obj.Name; } protected override LuGroupsDbo GetDboFromModel(lu_groups model) { return model.ToDbo(); } } }