Explorar el Código

Add BillingPlanAddCommand, BillingPlansGetCommand

Dalibor Votruba hace 4 años
padre
commit
b3fca283fd

+ 1 - 1
AppServer/Business/ErrorCodes.txt

@@ -4,7 +4,7 @@
 Business (1000 - 2000)
 1000	Entity '{0}' named '{1}' already exists in database.
 1001	Entity '{0}' named '{1}' not exists in database.
-
+1010	Entity '{0}' filed '{1}' maximal length overflow (max. {2})
 
 Business.UserService (1100 - 1200)
 1100	Cannot create user '{0}', user name or email already exists.

+ 20 - 0
AppServer/Business/Exceptions/DataSizeValidationException.cs

@@ -0,0 +1,20 @@
+using System;
+using Quadarax.Foundation.Core.Exceptions;
+
+namespace BO.AppServer.Business.Exceptions
+{
+    public class DataSizeValidationException : CodeException
+    {
+        private const string CS_MESSAGE = "Entity '{0}' filed '{1}' maximal length overflow (max. {2}).";
+        private const int CN_CODE = 1010;
+
+
+        public DataSizeValidationException(Type entityType, string fieldName, int max, Exception innerException) : base(CN_CODE, string.Format(CS_MESSAGE,entityType.Name, fieldName, max), innerException)
+        {
+        }
+
+        public DataSizeValidationException(Type entityType, string fieldName, int max) : base(CN_CODE, string.Format(CS_MESSAGE,entityType.Name, fieldName, max))
+        {
+        }
+    }
+}

+ 14 - 0
AppServer/Business/Services/CatalogueService.cs

@@ -130,6 +130,20 @@ namespace BO.AppServer.Business.Services
                 throw exc;
             }
 
+            if (billingPlan.Code.Length > 10)
+            {
+                var exc = new DataSizeValidationException(typeof(BillingPlan), nameof(BillingPlanCDto.Code), 10);
+                Log.LogWarning(exc.Message);
+                throw exc;
+            }
+            if (billingPlan.PstprocessProfile.Length > 5)
+            {
+                var exc = new DataSizeValidationException(typeof(BillingPlan), nameof(BillingPlanCDto.PstprocessProfile), 5);
+                Log.LogWarning(exc.Message);
+                throw exc;
+            }
+
+
             // Create entity
             var newBillingPlan = _repoBillingPlan.New();
             billingPlan.Code = billingPlan.Code.ToUpper();

+ 1 - 4
AppServer/Metadata/Dto/BillingPlanDto.cs

