You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuGroupsDataAccess.cs 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using Luticate2.Auth.DataAccess.Models;
  3. using Luticate2.Auth.Dbo.Groups;
  4. using Luticate2.Utils.DataAccess;
  5. using Luticate2.Utils.Dbo.Result;
  6. using Microsoft.EntityFrameworkCore;
  7. using Npgsql;
  8. namespace Luticate2.Auth.DataAccess
  9. {
  10. public class LuGroupsDataAccess : LuEfCrudDataAccess<lu_groups, LuGroupsAddDbo, LuGroupsDbo, LuGroupsAddDbo, LuAuthDatabaseContext, string>
  11. {
  12. public LuGroupsDataAccess(IServiceProvider serviceProvider) : base(serviceProvider)
  13. {
  14. }
  15. protected override LuResult<T> HandleError<T>(Exception e)
  16. {
  17. if (e is DbUpdateException && e.InnerException is PostgresException)
  18. {
  19. var pge = (PostgresException) e.InnerException;
  20. if (pge.ConstraintName == "lu_groups_name_key")
  21. {
  22. return LuResult<T>.Error(LuStatus.InputError, e, "Group name already exists");
  23. }
  24. }
  25. return null;
  26. }
  27. protected override DbSet<lu_groups> GetTable(LuAuthDatabaseContext db)
  28. {
  29. return db.lu_groups;
  30. }
  31. protected override lu_groups GetModelFromTCreate(LuGroupsAddDbo obj)
  32. {
  33. return GetModelFromTUpdate(obj, new lu_groups());
  34. }
  35. protected override void EditModelFromTUpdate(LuGroupsAddDbo obj, lu_groups model)
  36. {
  37. model.name = obj.Name;
  38. }
  39. protected override LuGroupsDbo GetDboFromModel(lu_groups model)
  40. {
  41. return model.ToDbo();
  42. }
  43. }
  44. }