1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 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<lu_groups, LuGroupsAddDbo, LuGroupsDbo, LuGroupsAddDbo, LuAuthDatabaseContext, string>
- {
- public LuGroupsDataAccess(IServiceProvider serviceProvider) : base(serviceProvider)
- {
- }
-
- protected override LuResult<T> HandleError<T>(Exception e)
- {
- if (e is DbUpdateException && e.InnerException is PostgresException)
- {
- var pge = (PostgresException) e.InnerException;
- if (pge.ConstraintName == "lu_groups_name_key")
- {
- return LuResult<T>.Error(LuStatus.InputError, e, "Group name already exists");
- }
- }
- return null;
- }
-
- protected override DbSet<lu_groups> 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();
- }
- }
- }
|