Sfoglia il codice sorgente

removed unused imports; added someText check; fixed crud business null check

tags/v0.1.0
Robin Thoni 8 anni fa
parent
commit
aa8471a1aa

+ 3
- 3
Luticate2.Utils/Business/LuCrudBusiness.cs Vedi File

@@ -94,7 +94,7 @@ namespace Luticate2.Utils.Business
94 94
             if (newEntity)
95 95
             {
96 96
                 _notificationsBusiness.NotifyCreate(EntityType, newEntity.Data,
97
-                    s => NotifyCreateFilter(s, newEntity.Data));
97
+                    NotifyCreateFilter != null ? s => NotifyCreateFilter(s, newEntity.Data) : (Func<string, bool>) null);
98 98
                 return LuResult<T>.Ok(returnFunc(newEntity.Data));
99 99
             }
100 100
             return newEntity.To<T>();
@@ -161,7 +161,7 @@ namespace Luticate2.Utils.Business
161 161
             if (editedEntity)
162 162
             {
163 163
                 _notificationsBusiness.NotifyUpdate(EntityType, originalEntity.Data, editedEntity.Data,
164
-                    s => NotifyUpdateFilter(s, originalEntity.Data, editedEntity.Data));
164
+                    NotifyUpdateFilter != null ? s => NotifyUpdateFilter(s, originalEntity.Data, editedEntity.Data) : (Func<string, bool>) null);
165 165
                 return LuResult<T>.Ok(returnFunc(editedEntity.Data));
166 166
             }
167 167
             return editedEntity.To<T>();
@@ -191,7 +191,7 @@ namespace Luticate2.Utils.Business
191 191
             if (res)
192 192
             {
193 193
                 _notificationsBusiness.NotifyDelete(EntityType, originalEntity.Data,
194
-                    s => NotifyDeleteFilter(s, originalEntity.Data));
194
+                    NotifyDeleteFilter != null ? s => NotifyDeleteFilter(s, originalEntity.Data) : (Func<string, bool>) null);
195 195
             }
196 196
             return res;
197 197
         }

+ 1
- 6
Luticate2.Utils/Controllers/LuController.cs Vedi File

@@ -1,17 +1,12 @@
1
-using System;
2
-using System.Collections.Generic;
3
-using System.Threading;
4
-using Luticate2.Utils.Dbo;
1
+using System.Collections.Generic;
5 2
 using Luticate2.Utils.Dbo.Basic;
6 3
 using Luticate2.Utils.Dbo.Result;
7 4
 using Microsoft.AspNetCore.Mvc;
8
-//using Microsoft.AspNetCore.SignalR.Infrastructure;
9 5
 
10 6
 namespace Luticate2.Utils.Controllers