@@ -58,10 +58,7 @@ namespace BO.AppServer.Metadata.Dto
 
     public class BillingPlanRDto : BillingPlanBaseDto, IReadDto
     {
-        public BoAuditDto Audit { get; }        
-        public string Name { get; }
-        public string Code { get; }
-        public string Description { get; }
+        public BoAuditDto Audit { get; }
         public int PSTInitCredits { get; }
         public decimal PSTPrize { get; }
         public string PSTCurrency { get; }

+ 4 - 1
AppServer/Web/appsettings.Development.json

@@ -3,7 +3,10 @@
     "LogLevel": {
       "Default": "Information",
       "Microsoft": "Warning",
-      "Microsoft.Hosting.Lifetime": "Information"
+      // Enable components logging
+      "Microsoft.Hosting.Lifetime": "Information",
+      // Enable EF logging
+      "Microsoft.EntityFrameworkCore.Database.Command": "Information"
     }
   },
   "Bo": {

+ 4 - 1
AppServer/Web/appsettings.json

@@ -3,7 +3,10 @@
     "LogLevel": {
       "Default": "Information",
       "Microsoft": "Warning",
-      "Microsoft.Hosting.Lifetime": "Information"
+      // Enable components logging
+      "Microsoft.Hosting.Lifetime": "Information",
+      // Enable EF logging
+      "Microsoft.EntityFrameworkCore.Database.Command": "Information"
     }
   },
   "Bo": {

+ 44 - 0
Console/Commands/Catalogues/BillingPlanAddCommand.cs

@@ -0,0 +1,44 @@
+using BO.AppServer.Metadata.Dto;
+using BO.Console.Commands.Base;
+using Quadarax.Foundation.Core.QConsole;
+using Quadarax.Foundation.Core.QConsole.Attributes;
+
+namespace BO.Console.Commands.Catalogues
+{
+    [CommandDefinition]
+    internal class BillingPlanAddCommand : AbstractPostCommand<BillingPlanCDto, BillingPlanRDto>
+    {
+        #region *** Constants ***
+        private const string CS_CMD_BPLANADD_NAME = "bplan_add";
+        private const string CS_CMD_BPLANADD_DESCR = "Add new billing plan/s by import file.";
+        #endregion
+
+        #region *** Properties ***
+
+        public override string Name => CS_CMD_BPLANADD_NAME;
+        public override string Description => CS_CMD_BPLANADD_DESCR;
+
+        #endregion
+
+        #region *** Constructor ***
+        public BillingPlanAddCommand(Engine engine) : base(engine)
+        {
+        }
+        #endregion
+
+        #region *** EXECUTE ***
+        protected override BillingPlanRDto IterationExecute(BillingPlanCDto data)
+        {
+            WriteDebugInfo($"MimeType '{data.Code}' starts creating...");
+            var result = Client.CreateBillingPlanAsync(data).Result;
+            WriteCaption($"BillingPlan '{data.Code}' created.");
+            return result;
+        }
+
+        #endregion
+
+        #region *** Private operations ***
+        #endregion
+
+    }
+}

+ 48 - 0
Console/Commands/Catalogues/BillingPlansGetCommand.cs

@@ -0,0 +1,48 @@
+using BO.Console.Commands.Base;
+using Quadarax.Foundation.Core.QConsole;
+using Quadarax.Foundation.Core.QConsole.Attributes;
+using Quadarax.Foundation.Core.Value;
+
+namespace BO.Console.Commands.Catalogues
+{
+    [CommandDefinition]
+    internal class BillingPlansGetCommand : AbstractListScopedCommand<AppServer.Metadata.Enums.BPlanScopeEnums>
+    {
+        #region *** Constants ***
+
+        private const string CS_CMD_BPLANGET_NAME = "bplan_list";
+        private const string CS_CMD_BPLANGET_DESCR = "Get list of billing plans by specification scope.";
+
+        #endregion
+
+        #region *** Properties ***
+
+        public override string Name => CS_CMD_BPLANGET_NAME;
+        public override string Description => CS_CMD_BPLANGET_DESCR;
+
+        #endregion
+
+        #region *** Constructor ***
+
+        public BillingPlansGetCommand(Engine engine) : base(engine)
+        {
+        }
+
+        #endregion
+
+        #region *** EXECUTE ***
+
+        protected override Result OnExecute()
+        {
+            var mimes = Client.GetBillingPlansAsync(Scope, Paging).Result;
+            WriteDtoToConsole(mimes,"Id","Code","Name","PstprocessProfile","PstinitialCredits","Psttest","IsCustom","IsHidden","IsEnabled");
+            return new Result();
+        }
+
+        #endregion
+
+        #region *** Private operations ***
+
+        #endregion
+    }
+}

+ 2 - 0
Console/Console.csproj

@@ -20,4 +20,6 @@
     </None>
   </ItemGroup>
 
+  <ProjectExtensions><VisualStudio><UserProperties samples_4workspace_1json__JsonSchema="https://docs.renovatebot.com/renovate-schema.json" /></VisualStudio></ProjectExtensions>
+
 </Project>

+ 16 - 0
Console/Samples/billingplans.json

@@ -0,0 +1,16 @@
+[{
+"name" : "Unlimited",
+"code" : "UNLIMITED",
+"Description" : "This plan is only for testing purpose",
+"PstinitialCredits" : 1000,
+"PstcreditsPerItem" : 1,
+"Pstwatermark" : true,
+"Pstquality" : 1,
+"PstprocessProfile" : "PRC01",
+"Psttest" : true,
+"Price" : 1,
+"Currency" : "EUR",
+"IsCustom" : false,
+"IsHidden" : false,
+"IsEnabled" : true
+}]