Browse Source

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

tags/v0.1.0
Robin Thoni 8 years ago
parent
commit
aa8471a1aa

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

94
             if (newEntity)
94
             if (newEntity)
95
             {
95
             {
96
                 _notificationsBusiness.NotifyCreate(EntityType, newEntity.Data,
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
                 return LuResult<T>.Ok(returnFunc(newEntity.Data));
98
                 return LuResult<T>.Ok(returnFunc(newEntity.Data));
99
             }
99
             }
100
             return newEntity.To<T>();
100
             return newEntity.To<T>();
161
             if (editedEntity)
161
             if (editedEntity)
162
             {
162
             {
163
                 _notificationsBusiness.NotifyUpdate(EntityType, originalEntity.Data, editedEntity.Data,
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
                 return LuResult<T>.Ok(returnFunc(editedEntity.Data));
165
                 return LuResult<T>.Ok(returnFunc(editedEntity.Data));
166
             }
166
             }
167
             return editedEntity.To<T>();
167
             return editedEntity.To<T>();
191
             if (res)
191
             if (res)
192
             {
192
             {
193
                 _notificationsBusiness.NotifyDelete(EntityType, originalEntity.Data,
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
             return res;
196
             return res;
197
         }
197
         }

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

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

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

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
 using Luticate2.Utils.Dbo.Filter;
2
 using Luticate2.Utils.Dbo.Filter;
6
 using Luticate2.Utils.Dbo.OrderBy;
3
 using Luticate2.Utils.Dbo.OrderBy;
7
 using Luticate2.Utils.Interfaces;
4
 using Luticate2.Utils.Interfaces;

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

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

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

9
 using Luticate2.Utils.Interfaces;
9
 using Luticate2.Utils.Interfaces;
10
 using Luticate2.Utils.Utils;
10
 using Luticate2.Utils.Utils;
11
 using Microsoft.EntityFrameworkCore;
11
 using Microsoft.EntityFrameworkCore;
12
-using Microsoft.EntityFrameworkCore.Metadata.Internal;
13
 
12
 
14
 namespace Luticate2.Utils.DataAccess
13
 namespace Luticate2.Utils.DataAccess
15
 {
14
 {

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

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

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

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

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

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

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

1
 using System;
1
 using System;
2
+using System.Linq;
2
 using System.Linq.Expressions;
3
 using System.Linq.Expressions;
3
 using Luticate2.Utils.DataAccess;
4
 using Luticate2.Utils.DataAccess;
4
 using Luticate2.Utils.Dbo.Filter;
5
 using Luticate2.Utils.Dbo.Filter;
6
+using Luticate2.Utils.Dbo.Result;
5
 using TestUtils.DataAccess.Models;
7
 using TestUtils.DataAccess.Models;
6
 using TestUtils.Dbo.PkGuid;
8
 using TestUtils.Dbo.PkGuid;
7
 
9
 
40
         {
42
         {
41
             return model => LuUtilsDbContext.lu_texts_match(filter.Query, model.some_text + " " + model.some_int.ToString());
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 View File

7
 {
7
 {
8
     public class PkGuidBusiness : LuCrudBusiness<LuUtilsPkGuidDataAccess, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, string>
8
     public class PkGuidBusiness : LuCrudBusiness<LuUtilsPkGuidDataAccess, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, string>
9
     {
9
     {
10
+        private readonly LuUtilsPkGuidDataAccess _dataAccess;
10
 
11
 
11
         public PkGuidBusiness(LuUtilsPkGuidDataAccess dataAccess, LuNotificationsBusiness notificationsBusiness) : base(dataAccess, notificationsBusiness)
12
         public PkGuidBusiness(LuUtilsPkGuidDataAccess dataAccess, LuNotificationsBusiness notificationsBusiness) : base(dataAccess, notificationsBusiness)
12
         {
13
         {
14
+            _dataAccess = dataAccess;
13
             EntityType = "pkguid";
15
             EntityType = "pkguid";
14
         }
16
         }
15
 
17
 
18
+        public LuResult<bool> SomeTextExists(string someText)
19
+        {
20
+            return _dataAccess.SomeTextExists(someText);
21
+        }
22
+
16
         protected override LuResult<PkGuidAddDbo> CheckAdd(PkGuidAddDbo obj)
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
             if (obj.SomeText.EndsWith("_edited"))
34
             if (obj.SomeText.EndsWith("_edited"))
19
             {
35
             {
20
                 return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText can not end with '_edited'", "");
36
                 return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText can not end with '_edited'", "");
24
 
40
 
25
         protected override LuResult<PkGuidAddDbo> CheckEdit(PkGuidDbo dbo, PkGuidAddDbo update)
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
             if (!update.SomeText.EndsWith("_edited"))
55
             if (!update.SomeText.EndsWith("_edited"))
28
             {
56
             {
29
                 return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText must end with '_edited'", "");
57
                 return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText must end with '_edited'", "");

Loading…
Cancel
Save