11 7
 {
12 8
     public abstract class LuController : Controller
13 9
     {
14
-//        protected IConnectionManager ConnectionManager { get; set; }
15 10
 
16 11
         protected IDictionary<object, object> LuItems => HttpContext.GetLuItems();
17 12
 

+ 1
- 4
Luticate2.Utils/Controllers/LuCrudController.cs Vedi File

@@ -1,7 +1,4 @@
1
-using System;
2
-using System.Linq;
3
-using Luticate2.Utils.Dbo;
4
-using Luticate2.Utils.Dbo.Basic;
1
+using Luticate2.Utils.Dbo.Basic;
5 2
 using Luticate2.Utils.Dbo.Filter;
6 3
 using Luticate2.Utils.Dbo.OrderBy;
7 4
 using Luticate2.Utils.Interfaces;

+ 0
- 1
Luticate2.Utils/Controllers/LuResultException.cs Vedi File

@@ -1,5 +1,4 @@
1 1
 using System;
2
-using Luticate2.Utils.Dbo;
3 2
 using Luticate2.Utils.Dbo.Result;
4 3
 
5 4
 namespace Luticate2.Utils.Controllers

+ 0
- 1
Luticate2.Utils/DataAccess/LuEfCrudDataAccess.cs Vedi File

@@ -9,7 +9,6 @@ using Luticate2.Utils.Dbo.Result;
9 9
 using Luticate2.Utils.Interfaces;
10 10
 using Luticate2.Utils.Utils;
11 11
 using Microsoft.EntityFrameworkCore;
12
-using Microsoft.EntityFrameworkCore.Metadata.Internal;
13 12
 
14 13
 namespace Luticate2.Utils.DataAccess
15 14
 {

+ 0
- 1
Luticate2.Utils/DataAccess/LuEfDataAccess.cs Vedi File

@@ -1,7 +1,6 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3 3
 using System.Linq.Expressions;
4
-using Luticate2.Utils.Dbo;
5 4
 using Luticate2.Utils.Dbo.Result;
6 5
 using Microsoft.EntityFrameworkCore;
7 6
 

+ 0
- 1
Luticate2.Utils/Interfaces/ILuCrudInterface.cs Vedi File

@@ -1,6 +1,5 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3
-using Luticate2.Utils.Dbo;
4 3
 using Luticate2.Utils.Dbo.Basic;
5 4
 using Luticate2.Utils.Dbo.Filter;
6 5
 using Luticate2.Utils.Dbo.OrderBy;

+ 0
- 3
Luticate2.Utils/Middlewares/LuExceptionMiddleware.cs Vedi File

@@ -1,11 +1,8 @@
1 1
 using System;
2
-using System.Buffers;
3 2
 using System.Threading.Tasks;
4 3
 using Luticate2.Utils.Controllers;
5 4
 using Luticate2.Utils.Dbo.Basic;
6 5
 using Microsoft.AspNetCore.Http;
7
-using Microsoft.AspNetCore.Mvc.Formatters;
8
-using Microsoft.AspNetCore.Mvc.Infrastructure;
9 6
 using Newtonsoft.Json;
10 7
 
11 8
 namespace Luticate2.Utils.Middlewares

+ 7
- 0
TestUtils/DataAccess/LuUtilsPkGuidDataAccess.cs Vedi File

@@ -1,7 +1,9 @@
1 1
 using System;
2
+using System.Linq;
2 3
 using System.Linq.Expressions;
3 4
 using Luticate2.Utils.DataAccess;
4 5
 using Luticate2.Utils.Dbo.Filter;
6
+using Luticate2.Utils.Dbo.Result;
5 7
 using TestUtils.DataAccess.Models;
6 8
 using TestUtils.Dbo.PkGuid;
7 9
 
@@ -40,5 +42,10 @@ namespace TestUtils.DataAccess
40 42
         {
41 43
             return model => LuUtilsDbContext.lu_texts_match(filter.Query, model.some_text + " " + model.some_int.ToString());
42 44
         }
45
+
46
+        public LuResult<bool> SomeTextExists(string someText)
47
+        {
48
+            return Execute(() => LuResult<bool>.Ok(Table.Any(guid => guid.some_text == someText)));
49
+        }
43 50
     }
44 51
 }

+ 28
- 0
WebApiUtils/Business/PkGuidBusiness.cs Vedi File

@@ -7,14 +7,30 @@ namespace WebApiUtils.Business
7 7
 {
8 8
     public class PkGuidBusiness : LuCrudBusiness<LuUtilsPkGuidDataAccess, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, string>
9 9
     {
10
+        private readonly LuUtilsPkGuidDataAccess _dataAccess;
10 11
 
11 12
         public PkGuidBusiness(LuUtilsPkGuidDataAccess dataAccess, LuNotificationsBusiness notificationsBusiness) : base(dataAccess, notificationsBusiness)
12 13
         {
14
+            _dataAccess = dataAccess;
13 15
             EntityType = "pkguid";
14 16
         }
15 17
 
18
+        public LuResult<bool> SomeTextExists(string someText)
19
+        {
20
+            return _dataAccess.SomeTextExists(someText);
21
+        }
22
+
16 23
         protected override LuResult<PkGuidAddDbo> CheckAdd(PkGuidAddDbo obj)
17 24
         {
25
+            var res = SomeTextExists(obj.SomeText);
26
+            if (!res)
27
+            {
28
+                return res.To<PkGuidAddDbo>();
29
+            }
30
+            if (res.Data)
31
+            {
32
+                return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText already exists", "");
33
+            }
18 34
             if (obj.SomeText.EndsWith("_edited"))
19 35
             {
20 36
                 return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText can not end with '_edited'", "");
@@ -24,6 +40,18 @@ namespace WebApiUtils.Business
24 40
 
25 41
         protected override LuResult<PkGuidAddDbo> CheckEdit(PkGuidDbo dbo, PkGuidAddDbo update)
26 42
         {
43
+            if (dbo.SomeText != update.SomeText)
44
+            {
45
+                var res = SomeTextExists(update.SomeText);
46
+                if (!res)
47
+                {
48
+                    return res.To<PkGuidAddDbo>();
49
+                }
50
+                if (res.Data)
51
+                {
52
+                    return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText already exists", "");
53
+                }
54
+            }
27 55
             if (!update.SomeText.EndsWith("_edited"))
28 56
             {
29 57
                 return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText must end with '_edited'", "");

Loading…
Annulla
Salva