From 0a9cecc604cbe46a5814b68412ee0182b6b11074 Mon Sep 17 00:00:00 2001 From: Kamil Madej Date: Thu, 25 Apr 2019 10:12:35 +0200 Subject: [PATCH 01/86] OP-50: Adjusted findByUsernameAndPassword code --- OpenImis.DB.SqlServer/TblUsers.cs | 1 + .../UserModule/Repository/UserSQLServer.cs | 78 +++++++++++++------ 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/OpenImis.DB.SqlServer/TblUsers.cs b/OpenImis.DB.SqlServer/TblUsers.cs index 0bfbd6c5..385da50b 100644 --- a/OpenImis.DB.SqlServer/TblUsers.cs +++ b/OpenImis.DB.SqlServer/TblUsers.cs @@ -28,6 +28,7 @@ public TblUsers() public string DummyPwd { get; set; } public string EmailId { get; set; } public string PrivateKey { get; set; } + public string StoredPassword { get; set; } public TblLanguages Language { get; set; } public ICollection TblClaim { get; set; } diff --git a/OpenImis.Modules/UserModule/Repository/UserSQLServer.cs b/OpenImis.Modules/UserModule/Repository/UserSQLServer.cs index b9a12dd9..03968df4 100644 --- a/OpenImis.Modules/UserModule/Repository/UserSQLServer.cs +++ b/OpenImis.Modules/UserModule/Repository/UserSQLServer.cs @@ -4,7 +4,9 @@ using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; +using System.Security.Cryptography; using System.Threading.Tasks; +using System.Text; using OpenImis.Modules.UserModule.Entities; using Newtonsoft.Json; using OpenImis.Modules.Utils; @@ -46,22 +48,6 @@ public User GetByUsername(string username) return TypeCast.Cast(user); } - /// - /// Creates the SQL string for the GetByUsernameAndPassword[Async] calls - /// - /// - /// - /// - private RawSqlString GetByUsernameAndPasswordSQL() { - return new RawSqlString($@"OPEN SYMMETRIC KEY EncryptionKey DECRYPTION BY Certificate EncryptData - SELECT * - FROM TblUsers - WHERE LoginName = @user - AND CONVERT(NVARCHAR(25), DECRYPTBYKEY(Password)) COLLATE LATIN1_GENERAL_CS_AS = @password - AND ValidityTo is null - CLOSE SYMMETRIC KEY EncryptionKey"); - } - /// /// Get user by username and password by asychronious call /// @@ -73,10 +59,15 @@ public async Task GetByUsernameAndPasswordAsync(string username, string pa TblUsers user; using (var imisContext = new ImisDB()) { - var userParameter = new SqlParameter("user", username); - var passwordParameter = new SqlParameter("password", password); + user = await imisContext.TblUsers.Where(u => u.LoginName == username).FirstOrDefaultAsync(); - user = await imisContext.TblUsers.FromSql(GetByUsernameAndPasswordSQL(),userParameter, passwordParameter).SingleOrDefaultAsync(); + if (user != null) + { + if (!ValidateLogin(user.StoredPassword, user.PrivateKey, password)) + { + user = null; + } + } } return TypeCast.Cast(user); } @@ -90,15 +81,52 @@ public async Task GetByUsernameAndPasswordAsync(string username, string pa /// public User GetByUsernameAndPassword(string username, string password) { - User user; - using (var imisContext = new ImisDB()) + User user = GetByUsername(username); + + if (user == null) + { + return null; + } + else { - var userParameter = new SqlParameter("user", username); - var passwordParameter = new SqlParameter("password", password); + if (ValidateLogin(user.StoredPassword, user.PrivateKey, password)) + { + return user; + } + else + { + return null; + } + } + } - user = (User)imisContext.TblUsers.FromSql(GetByUsernameAndPasswordSQL(), userParameter, passwordParameter).SingleOrDefault(); + private bool ValidateLogin(string storedPassword, string privateKey, string password) + { + var generatedSHA = GenerateSHA256String(password + privateKey); + if (generatedSHA == storedPassword) + { + return true; + } + else + { + return false; } - return user; + } + + private string GenerateSHA256String(string inputString) + { + SHA256 sha256 = SHA256Managed.Create(); + byte[] bytes = Encoding.UTF8.GetBytes(inputString); + byte[] hash = sha256.ComputeHash(bytes); + var stringBuilder = new StringBuilder(); + + for (int i = 0; i < hash.Length; i++) + { + var str = hash[i].ToString("X2"); + stringBuilder.Append(str); + } + + return stringBuilder.ToString(); } } From 4222258d26b63de528205c9f49e3cb49a28e0efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kami=C5=84ski?= Date: Wed, 12 Jun 2019 14:33:42 +0200 Subject: [PATCH 02/86] OS-21: Added basic code of Claim Module --- OpenImis.Modules/ClaimModule/ClaimModule.cs | 25 +++ OpenImis.Modules/ClaimModule/IClaimModule.cs | 12 + .../ClaimModule/Logic/ClaimLogic.cs | 55 +++++ .../ClaimModule/Logic/IClaimLogic.cs | 16 ++ .../ClaimModule/Models/ClaimAdminModel.cs | 13 ++ .../ClaimModule/Models/CodeName.cs | 12 + .../ClaimModule/Models/CodeNamePrice.cs | 13 ++ .../Models/DiagnosisServiceItem.cs | 14 ++ .../ClaimModule/Models/DsiInputModel.cs | 13 ++ .../ClaimModule/Models/PaymentLists.cs | 15 ++ .../Models/PaymentListsInputModel.cs | 15 ++ .../Repositories/ClaimRepository.cs | 211 ++++++++++++++++++ .../Repositories/IClaimRepository.cs | 16 ++ OpenImis.Modules/IImisModules.cs | 17 +- OpenImis.Modules/ImisModules.cs | 16 +- .../Controllers/ClaimsController.cs | 106 +++++++++ 16 files changed, 560 insertions(+), 9 deletions(-) create mode 100644 OpenImis.Modules/ClaimModule/ClaimModule.cs create mode 100644 OpenImis.Modules/ClaimModule/IClaimModule.cs create mode 100644 OpenImis.Modules/ClaimModule/Logic/ClaimLogic.cs create mode 100644 OpenImis.Modules/ClaimModule/Logic/IClaimLogic.cs create mode 100644 OpenImis.Modules/ClaimModule/Models/ClaimAdminModel.cs create mode 100644 OpenImis.Modules/ClaimModule/Models/CodeName.cs create mode 100644 OpenImis.Modules/ClaimModule/Models/CodeNamePrice.cs create mode 100644 OpenImis.Modules/ClaimModule/Models/DiagnosisServiceItem.cs create mode 100644 OpenImis.Modules/ClaimModule/Models/DsiInputModel.cs create mode 100644 OpenImis.Modules/ClaimModule/Models/PaymentLists.cs create mode 100644 OpenImis.Modules/ClaimModule/Models/PaymentListsInputModel.cs create mode 100644 OpenImis.Modules/ClaimModule/Repositories/ClaimRepository.cs create mode 100644 OpenImis.Modules/ClaimModule/Repositories/IClaimRepository.cs create mode 100644 OpenImis.RestApi/Controllers/ClaimsController.cs diff --git a/OpenImis.Modules/ClaimModule/ClaimModule.cs b/OpenImis.Modules/ClaimModule/ClaimModule.cs new file mode 100644 index 00000000..23696135 --- /dev/null +++ b/OpenImis.Modules/ClaimModule/ClaimModule.cs @@ -0,0 +1,25 @@ +using OpenImis.Modules.ClaimModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.ClaimModule +{ + public class ClaimModule : IClaimModule + { + private IClaimLogic _claimLogic; + + public ClaimModule() + { + } + + public IClaimLogic GetClaimLogic() + { + if (_claimLogic == null) + { + _claimLogic = new ClaimLogic(); + } + return _claimLogic; + } + } +} diff --git a/OpenImis.Modules/ClaimModule/IClaimModule.cs b/OpenImis.Modules/ClaimModule/IClaimModule.cs new file mode 100644 index 00000000..5da9bbf1 --- /dev/null +++ b/OpenImis.Modules/ClaimModule/IClaimModule.cs @@ -0,0 +1,12 @@ +using OpenImis.Modules.ClaimModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.ClaimModule +{ + public interface IClaimModule + { + IClaimLogic GetClaimLogic(); + } +} diff --git a/OpenImis.Modules/ClaimModule/Logic/ClaimLogic.cs b/OpenImis.Modules/ClaimModule/Logic/ClaimLogic.cs new file mode 100644 index 00000000..7c3358bb --- /dev/null +++ b/OpenImis.Modules/ClaimModule/Logic/ClaimLogic.cs @@ -0,0 +1,55 @@ +using OpenImis.DB.SqlServer; +using OpenImis.Modules.ClaimModule.Models; +using OpenImis.Modules.ClaimModule.Repositories; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.ClaimModule.Logic +{ + public class ClaimLogic : IClaimLogic + { + protected IClaimRepository claimRepository; + + public ClaimLogic() + { + claimRepository = new ClaimRepository(); + } + + public DiagnosisServiceItem GetDsi(DsiInputModel model) + { + DiagnosisServiceItem message; + + message = claimRepository.GetDsi(model); + + return message; + } + + public List GetClaimAdministrators() + { + List response = new List(); + + response = claimRepository.GetClaimAdministrators(); + + return response; + } + + public List GetControls() + { + List response = new List(); + + response = claimRepository.GetControls(); + + return response; + } + + public PaymentLists GetPaymentLists(PaymentListsInputModel model) + { + PaymentLists response; + + response = claimRepository.GetPaymentLists(model); + + return response; + } + } +} diff --git a/OpenImis.Modules/ClaimModule/Logic/IClaimLogic.cs b/OpenImis.Modules/ClaimModule/Logic/IClaimLogic.cs new file mode 100644 index 00000000..a099bb9b --- /dev/null +++ b/OpenImis.Modules/ClaimModule/Logic/IClaimLogic.cs @@ -0,0 +1,16 @@ +using OpenImis.DB.SqlServer; +using OpenImis.Modules.ClaimModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.ClaimModule.Logic +{ + public interface IClaimLogic + { + DiagnosisServiceItem GetDsi(DsiInputModel model); + List GetClaimAdministrators(); + List GetControls(); + PaymentLists GetPaymentLists(PaymentListsInputModel model); + } +} diff --git a/OpenImis.Modules/ClaimModule/Models/ClaimAdminModel.cs b/OpenImis.Modules/ClaimModule/Models/ClaimAdminModel.cs new file mode 100644 index 00000000..ca5b19e6 --- /dev/null +++ b/OpenImis.Modules/ClaimModule/Models/ClaimAdminModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.ClaimModule.Models +{ + public class ClaimAdminModel + { + public string lastName { get; set; } + public string otherNames { get; set; } + public string claimAdminCode { get; set; } + } +} diff --git a/OpenImis.Modules/ClaimModule/Models/CodeName.cs b/OpenImis.Modules/ClaimModule/Models/CodeName.cs new file mode 100644 index 00000000..d1f0aa42 --- /dev/null +++ b/OpenImis.Modules/ClaimModule/Models/CodeName.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.ClaimModule.Models +{ + public class CodeName + { + public string code { get; set; } + public string name { get; set; } + } +} diff --git a/OpenImis.Modules/ClaimModule/Models/CodeNamePrice.cs b/OpenImis.Modules/ClaimModule/Models/CodeNamePrice.cs new file mode 100644 index 00000000..2d2a2e3c --- /dev/null +++ b/OpenImis.Modules/ClaimModule/Models/CodeNamePrice.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.ClaimModule.Models +{ + public class CodeNamePrice + { + public string code { get; set; } + public string name { get; set; } + public string price { get; set; } + } +} diff --git a/OpenImis.Modules/ClaimModule/Models/DiagnosisServiceItem.cs b/OpenImis.Modules/ClaimModule/Models/DiagnosisServiceItem.cs new file mode 100644 index 00000000..5e53efe7 --- /dev/null +++ b/OpenImis.Modules/ClaimModule/Models/DiagnosisServiceItem.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.ClaimModule.Models +{ + public class DiagnosisServiceItem + { + public List diagnoses { get; set; } + public List services { get; set; } + public List items { get; set; } + public DateTime update_since_last { get; set; } + } +} diff --git a/OpenImis.Modules/ClaimModule/Models/DsiInputModel.cs b/OpenImis.Modules/ClaimModule/Models/DsiInputModel.cs new file mode 100644 index 00000000..9d46be73 --- /dev/null +++ b/OpenImis.Modules/ClaimModule/Models/DsiInputModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.ClaimModule.Models +{ + public class DsiInputModel + { + // TODO ValidDate Attribute + //[ValidDate(ErrorMessage = "Please Enter A valid date format")] + public string last_update_date { get; set; } + } +} diff --git a/OpenImis.Modules/ClaimModule/Models/PaymentLists.cs b/OpenImis.Modules/ClaimModule/Models/PaymentLists.cs new file mode 100644 index 00000000..2aba22a8 --- /dev/null +++ b/OpenImis.Modules/ClaimModule/Models/PaymentLists.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.ClaimModule.Models +{ + public class PaymentLists + { + public DateTime update_since_last { get; set; } + public string health_facility_code { get; set; } + public string health_facility_name { get; set; } + public List pricelist_services { get; set; } + public List pricelist_items { get; set; } + } +} diff --git a/OpenImis.Modules/ClaimModule/Models/PaymentListsInputModel.cs b/OpenImis.Modules/ClaimModule/Models/PaymentListsInputModel.cs new file mode 100644 index 00000000..757e2950 --- /dev/null +++ b/OpenImis.Modules/ClaimModule/Models/PaymentListsInputModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.ClaimModule.Models +{ + public class PaymentListsInputModel + { + [Required] + public string claim_administrator_code { get; set; } + //[ValidDate] + public string last_update_date { get; set; } + } +} diff --git a/OpenImis.Modules/ClaimModule/Repositories/ClaimRepository.cs b/OpenImis.Modules/ClaimModule/Repositories/ClaimRepository.cs new file mode 100644 index 00000000..49557fad --- /dev/null +++ b/OpenImis.Modules/ClaimModule/Repositories/ClaimRepository.cs @@ -0,0 +1,211 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Internal; +using Newtonsoft.Json; +using OpenImis.DB.SqlServer; +using OpenImis.Modules.ClaimModule.Models; + +namespace OpenImis.Modules.ClaimModule.Repositories +{ + public class ClaimRepository : IClaimRepository + { + public ClaimRepository() + { + } + + public DiagnosisServiceItem GetDsi(DsiInputModel model) + { + DiagnosisServiceItem message = new DiagnosisServiceItem(); + + try + { + using (var imisContext = new ImisDB()) + { + List diagnoses; + List items; + List services; + + diagnoses = imisContext.TblIcdcodes + .Where(i => i.ValidityFrom >= Convert.ToDateTime(model.last_update_date) + && i.ValidityTo == null) + .Select(x => new CodeName() + { + code = x.Icdcode, + name = x.Icdname + }).ToList(); + + items = imisContext.TblItems + .Where(i => i.ValidityFrom >= Convert.ToDateTime(model.last_update_date) + && i.ValidityTo == null) + .Select(x => new CodeNamePrice() + { + code = x.ItemCode, + name = x.ItemName, + price = x.ItemPrice.ToString() + }).ToList(); + + services = imisContext.TblServices + .Where(i => i.ValidityFrom >= Convert.ToDateTime(model.last_update_date) + && i.ValidityTo == null) + .Select(x => new CodeNamePrice() + { + code = x.ServCode, + name = x.ServName, + price = x.ServPrice.ToString() + }).ToList(); + + message.diagnoses = diagnoses; + message.items = items; + message.services = services; + message.update_since_last = DateTime.UtcNow; + } + + return message; + } + catch (Exception e) + { + throw e; + } + } + + public List GetClaimAdministrators() + { + List response = new List(); + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.TblClaimAdmin + .Where(c => c.ValidityTo == null) + .Select(x => new ClaimAdminModel() + { + lastName = x.LastName, + otherNames = x.OtherNames, + claimAdminCode = x.ClaimAdminCode + }).ToList(); + } + + return response; + } + catch (Exception e) + { + throw e; + } + } + + public List GetControls() + { + List response = new List(); + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.TblControls + .Select(x => new TblControls() + { + FieldName = x.FieldName, + Adjustibility = x.Adjustibility, + Usage = x.Usage + }).ToList(); + } + + return response; + } + catch (Exception e) + { + throw e; + } + } + + public PaymentLists GetPaymentLists(PaymentListsInputModel model) + { + PaymentLists message = new PaymentLists(); + + try + { + using (var imisContext = new ImisDB()) + { + int? HFID; + int? PLServiceID; + int? PLItemID; + + List hf = new List(); + List plItemsDetail = new List(); + List plServicesDetail = new List(); + + HFID = imisContext.TblClaimAdmin + .Where(c => c.ClaimAdminCode == model.claim_administrator_code + && c.ValidityTo == null) + .Select(x => x.Hfid).FirstOrDefault(); + + PLServiceID = imisContext.TblHf + .Where(h => h.HfId == HFID) + .Select(x => x.PlserviceId).FirstOrDefault(); + + PLItemID = imisContext.TblHf + .Where(h => h.HfId == HFID) + .Select(x => x.PlitemId).FirstOrDefault(); + + hf = imisContext.TblHf + .Where(h => h.HfId == HFID) + .Select(x => new CodeName() + { + code = x.Hfcode, + name = x.Hfname + }).ToList(); + + plItemsDetail = imisContext.TblPlitemsDetail + .Join(imisContext.TblItems, + p => p.ItemId, + i => i.ItemId, + (p, i) => new { TblPlitemsDetail = p, TblItems = i }) + .Where(r => r.TblItems.ValidityTo == null) + .Where(r => r.TblPlitemsDetail.PlitemId == PLItemID + && r.TblPlitemsDetail.ValidityTo == null + && (r.TblPlitemsDetail.ValidityFrom >= Convert.ToDateTime(model.last_update_date) || model.last_update_date == null)) + .Select(x => new CodeNamePrice() + { + code = x.TblItems.ItemCode, + name = x.TblItems.ItemName, + price = (x.TblPlitemsDetail.PriceOverule == null) ? x.TblItems.ItemPrice.ToString() : x.TblPlitemsDetail.PriceOverule.ToString() + }).ToList(); + + plServicesDetail = imisContext.TblPlservicesDetail + .Join(imisContext.TblServices, + p => p.ServiceId, + i => i.ServiceId, + (p, i) => new { TblPlservicesDetail = p, TblServices = i }) + .Where(r => r.TblServices.ValidityTo == null) + .Where(r => r.TblPlservicesDetail.PlserviceId == PLServiceID + && r.TblPlservicesDetail.ValidityTo == null + && (r.TblPlservicesDetail.ValidityFrom >= Convert.ToDateTime(model.last_update_date) || model.last_update_date == null)) + .Select(x => new CodeNamePrice() + { + code = x.TblServices.ServCode, + name = x.TblServices.ServName, + price = (x.TblPlservicesDetail.PriceOverule == null) ? x.TblServices.ServPrice.ToString() : x.TblPlservicesDetail.PriceOverule.ToString() + }).ToList(); + + message.health_facility_code = hf.Select(x => x.code).FirstOrDefault(); + message.health_facility_name = hf.Select(x => x.name).FirstOrDefault(); + + message.pricelist_items = plItemsDetail; + message.pricelist_services = plServicesDetail; + message.update_since_last = DateTime.UtcNow; + } + + return message; + } + catch (Exception e) + { + throw e; + } + } + } +} \ No newline at end of file diff --git a/OpenImis.Modules/ClaimModule/Repositories/IClaimRepository.cs b/OpenImis.Modules/ClaimModule/Repositories/IClaimRepository.cs new file mode 100644 index 00000000..b3a16c1c --- /dev/null +++ b/OpenImis.Modules/ClaimModule/Repositories/IClaimRepository.cs @@ -0,0 +1,16 @@ +using OpenImis.DB.SqlServer; +using OpenImis.Modules.ClaimModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.ClaimModule.Repositories +{ + public interface IClaimRepository + { + DiagnosisServiceItem GetDsi(DsiInputModel model); + List GetClaimAdministrators(); + List GetControls(); + PaymentLists GetPaymentLists(PaymentListsInputModel model); + } +} diff --git a/OpenImis.Modules/IImisModules.cs b/OpenImis.Modules/IImisModules.cs index 32ae87b1..2a25ca93 100644 --- a/OpenImis.Modules/IImisModules.cs +++ b/OpenImis.Modules/IImisModules.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using OpenImis.Modules.MasterDataManagementModule; +using OpenImis.Modules.ClaimModule; namespace OpenImis.Modules { @@ -13,13 +14,15 @@ namespace OpenImis.Modules /// public interface IImisModules { - /// - /// Creates and returns the user management module. - /// - /// - /// The User module. - /// - IUserModule GetUserModule(); + IClaimModule GetClaimModule(); + + /// + /// Creates and returns the user management module. + /// + /// + /// The User module. + /// + IUserModule GetUserModule(); IInsureeManagementModule GetInsureeManagementModule(); diff --git a/OpenImis.Modules/ImisModules.cs b/OpenImis.Modules/ImisModules.cs index 820427c4..13886bdd 100644 --- a/OpenImis.Modules/ImisModules.cs +++ b/OpenImis.Modules/ImisModules.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Configuration; using OpenImis.Modules.MasterDataManagementModule; using OpenImis.Modules.MasterDataManagementModule.Logic; +using OpenImis.Modules.ClaimModule; namespace OpenImis.Modules { @@ -36,7 +37,9 @@ public class ImisModules: IImisModules private IInsureeManagementModule insureeManagementModule; private IMasterDataManagementModule masterDataManagementModule; - private readonly IConfiguration _configuration; + private IClaimModule claimModule; + + private readonly IConfiguration _configuration; private readonly ILogger logger; public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory) @@ -45,7 +48,16 @@ public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory) logger = loggerFactory.CreateLogger("LoggerCategory"); } - /// + public IClaimModule GetClaimModule() + { + if (claimModule == null) + { + claimModule = new ClaimModule.ClaimModule(); + } + return claimModule; + } + + /// /// Creates and returns the user management module. /// /// diff --git a/OpenImis.RestApi/Controllers/ClaimsController.cs b/OpenImis.RestApi/Controllers/ClaimsController.cs new file mode 100644 index 00000000..68b27f93 --- /dev/null +++ b/OpenImis.RestApi/Controllers/ClaimsController.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Cors; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using OpenImis.Modules; +using OpenImis.Modules.ClaimModule.Models; + +namespace OpenImis.RestApi.Controllers +{ + //[ApiVersion("1")] + //[Authorize(Roles = "IMISAdmin, EnrollmentOfficer")] + [Route("api/")] + [ApiController] + [EnableCors("AllowSpecificOrigin")] + public class ClaimsController : Controller + { + private readonly IImisModules _imisModules; + public ClaimsController(IImisModules imisModules) + { + _imisModules = imisModules; + } + + [HttpPost] + [Route("GetDiagnosesServicesItems")] + [ProducesResponseType(typeof(void), 200)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public IActionResult GetDiagnosesServicesItems([FromBody]DsiInputModel model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + try + { + var response = _imisModules.GetClaimModule().GetClaimLogic().GetDsi(model); + return Json(response); + } + catch (Exception e) + { + return BadRequest(new { error_occured = true, error_message = e.Message }); + } + } + + //[Authorize(Roles = "ClaimAdd")] + [HttpPost] + [Route("GetPaymentLists")] + [ProducesResponseType(typeof(void), 200)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public IActionResult GetPaymentLists([FromBody]PaymentListsInputModel model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + try + { + var response = _imisModules.GetClaimModule().GetClaimLogic().GetPaymentLists(model); + return Json(response); + } + catch (Exception e) + { + return BadRequest(new { error_occured = true, error_message = e.Message }); + } + } + + [HttpGet] + [Route("Claims/GetClaimAdmins")] + public IActionResult ValidateClaimAdmin() + { + try + { + var data = _imisModules.GetClaimModule().GetClaimLogic().GetClaimAdministrators(); + return Ok(new { error_occured = false, claim_admins = data }); + } + catch (Exception e) + { + return BadRequest(new { error_occured = true, error_message = e.Message }); + } + } + + [HttpGet] + [Route("Claims/Controls")] + public IActionResult GetControls() + { + try + { + var data = _imisModules.GetClaimModule().GetClaimLogic().GetControls(); + return Ok(new { error_occured = false, controls = data }); + } + catch (Exception e) + { + return BadRequest(new { error_occured = true, error_message = e.Message }); + } + } + + } +} \ No newline at end of file From 6c3c4510ec59b2b6a0743d2a8ce02461c64d9578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kami=C5=84ski?= Date: Tue, 18 Jun 2019 14:11:08 +0200 Subject: [PATCH 03/86] OS-26: The DataHelper has been moved from Exact and the automatic HTTP 400 service has been disabled --- .../DataHelper/DataHelper.cs | 169 ++++++++++++++++++ .../DataHelper/ProcedureOutPut.cs | 11 ++ OpenImis.RestApi/Startup.cs | 5 + 3 files changed, 185 insertions(+) create mode 100644 OpenImis.DB.SqlServer/DataHelper/DataHelper.cs create mode 100644 OpenImis.DB.SqlServer/DataHelper/ProcedureOutPut.cs diff --git a/OpenImis.DB.SqlServer/DataHelper/DataHelper.cs b/OpenImis.DB.SqlServer/DataHelper/DataHelper.cs new file mode 100644 index 00000000..d881d8d3 --- /dev/null +++ b/OpenImis.DB.SqlServer/DataHelper/DataHelper.cs @@ -0,0 +1,169 @@ +using Microsoft.Extensions.Configuration; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Text; + +namespace OpenImis.DB.SqlServer.DataHelper +{ + public class DataHelper + { + private readonly string ConnectionString; + + public int ReturnValue { get; set; } + + public DataHelper(IConfiguration configuration) + { + ConnectionString = configuration["ConnectionStrings:IMISDatabase"]; + } + + public DataSet FillDataSet(string SQL, SqlParameter[] parameters, CommandType commandType) + { + DataSet ds = new DataSet(); + var sqlConnection = new SqlConnection(ConnectionString); + + SqlParameter returnParameter = new SqlParameter("@RV", SqlDbType.Int); + returnParameter.Direction = ParameterDirection.ReturnValue; + + var command = new SqlCommand(SQL, sqlConnection) + { + CommandType = commandType + }; + + command.Parameters.Add(returnParameter); + + var adapter = new SqlDataAdapter(command); + using (command) + { + if (parameters.Length > 0) + command.Parameters.AddRange(parameters); + adapter.Fill(ds); + } + + ReturnValue = int.Parse(returnParameter.Value.ToString()); + + return ds; + } + + public DataTable GetDataTable(string SQL, SqlParameter[] parameters, CommandType commandType) + { + DataTable dt = new DataTable(); + var sqlConnection = new SqlConnection(ConnectionString); + var command = new SqlCommand(SQL, sqlConnection) + { + CommandType = commandType + }; + + var adapter = new SqlDataAdapter(command); + + using (command) + { + if (parameters.Length > 0) + command.Parameters.AddRange(parameters); + adapter.Fill(dt); + } + + return dt; + } + + public void Execute(string SQL, SqlParameter[] parameters, CommandType commandType) + { + var sqlConnection = new SqlConnection(ConnectionString); + + //if(SqlCommand.C) + // sqlConnection.Open + var command = new SqlCommand(SQL, sqlConnection) + { + CommandType = commandType + }; + + using (command) + { + if (command.Connection.State == 0) + { + command.Connection.Open(); + + if (parameters.Length > 0) + command.Parameters.AddRange(parameters); + + command.ExecuteNonQuery(); + + command.Connection.Close(); + } + } + } + + public ProcedureOutPut Procedure(string StoredProcedure, SqlParameter[] parameters, int tableIndex = 0) + { + DataSet dt = new DataSet(); + + SqlConnection sqlConnection = new SqlConnection(ConnectionString); + SqlCommand command = new SqlCommand(); + //SqlDataReader reader; + + SqlParameter returnParameter = new SqlParameter("@RV", SqlDbType.Int); + returnParameter.Direction = ParameterDirection.ReturnValue; + + command.CommandText = StoredProcedure; + command.CommandType = CommandType.StoredProcedure; + command.Connection = sqlConnection; + command.Parameters.Add(returnParameter); + + if (parameters.Length > 0) + command.Parameters.AddRange(parameters); + + var adapter = new SqlDataAdapter(command); + + using (command) + { + adapter.Fill(dt); + } + + int rv = int.Parse(returnParameter.Value.ToString()); + DataTable dat = new DataTable(); + + if (rv == 0) + { + dat = dt.Tables[tableIndex]; + } + + var output = new ProcedureOutPut + { + Code = rv, + Data = dat + }; + + return output; + } + + public IList ExecProcedure(string StoredProcedure, SqlParameter[] parameters) + { + SqlConnection sqlConnection = new SqlConnection(ConnectionString); + SqlCommand command = new SqlCommand(); + + SqlParameter returnParameter = new SqlParameter("@RV", SqlDbType.Int); + returnParameter.Direction = ParameterDirection.ReturnValue; + + command.CommandText = StoredProcedure; + command.CommandType = CommandType.StoredProcedure; + command.Connection = sqlConnection; + command.Parameters.Add(returnParameter); + + if (parameters.Length > 0) + command.Parameters.AddRange(parameters); + + sqlConnection.Open(); + + command.ExecuteNonQuery(); + + var rv = parameters.Where(x => x.Direction.Equals(ParameterDirection.Output) || x.Direction.Equals(ParameterDirection.ReturnValue)).ToList(); + rv.Add(returnParameter); + + sqlConnection.Close(); + + return rv; + } + } +} diff --git a/OpenImis.DB.SqlServer/DataHelper/ProcedureOutPut.cs b/OpenImis.DB.SqlServer/DataHelper/ProcedureOutPut.cs new file mode 100644 index 00000000..b544ed52 --- /dev/null +++ b/OpenImis.DB.SqlServer/DataHelper/ProcedureOutPut.cs @@ -0,0 +1,11 @@ +using System; +using System.Data; + +namespace OpenImis.DB.SqlServer.DataHelper +{ + public class ProcedureOutPut + { + public int Code { get; set; } + public DataTable Data { get; set; } + } +} diff --git a/OpenImis.RestApi/Startup.cs b/OpenImis.RestApi/Startup.cs index 6116f420..d12feb8e 100644 --- a/OpenImis.RestApi/Startup.cs +++ b/OpenImis.RestApi/Startup.cs @@ -84,6 +84,11 @@ public void ConfigureServices(IServiceCollection services) options.AddPolicy("AllowSpecificOrigin", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowCredentials().AllowAnyHeader()); }); + + services.Configure(options => + { + options.SuppressModelStateInvalidFilter = true; + }); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) From fa152f73008aeaa499c4b06c355f16da5ab4e5f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kami=C5=84ski?= Date: Thu, 13 Jun 2019 12:54:45 +0200 Subject: [PATCH 04/86] OS-23: Module initialization --- .../CoverageModule/CoverageModule.cs | 11 ++++++ .../CoverageModule/ICoverageModule.cs | 11 ++++++ .../CoverageModule/Logic/CoverageLogic.cs | 11 ++++++ .../CoverageModule/Logic/ICoverageLogic.cs | 11 ++++++ .../CoverageModule/Models/CoverageProduct.cs | 34 +++++++++++++++++++ .../CoverageModule/Models/DataMessage.cs | 14 ++++++++ .../Repositories/CoverageRepository.cs | 32 +++++++++++++++++ .../Repositories/ICoverageRepository.cs | 11 ++++++ 8 files changed, 135 insertions(+) create mode 100644 OpenImis.Modules/CoverageModule/CoverageModule.cs create mode 100644 OpenImis.Modules/CoverageModule/ICoverageModule.cs create mode 100644 OpenImis.Modules/CoverageModule/Logic/CoverageLogic.cs create mode 100644 OpenImis.Modules/CoverageModule/Logic/ICoverageLogic.cs create mode 100644 OpenImis.Modules/CoverageModule/Models/CoverageProduct.cs create mode 100644 OpenImis.Modules/CoverageModule/Models/DataMessage.cs create mode 100644 OpenImis.Modules/CoverageModule/Repositories/CoverageRepository.cs create mode 100644 OpenImis.Modules/CoverageModule/Repositories/ICoverageRepository.cs diff --git a/OpenImis.Modules/CoverageModule/CoverageModule.cs b/OpenImis.Modules/CoverageModule/CoverageModule.cs new file mode 100644 index 00000000..daa37fb7 --- /dev/null +++ b/OpenImis.Modules/CoverageModule/CoverageModule.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.CoverageModule +{ + public class CoverageModule : ICoverageModule + { + + } +} diff --git a/OpenImis.Modules/CoverageModule/ICoverageModule.cs b/OpenImis.Modules/CoverageModule/ICoverageModule.cs new file mode 100644 index 00000000..7f7c65fb --- /dev/null +++ b/OpenImis.Modules/CoverageModule/ICoverageModule.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.CoverageModule +{ + public interface ICoverageModule + { + + } +} diff --git a/OpenImis.Modules/CoverageModule/Logic/CoverageLogic.cs b/OpenImis.Modules/CoverageModule/Logic/CoverageLogic.cs new file mode 100644 index 00000000..4f7fe0d8 --- /dev/null +++ b/OpenImis.Modules/CoverageModule/Logic/CoverageLogic.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.CoverageModule.Logic +{ + public class CoverageLogic : ICoverageLogic + { + + } +} diff --git a/OpenImis.Modules/CoverageModule/Logic/ICoverageLogic.cs b/OpenImis.Modules/CoverageModule/Logic/ICoverageLogic.cs new file mode 100644 index 00000000..1852265d --- /dev/null +++ b/OpenImis.Modules/CoverageModule/Logic/ICoverageLogic.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.CoverageModule.Logic +{ + public interface ICoverageLogic + { + + } +} diff --git a/OpenImis.Modules/CoverageModule/Models/CoverageProduct.cs b/OpenImis.Modules/CoverageModule/Models/CoverageProduct.cs new file mode 100644 index 00000000..fe20b77c --- /dev/null +++ b/OpenImis.Modules/CoverageModule/Models/CoverageProduct.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.CoverageModule.Models +{ + public class CoverageProduct + { + public string ProductCode { get; set; } + public string PolicyValue { get; set; } + public string EffectiveDate { get; set; } + public string ExpiryDate { get; set; } + public string Status { get; set; } + public string DedType { get; set; } + [JsonProperty(PropertyName = "DeductionHospital")] + public string Ded1 { get; set; } + [JsonProperty(PropertyName = "DeductionNonHospital")] + public string Ded2 { get; set; } + [JsonProperty(PropertyName = "CeilingHospital")] + public string Ceiling1 { get; set; } + [JsonProperty(PropertyName = "CeilingNonHospital")] + public string Ceiling2 { get; set; } + public string AntenatalAmountLeft { get; set; } + public string TotalVisitsLeft { get; set; } + public string ConsultationAmountLeft { get; set; } + public string DeliveryAmountLeft { get; set; } + public string HospitalizationAmountLeft { get; set; } + public string SurgeryAmountLeft { get; set; } + public string TotalAdmissionsLeft { get; set; } + public string TotalAntenatalLeft { get; set; } + public string TotalConsultationsLeft { get; set; } + } +} diff --git a/OpenImis.Modules/CoverageModule/Models/DataMessage.cs b/OpenImis.Modules/CoverageModule/Models/DataMessage.cs new file mode 100644 index 00000000..b9541f04 --- /dev/null +++ b/OpenImis.Modules/CoverageModule/Models/DataMessage.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.CoverageModule.Models +{ + public class DataMessage + { + public int Code { get; set; } + public string MessageValue { get; set; } + public bool ErrorOccured { get; set; } + public object Data { get; set; } + } +} diff --git a/OpenImis.Modules/CoverageModule/Repositories/CoverageRepository.cs b/OpenImis.Modules/CoverageModule/Repositories/CoverageRepository.cs new file mode 100644 index 00000000..52aeab6f --- /dev/null +++ b/OpenImis.Modules/CoverageModule/Repositories/CoverageRepository.cs @@ -0,0 +1,32 @@ +using Microsoft.EntityFrameworkCore; +using OpenImis.DB.SqlServer; +using OpenImis.Modules.CoverageModule.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenImis.Modules.CoverageModule.Repositories +{ + public class CoverageRepository : ICoverageRepository + { + public List Get(string insureeNumber) + { + List response = new List(); + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.Query().FromSql("uspAPIGetCoverage").ToList(); + } + + return response; + } + catch (Exception e) + { + throw e; + } + } + } +} diff --git a/OpenImis.Modules/CoverageModule/Repositories/ICoverageRepository.cs b/OpenImis.Modules/CoverageModule/Repositories/ICoverageRepository.cs new file mode 100644 index 00000000..9ee14e2f --- /dev/null +++ b/OpenImis.Modules/CoverageModule/Repositories/ICoverageRepository.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.CoverageModule.Repositories +{ + public interface ICoverageRepository + { + + } +} From e88f5f3c52c6a525f2d3f8f6c6776d21e5ec3c13 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Tue, 25 Jun 2019 13:41:26 +0200 Subject: [PATCH 05/86] OS-23: Added module content --- .../CoverageModule/CoverageModule.cs | 19 +++- .../Helpers/GetCoverageResponse.cs | 53 +++++++++ .../CoverageModule/Helpers/ImisApiResponse.cs | 52 +++++++++ .../Helpers/Messages/Language.cs | 33 ++++++ .../Helpers/Messages/PrimaryLanguage.cs | 107 ++++++++++++++++++ .../Helpers/Messages/SecondaryLanguage.cs | 88 ++++++++++++++ .../CoverageModule/ICoverageModule.cs | 5 +- .../CoverageModule/Logic/CoverageLogic.cs | 21 +++- .../CoverageModule/Logic/ICoverageLogic.cs | 5 +- .../CoverageModule/Models/CoverageModel.cs | 14 +++ .../Repositories/CoverageRepository.cs | 49 ++++++-- .../Repositories/ICoverageRepository.cs | 5 +- OpenImis.Modules/IImisModules.cs | 5 +- OpenImis.Modules/ImisModules.cs | 16 ++- .../Controllers/CoverageController.cs | 74 ++++++++++++ 15 files changed, 525 insertions(+), 21 deletions(-) create mode 100644 OpenImis.Modules/CoverageModule/Helpers/GetCoverageResponse.cs create mode 100644 OpenImis.Modules/CoverageModule/Helpers/ImisApiResponse.cs create mode 100644 OpenImis.Modules/CoverageModule/Helpers/Messages/Language.cs create mode 100644 OpenImis.Modules/CoverageModule/Helpers/Messages/PrimaryLanguage.cs create mode 100644 OpenImis.Modules/CoverageModule/Helpers/Messages/SecondaryLanguage.cs create mode 100644 OpenImis.Modules/CoverageModule/Models/CoverageModel.cs create mode 100644 OpenImis.RestApi/Controllers/CoverageController.cs diff --git a/OpenImis.Modules/CoverageModule/CoverageModule.cs b/OpenImis.Modules/CoverageModule/CoverageModule.cs index daa37fb7..6b84e2c4 100644 --- a/OpenImis.Modules/CoverageModule/CoverageModule.cs +++ b/OpenImis.Modules/CoverageModule/CoverageModule.cs @@ -1,4 +1,6 @@ -using System; +using Microsoft.Extensions.Configuration; +using OpenImis.Modules.CoverageModule.Logic; +using System; using System.Collections.Generic; using System.Text; @@ -6,6 +8,21 @@ namespace OpenImis.Modules.CoverageModule { public class CoverageModule : ICoverageModule { + private IConfiguration Configuration; + private ICoverageLogic _coverageLogic; + public CoverageModule(IConfiguration configuration) + { + Configuration = configuration; + } + + public ICoverageLogic GetCoverageLogic() + { + if (_coverageLogic == null) + { + _coverageLogic = new CoverageLogic(Configuration); + } + return _coverageLogic; + } } } diff --git a/OpenImis.Modules/CoverageModule/Helpers/GetCoverageResponse.cs b/OpenImis.Modules/CoverageModule/Helpers/GetCoverageResponse.cs new file mode 100644 index 00000000..10ee57fe --- /dev/null +++ b/OpenImis.Modules/CoverageModule/Helpers/GetCoverageResponse.cs @@ -0,0 +1,53 @@ +using Newtonsoft.Json; +using OpenImis.Modules.CoverageModule.Helpers.Messages; +using OpenImis.Modules.CoverageModule.Models; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.CoverageModule.Helpers +{ + public class GetCoverageResponse : ImisApiResponse + { + public GetCoverageResponse(Exception error) : base(error) + { + + } + public GetCoverageResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + public GetCoverageResponse(int value, bool error, object data, int lang) : base(value, error, data, lang) + { + var jsonString = JsonConvert.SerializeObject(data); + var _data = JsonConvert.DeserializeObject(jsonString); + + msg.Data = _data; + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongFormatMissingIN"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "INNotFount"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/CoverageModule/Helpers/ImisApiResponse.cs b/OpenImis.Modules/CoverageModule/Helpers/ImisApiResponse.cs new file mode 100644 index 00000000..b02fdaf2 --- /dev/null +++ b/OpenImis.Modules/CoverageModule/Helpers/ImisApiResponse.cs @@ -0,0 +1,52 @@ +using Newtonsoft.Json; +using OpenImis.Modules.CoverageModule.Models; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.CoverageModule.Helpers +{ + public class ImisApiResponse + { + public DataMessage msg = new DataMessage(); + public int language { get; set; } + + public ImisApiResponse(Exception e) + { + msg.Code = -1; + msg.ErrorOccured = true; + msg.MessageValue = e.Message; + Message = msg; + } + + public ImisApiResponse(int value, bool error, int lang) + { + if (value != 0) + error = true; + + language = lang; + + msg.Code = value; + msg.ErrorOccured = error; + Message = msg; + + } + + public ImisApiResponse(int value, bool error, object data, int lang) + { + if (value != 0) + error = true; + + language = lang; + + msg.Code = value; + msg.ErrorOccured = error; + msg.Data = JsonConvert.SerializeObject(data); + Message = msg; + } + + public DataMessage Message { get; set; } + + } +} diff --git a/OpenImis.Modules/CoverageModule/Helpers/Messages/Language.cs b/OpenImis.Modules/CoverageModule/Helpers/Messages/Language.cs new file mode 100644 index 00000000..6f204815 --- /dev/null +++ b/OpenImis.Modules/CoverageModule/Helpers/Messages/Language.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; + +namespace OpenImis.Modules.CoverageModule.Helpers.Messages +{ + public class Language + { + public string GetMessage(int language, string name) + { + FieldInfo fieldInfos; + + switch (language) + { + + case 0: + fieldInfos = typeof(PrimaryLanguage).GetField(name); + break; + case 1: + fieldInfos = typeof(SecondaryLanguage).GetField(name); + + break; + default: + fieldInfos = typeof(PrimaryLanguage).GetField(name); + + break; + } + var val = (string)fieldInfos.GetValue(null); + return val; + } + } +} diff --git a/OpenImis.Modules/CoverageModule/Helpers/Messages/PrimaryLanguage.cs b/OpenImis.Modules/CoverageModule/Helpers/Messages/PrimaryLanguage.cs new file mode 100644 index 00000000..77d4a1b3 --- /dev/null +++ b/OpenImis.Modules/CoverageModule/Helpers/Messages/PrimaryLanguage.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.CoverageModule.Helpers.Messages +{ + public static class PrimaryLanguage + { + public static string Success = "Success"; + + //CtrlNumberResponse + public static string CantAssignCN = "1-Control number cannot be assigned by the external payment gateway"; + public static string DuplicateCN = "2-Duplicate Control Number"; + + //DeleteMemberFamilyResponse + public static string WrongFormatMissingIN = "Wrong Format or Missing Insurance Number of Member"; + public static string INNotFount = "Insurance number of member not found"; + public static string MemberNotHead = "Mamber is head of family"; + + //EditFamilyResponse + public static string WrongOrMissingHeadIN = "Wrong Format or Missing Insurance Number of head."; + public static string HeadINNotFound = "Insurance Number of head not found."; + public static string WrongPVillageCode = "Wrong permanent village code."; + public static string WrongCVillageCode = "Wrong current village Code."; + public static string WrongGender = "Wrong gender."; + public static string WrongConfirmationType = "Wrong confirmation type"; + public static string WrongGroupType = "Wrong group type"; + public static string WrongMaritalStatus = "Wrong marital status"; + public static string WrongEducation = "Wrong education"; + public static string WrongProfession = "Wrong profession."; + public static string FSPCodeNotFound = "FSP code not found"; + public static string WrongIdentificationType = "Wrong Identification Type"; + + //EditMemberFamilyResponse + public static string WrongINMember = "Wrong format of insurance number of member"; + public static string NotFountINMember = "Insurance number of member not found"; + public static string WrongVillageCode = "Wrong current village code"; + public static string WrongRelationship = "Wrong Relationship"; + + //EnterContributionResponse + public static string WrongOrMissingPC = "Wrong or missing product code (not existing or not applicable to the family/group)"; + public static string WrongOrMissingPayDate = "Wrong or missing payment date"; + public static string WrongContributionCat = "Wrong contribution category"; + public static string WrongOrMissingPayType = "Wrong or missing payment type"; + public static string WrongOrMissingPayer = "Wrong or missing payer"; + public static string MissingReceiptNumber = "Missing receipt no."; + public static string DuplicateReceiptNumber = "Duplicated receipt no."; + + //EnterFamilyResponse + public static string DuplicateINHead = "Duplicated Insurance Number of head."; + public static string WrongOrMissingPVC = "Wrong or missing permanent village code."; + public static string WrongOrMissingGender = "Wrong or missing gender."; + public static string WrongFrOrMissingBd = "Wrong format or missing birth date."; + public static string MissingLastName = "Missing last name."; + public static string MissingOtherName = "Missing other name"; + + //EnterMemberFamilyResponse + public static string DuplicatedMemberIN = "Insurance number of member duplicated "; + + //EnterPolicyResponse + public static string WrongOrMissingEnrolDate = "Wrong or missing enrolment date"; + public static string WrongOrMissingEOcode = "Wrong or missing enrolment officer code (not existing or not applicable to the family/group)"; + + //GetCoverageResponse + + //GetFamilyResponse + + //GetMemberFamilyResponse + public static string NoMemberOfOrder = "No member of the specified order number in the family/group"; + + //MatchPayResponse + public static string PayIdDoesntExist = "1-The paymentId does not exist"; + + //RenewPolicyResponse + public static string WrongOrMissingRenDate = "Wrong or missing renewal date"; + + //RequestedCNResponse + public static string WrongInternalIdFormat = "1-Wrong format of internal identifier"; + public static string InvalidInternalId = "2-Not valid internal identifier "; + + //SaveAckResponse + public static string CantPostReq = "1-Request for control number cannot be posted in the external payment gateway"; + + //SaveIntentResponse + public static string WrongFormatInsureeNo = "1-Wrong format of insurance number"; + public static string InValidINmissingPC = "2-Not valid insurance or missing product code"; + public static string InValidEOC = "3-Not valid enrolment officer code"; + public static string IncompatibleEO_PC = "4-Enrolment officer code and insurance product code are not compatible"; + public static string NoRenewalProduct = "5-Beneficiary has no policy of specified insurance product for renewal"; + public static string InsureeNoMissing = "6-Missing insurance number"; + public static string InsureeNotEnrolled = "7-Insuree not enrolled while prior enrolment mandatory."; + public static string DuplicateCNAssigned = "8-Duplicated control number assigned"; + public static string CantAssignCn2 = "9-Control number cannot be assigned"; + public static string UnknownPaymentType = "10-Uknown type of payment"; + + //SavePayResponse + public static string WrongOrMissingRecDate = "1-Wrong or missing receiving date"; + public static string WrongFormatInputData = "2-Wrong format of input data"; + public static string WrongControlNumber = "3-Wrong control_number"; + public static string WrongAmount = "4-Wrong Amount"; + public static string DuplicatePayAmount = "5-Duplicate Payment Amount"; + public static string DoesntExistEO = "6-Enrolment Officer Code does not exist"; + public static string DoesntExistPC = "7-Product Code Does not Exist"; + public static string NoPolicyForRenewal = "8-Beneficiary has no policy of specified insurance product for renewal"; + public static string UnknownTypeOfPay = "9-Uknown type of payment"; + } +} diff --git a/OpenImis.Modules/CoverageModule/Helpers/Messages/SecondaryLanguage.cs b/OpenImis.Modules/CoverageModule/Helpers/Messages/SecondaryLanguage.cs new file mode 100644 index 00000000..2f09c804 --- /dev/null +++ b/OpenImis.Modules/CoverageModule/Helpers/Messages/SecondaryLanguage.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.CoverageModule.Helpers.Messages +{ + public static class SecondaryLanguage + { + public static string Success = "Imefanikiwa"; + + public static string CantAssignCN = "1-Na. ya ankara imeshindikana kutotelewa na mfumo wa malipo"; + public static string DuplicateCN = "2-Na. ya ankara imejirudia"; + + public static string WrongFormatMissingIN = "Umekosea namba ya mwanachama au namba haipo"; + public static string INNotFount = "Namba ya mwanachama haipo"; + public static string MemberNotHead = "Mwanachama ni mkuu wa kaya"; + + public static string WrongOrMissingHeadIN = "Umekosea namba ya mkuu wa kaya au namba haipo"; + public static string HeadINNotFound = "Namba ya mkuu wa kaya haipo"; + public static string WrongPVillageCode = "Umekosea namba ya kijiji"; + public static string WrongCVillageCode = "Umekosea namba ya kijiji"; + public static string WrongGender = "Umekosea jinsia"; + public static string WrongConfirmationType = "Wrong confirmation type"; + public static string WrongGroupType = "Umekosea aina ya kundi"; + public static string WrongMaritalStatus = "Umekosea hali ya ndoa"; + public static string WrongEducation = "Umekosea elimu"; + public static string WrongProfession = "Umekosea elimu"; + public static string FSPCodeNotFound = "Na. ya FSP haipo"; + public static string WrongIdentificationType = "Umekosea aina ya kitambulisho"; + + public static string WrongINMember = "Umekosea namba ya mwanachama"; + public static string NotFountINMember = "Namba ya mwanachama haipo kwenye kompuyta kuu"; + public static string WrongVillageCode = "Umekosea namba ya kijiji"; + public static string WrongRelationship = "Umekosea uhusiano"; + + public static string WrongOrMissingPC = "Umekosea namba ya bidhaa au haitumiki kwenye familia husika"; + public static string WrongOrMissingPayDate = "Umekosea tarehe ya malipo"; + public static string WrongContributionCat = "Umekosea kundi la malipo"; + public static string WrongOrMissingPayType = "Umekosea aina ya malipo"; + public static string WrongOrMissingPayer = "Umekosea mlipaji"; + public static string MissingReceiptNumber = "Jaza namba ya risiti"; + public static string DuplicateReceiptNumber = "Namba ya risiti imejirudia"; + + public static string DuplicateINHead = "Namba ya mwachama imejirudia"; + public static string WrongOrMissingPVC = "Umekosea/Jaza namba ya kijiji"; + public static string WrongOrMissingGender = "Umekosea/Jaza Jinsia"; + public static string WrongFrOrMissingBd = "Jaza/Umekosea tarehe"; + public static string MissingLastName = "Jaza jina la ukoo"; + public static string MissingOtherName = "Jaza majina mengine"; + + public static string DuplicatedMemberIN = "Namba ya mwanachama imejirudia"; + + public static string WrongOrMissingEnrolDate = "Jaza/Umekosea tarehe ya kujiunga"; + public static string WrongOrMissingEOcode = "Jaza/Umekosea namba ya msimbo ya afisa mwandikishaji"; + + public static string NoMemberOfOrder = "Na ya mwanchama kwenye familia haipo"; + public static string PayIdDoesntExist = "1-Namba ya malipo haipo"; + + public static string WrongOrMissingRenDate = "Jaza/Umekosea tarehe ya kuhuisha"; + + public static string WrongInternalIdFormat = "1-Wrong format of internal identifier"; + public static string InvalidInternalId = "2-Not valid internal identifier "; + + public static string CantPostReq = "1-Maombi ya Na. ya ankara yameshindikana, jaribu tena"; + + public static string WrongFormatInsureeNo = "1-Namba ya mwanachama imekosewa"; + public static string InValidINmissingPC = "2-Umekosea namba ya mwanachama au namba ya bidhaa"; + public static string InValidEOC = "3-Umekosea namba ya msimbo ya afisa mwandikishaji"; + public static string IncompatibleEO_PC = "4-Namba ya mwanachama na namba ya bidhaa haviendani"; + public static string NoRenewalProduct = "5-Mwanachama hajajiunga na bidhaa husika"; + + public static string InsureeNoMissing = "6-Jaza namba ya mwanachama"; + public static string InsureeNotEnrolled = "7-Insuree not enrolled while prior enrolment mandatory."; + public static string DuplicateCNAssigned = "8-Umepatiwa namba ya ankara iliyojirudia, jaribu tena"; + public static string CantAssignCn2 = "9-Na. ya ankara imeshishindikana kutolewa, jaribu tena"; + public static string UnknownPaymentType = "10-Aina ya malipo uliyochagua hayapo"; + + public static string WrongOrMissingRecDate = "1-Umekosea tarehe ya kupokea"; + public static string WrongFormatInputData = "2-Umekosea taarifa uliyojaza"; + public static string WrongControlNumber = "3-Umekosea Na. ya ankara"; + public static string WrongAmount = "4-Umekosea kiasi"; + public static string DuplicatePayAmount = "5-Umerudia malipo"; + public static string DoesntExistEO = "6-Namba ya msimbo ya afisa mwandikishaji haipo"; + public static string DoesntExistPC = "7-Namba ya bidhaa haipo"; + public static string NoPolicyForRenewal = "8-Mwanachama hajajiunga na bidhaa husika"; + public static string UnknownTypeOfPay = "9-Aina ya malipo uliyochagua haipo"; + } +} diff --git a/OpenImis.Modules/CoverageModule/ICoverageModule.cs b/OpenImis.Modules/CoverageModule/ICoverageModule.cs index 7f7c65fb..dac9346f 100644 --- a/OpenImis.Modules/CoverageModule/ICoverageModule.cs +++ b/OpenImis.Modules/CoverageModule/ICoverageModule.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.Modules.CoverageModule.Logic; +using System; using System.Collections.Generic; using System.Text; @@ -6,6 +7,6 @@ namespace OpenImis.Modules.CoverageModule { public interface ICoverageModule { - + ICoverageLogic GetCoverageLogic(); } } diff --git a/OpenImis.Modules/CoverageModule/Logic/CoverageLogic.cs b/OpenImis.Modules/CoverageModule/Logic/CoverageLogic.cs index 4f7fe0d8..26986457 100644 --- a/OpenImis.Modules/CoverageModule/Logic/CoverageLogic.cs +++ b/OpenImis.Modules/CoverageModule/Logic/CoverageLogic.cs @@ -1,4 +1,7 @@ -using System; +using Microsoft.Extensions.Configuration; +using OpenImis.Modules.CoverageModule.Models; +using OpenImis.Modules.CoverageModule.Repositories; +using System; using System.Collections.Generic; using System.Text; @@ -6,6 +9,22 @@ namespace OpenImis.Modules.CoverageModule.Logic { public class CoverageLogic : ICoverageLogic { + private IConfiguration Configuration; + protected ICoverageRepository coverageRepository; + public CoverageLogic(IConfiguration configuration) + { + Configuration = configuration; + coverageRepository = new CoverageRepository(Configuration); + } + + public CoverageModel Get(string insureeNumber) + { + CoverageModel response; + + response = coverageRepository.Get(insureeNumber); + + return response; + } } } diff --git a/OpenImis.Modules/CoverageModule/Logic/ICoverageLogic.cs b/OpenImis.Modules/CoverageModule/Logic/ICoverageLogic.cs index 1852265d..5b87bb81 100644 --- a/OpenImis.Modules/CoverageModule/Logic/ICoverageLogic.cs +++ b/OpenImis.Modules/CoverageModule/Logic/ICoverageLogic.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.Modules.CoverageModule.Models; +using System; using System.Collections.Generic; using System.Text; @@ -6,6 +7,6 @@ namespace OpenImis.Modules.CoverageModule.Logic { public interface ICoverageLogic { - + CoverageModel Get(string insureeNumber); } } diff --git a/OpenImis.Modules/CoverageModule/Models/CoverageModel.cs b/OpenImis.Modules/CoverageModule/Models/CoverageModel.cs new file mode 100644 index 00000000..e48ba670 --- /dev/null +++ b/OpenImis.Modules/CoverageModule/Models/CoverageModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.CoverageModule.Models +{ + public class CoverageModel + { + public string OtherNames { get; set; } + public string LastNames { get; set; } + public string BirthDate { get; set; } + public List CoverageProducts { get; set; } + } +} diff --git a/OpenImis.Modules/CoverageModule/Repositories/CoverageRepository.cs b/OpenImis.Modules/CoverageModule/Repositories/CoverageRepository.cs index 52aeab6f..e974f57e 100644 --- a/OpenImis.Modules/CoverageModule/Repositories/CoverageRepository.cs +++ b/OpenImis.Modules/CoverageModule/Repositories/CoverageRepository.cs @@ -1,8 +1,13 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; using OpenImis.DB.SqlServer; +using OpenImis.DB.SqlServer.DataHelper; using OpenImis.Modules.CoverageModule.Models; using System; using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; using System.Linq; using System.Text; @@ -10,23 +15,47 @@ namespace OpenImis.Modules.CoverageModule.Repositories { public class CoverageRepository : ICoverageRepository { - public List Get(string insureeNumber) + private IConfiguration Configuration; + + public CoverageRepository(IConfiguration configuration) + { + Configuration = configuration; + } + + public CoverageModel Get(string insureeNumber) { - List response = new List(); + CoverageModel response = null; + DataTable data; + + DataHelper helper = new DataHelper(Configuration); + + SqlParameter[] sqlParameters = { + new SqlParameter("@InsureeNumber", insureeNumber), + }; try { - using (var imisContext = new ImisDB()) - { - response = imisContext.Query().FromSql("uspAPIGetCoverage").ToList(); - } - - return response; + data = helper.GetDataTable("uspAPIGetCoverage", sqlParameters, CommandType.StoredProcedure); } - catch (Exception e) + catch (SqlException) { - throw e; + throw; } + catch (Exception) + { + throw new Exception(); + } + + if (data.Rows.Count > 0) + { + var firstRow = data.Rows[0]; + var jsonString = JsonConvert.SerializeObject(data); + var coverage_products = JsonConvert.DeserializeObject>(jsonString); + + response = new CoverageModel() { OtherNames = firstRow["OtherNames"].ToString(), LastNames = firstRow["LastName"].ToString(), BirthDate = firstRow["DOB"].ToString(), CoverageProducts = coverage_products }; + } + + return response; } } } diff --git a/OpenImis.Modules/CoverageModule/Repositories/ICoverageRepository.cs b/OpenImis.Modules/CoverageModule/Repositories/ICoverageRepository.cs index 9ee14e2f..5b03164a 100644 --- a/OpenImis.Modules/CoverageModule/Repositories/ICoverageRepository.cs +++ b/OpenImis.Modules/CoverageModule/Repositories/ICoverageRepository.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.Modules.CoverageModule.Models; +using System; using System.Collections.Generic; using System.Text; @@ -6,6 +7,6 @@ namespace OpenImis.Modules.CoverageModule.Repositories { public interface ICoverageRepository { - + CoverageModel Get(string insureeNumber); } } diff --git a/OpenImis.Modules/IImisModules.cs b/OpenImis.Modules/IImisModules.cs index 32ae87b1..bda4869f 100644 --- a/OpenImis.Modules/IImisModules.cs +++ b/OpenImis.Modules/IImisModules.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using OpenImis.Modules.MasterDataManagementModule; +using OpenImis.Modules.CoverageModule; namespace OpenImis.Modules { @@ -25,5 +26,7 @@ public interface IImisModules IMasterDataManagementModule GetMasterDataManagementModule(); - } + ICoverageModule GetCoverageModule(); + + } } diff --git a/OpenImis.Modules/ImisModules.cs b/OpenImis.Modules/ImisModules.cs index 820427c4..0a2bc6d9 100644 --- a/OpenImis.Modules/ImisModules.cs +++ b/OpenImis.Modules/ImisModules.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Configuration; using OpenImis.Modules.MasterDataManagementModule; using OpenImis.Modules.MasterDataManagementModule.Logic; +using OpenImis.Modules.CoverageModule; namespace OpenImis.Modules { @@ -36,7 +37,9 @@ public class ImisModules: IImisModules private IInsureeManagementModule insureeManagementModule; private IMasterDataManagementModule masterDataManagementModule; - private readonly IConfiguration _configuration; + private ICoverageModule coverageModule; + + private readonly IConfiguration _configuration; private readonly ILogger logger; public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory) @@ -45,7 +48,16 @@ public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory) logger = loggerFactory.CreateLogger("LoggerCategory"); } - /// + public ICoverageModule GetCoverageModule() + { + if (coverageModule == null) + { + coverageModule = new CoverageModule.CoverageModule(_configuration); + } + return coverageModule; + } + + /// /// Creates and returns the user management module. /// /// diff --git a/OpenImis.RestApi/Controllers/CoverageController.cs b/OpenImis.RestApi/Controllers/CoverageController.cs new file mode 100644 index 00000000..7ccb7b33 --- /dev/null +++ b/OpenImis.RestApi/Controllers/CoverageController.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Diagnostics; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Cors; +using Microsoft.AspNetCore.Mvc; +using OpenImis.Modules; +using OpenImis.Modules.CoverageModule.Helpers; +using OpenImis.Modules.CoverageModule.Models; + +namespace OpenImis.RestApi.Controllers +{ + [Route("api/")] + [ApiController] + [EnableCors("AllowSpecificOrigin")] + public class CoverageController : Controller + { + private readonly IImisModules _imisModules; + public CoverageController(IImisModules imisModules) + { + _imisModules = imisModules; + } + + [HttpGet] + [Route("Coverage/Get_Coverage")] + public virtual IActionResult Get(string InsureeNumber) + { + // Temporary HTTP 400 + if (!ModelState.IsValid) + { + return BadRequest(new { error_occured = true, error_message = "1:Wrong format or missing insurance number of insuree" }); + } + + //if (new ValidationBase().InsureeNumber(InsureeNumber) != ValidationResult.Success) + //{ + // return BadRequest(new { error_occured = true, error_message = "1:Wrong format or missing insurance number of insuree" }); + //} + + DataMessage response; + try + { + if (InsureeNumber != null || InsureeNumber.Length != 0) + { + var data = _imisModules.GetCoverageModule().GetCoverageLogic().Get(InsureeNumber); + + if (data != null) + { + response = new GetCoverageResponse(0, false, data, 0).Message; + } + else + { + response = new GetCoverageResponse(2, true, 0).Message; + } + } + else + { + response = new GetCoverageResponse(1, true, 0).Message; + } + } + catch (SqlException e) + { + response = new GetCoverageResponse(e).Message; + } + catch (Exception e) + { + response = new GetCoverageResponse(e).Message; + } + + return Json(response); + } + } +} \ No newline at end of file From fed80ed59058280a55ced070431fdb2ddd78e6dd Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 26 Jun 2019 13:31:36 +0200 Subject: [PATCH 06/86] OS-24: Added module --- OpenImis.Modules/IImisModules.cs | 3 + OpenImis.Modules/ImisModules.cs | 16 +++- OpenImis.Modules/LoginModule/ILoginModule.cs | 12 +++ .../LoginModule/Logic/ILoginLogic.cs | 12 +++ .../LoginModule/Logic/LoginLogic.cs | 82 +++++++++++++++++ OpenImis.Modules/LoginModule/LoginModule.cs | 28 ++++++ .../LoginModule/Models/Language.cs | 12 +++ .../LoginModule/Models/LoginModel.cs | 12 +++ OpenImis.Modules/LoginModule/Models/Rights.cs | 23 +++++ .../LoginModule/Models/UserData.cs | 15 +++ .../Repositories/ILoginRepository.cs | 14 +++ .../Repositories/LoginRepository.cs | 91 +++++++++++++++++++ .../Controllers/LoginController.cs | 73 +++++++++++++++ 13 files changed, 391 insertions(+), 2 deletions(-) create mode 100644 OpenImis.Modules/LoginModule/ILoginModule.cs create mode 100644 OpenImis.Modules/LoginModule/Logic/ILoginLogic.cs create mode 100644 OpenImis.Modules/LoginModule/Logic/LoginLogic.cs create mode 100644 OpenImis.Modules/LoginModule/LoginModule.cs create mode 100644 OpenImis.Modules/LoginModule/Models/Language.cs create mode 100644 OpenImis.Modules/LoginModule/Models/LoginModel.cs create mode 100644 OpenImis.Modules/LoginModule/Models/Rights.cs create mode 100644 OpenImis.Modules/LoginModule/Models/UserData.cs create mode 100644 OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs create mode 100644 OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs create mode 100644 OpenImis.RestApi/Controllers/LoginController.cs diff --git a/OpenImis.Modules/IImisModules.cs b/OpenImis.Modules/IImisModules.cs index 32ae87b1..cd02a7bc 100644 --- a/OpenImis.Modules/IImisModules.cs +++ b/OpenImis.Modules/IImisModules.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using OpenImis.Modules.MasterDataManagementModule; +using OpenImis.Modules.LoginModule; namespace OpenImis.Modules { @@ -13,6 +14,8 @@ namespace OpenImis.Modules /// public interface IImisModules { + ILoginModule GetLoginModule(); + /// /// Creates and returns the user management module. /// diff --git a/OpenImis.Modules/ImisModules.cs b/OpenImis.Modules/ImisModules.cs index 820427c4..e1e2c84c 100644 --- a/OpenImis.Modules/ImisModules.cs +++ b/OpenImis.Modules/ImisModules.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Configuration; using OpenImis.Modules.MasterDataManagementModule; using OpenImis.Modules.MasterDataManagementModule.Logic; +using OpenImis.Modules.LoginModule; namespace OpenImis.Modules { @@ -36,7 +37,9 @@ public class ImisModules: IImisModules private IInsureeManagementModule insureeManagementModule; private IMasterDataManagementModule masterDataManagementModule; - private readonly IConfiguration _configuration; + private ILoginModule loginModule; + + private readonly IConfiguration _configuration; private readonly ILogger logger; public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory) @@ -45,7 +48,16 @@ public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory) logger = loggerFactory.CreateLogger("LoggerCategory"); } - /// + public ILoginModule GetLoginModule() + { + if (loginModule == null) + { + loginModule = new LoginModule.LoginModule(_configuration); + } + return loginModule; + } + + /// /// Creates and returns the user management module. /// /// diff --git a/OpenImis.Modules/LoginModule/ILoginModule.cs b/OpenImis.Modules/LoginModule/ILoginModule.cs new file mode 100644 index 00000000..cbccb53b --- /dev/null +++ b/OpenImis.Modules/LoginModule/ILoginModule.cs @@ -0,0 +1,12 @@ +using OpenImis.Modules.LoginModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.LoginModule +{ + public interface ILoginModule + { + ILoginLogic GetLoginLogic(); + } +} diff --git a/OpenImis.Modules/LoginModule/Logic/ILoginLogic.cs b/OpenImis.Modules/LoginModule/Logic/ILoginLogic.cs new file mode 100644 index 00000000..d48bca6d --- /dev/null +++ b/OpenImis.Modules/LoginModule/Logic/ILoginLogic.cs @@ -0,0 +1,12 @@ +using OpenImis.Modules.LoginModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.LoginModule.Logic +{ + public interface ILoginLogic + { + UserData FindUser(string UserName, string Password); + } +} diff --git a/OpenImis.Modules/LoginModule/Logic/LoginLogic.cs b/OpenImis.Modules/LoginModule/Logic/LoginLogic.cs new file mode 100644 index 00000000..b66f4fb7 --- /dev/null +++ b/OpenImis.Modules/LoginModule/Logic/LoginLogic.cs @@ -0,0 +1,82 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.Modules.LoginModule.Models; +using OpenImis.Modules.LoginModule.Repositories; +using System; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Security.Claims; +using System.Security.Cryptography; +using System.Text; + +namespace OpenImis.Modules.LoginModule.Logic +{ + public class LoginLogic : ILoginLogic + { + private IConfiguration Configuration; + protected ILoginRepository loginRepository; + + public LoginLogic(IConfiguration configuration) + { + Configuration = configuration; + loginRepository = new LoginRepository(Configuration); + } + + public UserData FindUser(string UserName, string Password) + { + var users = loginRepository.FindUserByName(UserName); + + if (users.Count == 1) + { + UserData user = users.FirstOrDefault(); + + bool validUser = ValidateLogin(user, Password); + + if (validUser) + { + List userRights = loginRepository.GetUserRights(user.UserID); + user.Rights = userRights; + return user; + } + else + { + return null; + } + } + else + { + return null; + } + } + + private bool ValidateLogin(UserData user, string password) + { + var generatedSHA = GenerateSHA256String(password + user.PrivateKey); + if (generatedSHA == user.StoredPassword) + { + return true; + } + else + { + return false; + } + } + + private string GenerateSHA256String(string inputString) + { + SHA256 sha256 = SHA256Managed.Create(); + byte[] bytes = Encoding.UTF8.GetBytes(inputString); + byte[] hash = sha256.ComputeHash(bytes); + var stringBuilder = new StringBuilder(); + + for (int i = 0; i < hash.Length; i++) + { + var str = hash[i].ToString("X2"); + stringBuilder.Append(str); + } + + return stringBuilder.ToString(); + } + } +} diff --git a/OpenImis.Modules/LoginModule/LoginModule.cs b/OpenImis.Modules/LoginModule/LoginModule.cs new file mode 100644 index 00000000..3d767a8a --- /dev/null +++ b/OpenImis.Modules/LoginModule/LoginModule.cs @@ -0,0 +1,28 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.Modules.LoginModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.LoginModule +{ + public class LoginModule : ILoginModule + { + private IConfiguration Configuration; + private ILoginLogic _loginLogic; + + public LoginModule(IConfiguration configuration) + { + Configuration = configuration; + } + + public ILoginLogic GetLoginLogic() + { + if (_loginLogic == null) + { + _loginLogic = new LoginLogic(Configuration); + } + return _loginLogic; + } + } +} diff --git a/OpenImis.Modules/LoginModule/Models/Language.cs b/OpenImis.Modules/LoginModule/Models/Language.cs new file mode 100644 index 00000000..ab6be323 --- /dev/null +++ b/OpenImis.Modules/LoginModule/Models/Language.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.LoginModule.Models +{ + public enum Language + { + Primary, + Secondary + } +} diff --git a/OpenImis.Modules/LoginModule/Models/LoginModel.cs b/OpenImis.Modules/LoginModule/Models/LoginModel.cs new file mode 100644 index 00000000..83208adb --- /dev/null +++ b/OpenImis.Modules/LoginModule/Models/LoginModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.LoginModule.Models +{ + public class LoginModel + { + public string UserName { get; set; } + public string Password { get; set; } + } +} diff --git a/OpenImis.Modules/LoginModule/Models/Rights.cs b/OpenImis.Modules/LoginModule/Models/Rights.cs new file mode 100644 index 00000000..8c57dd80 --- /dev/null +++ b/OpenImis.Modules/LoginModule/Models/Rights.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.LoginModule.Models +{ + public enum Rights + { + PaymentSearch = 101401, + PaymentAdd = 101402, + PaymentEdit = 101403, + PaymentDelete = 101404, + + InsureeSearch = 101101, + InsureeAdd = 101102, + InsureeEdit = 101103, + InsureeDelete = 101104, + InsureeEnquire = 101105, + + FindClaim = 111001, + ClaimAdd = 111002 + } +} diff --git a/OpenImis.Modules/LoginModule/Models/UserData.cs b/OpenImis.Modules/LoginModule/Models/UserData.cs new file mode 100644 index 00000000..22cc14df --- /dev/null +++ b/OpenImis.Modules/LoginModule/Models/UserData.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.LoginModule.Models +{ + public class UserData + { + public string UserID { get; set; } + public string LoginName { get; set; } + public string PrivateKey { get; set; } + public string StoredPassword { get; set; } + public List Rights { get; set; } + } +} diff --git a/OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs b/OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs new file mode 100644 index 00000000..855613a6 --- /dev/null +++ b/OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs @@ -0,0 +1,14 @@ +using OpenImis.Modules.LoginModule.Models; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.LoginModule.Repositories +{ + public interface ILoginRepository + { + List FindUserByName(string UserName); + List GetUserRights(string userId); + } +} diff --git a/OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs b/OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs new file mode 100644 index 00000000..9fa10242 --- /dev/null +++ b/OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs @@ -0,0 +1,91 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using OpenImis.DB.SqlServer.DataHelper; +using OpenImis.Modules.LoginModule.Models; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Text; + +namespace OpenImis.Modules.LoginModule.Repositories +{ + public class LoginRepository : ILoginRepository + { + private IConfiguration Configuration; + + public LoginRepository(IConfiguration configuration) + { + Configuration = configuration; + } + + public List FindUserByName(string UserName) + { + List response = new List(); + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.TblUsers + .Where(u => u.LoginName == UserName && u.ValidityTo == null) + .Select(x => new UserData() + { + UserID = Convert.ToString(x.UserId), + LoginName = Convert.ToString(x.LoginName), + PrivateKey = Convert.ToString(x.PrivateKey), + StoredPassword = Convert.ToString(x.StoredPassword) + }) + .ToList(); + } + + return response; + } + catch (Exception e) + { + throw e; + } + } + + public List GetUserRights(string userId) + { + DataHelper helper = new DataHelper(Configuration); + + var rights = new List(); + + var sSQL = @"SELECT DISTINCT tblRoleRight.RightID + FROM tblRole INNER JOIN + tblRoleRight ON tblRole.RoleID = tblRoleRight.RoleID AnD tblRoleRight.ValidityTo IS NULL + INNER JOIN + tblUserRole ON tblRole.RoleID = tblUserRole.RoleID AND tblUserRole.ValidityTo IS NULL + INNER JOIN + tblUsers ON tblUserRole.UserID = tblUsers.UserID AND tblUsers.ValidityTo IS NULL + WHERE tblUsers.UserID = @UserId AND tblRole.ValidityTo IS NULL"; + + SqlParameter[] paramets = { + new SqlParameter("@UserId", userId) + }; + + var dt = helper.GetDataTable(sSQL, paramets, CommandType.Text); + + if (dt.Rows.Count > 0) + { + for (int i = 0; i < dt.Rows.Count; i++) + { + var row = dt.Rows[i]; + var rightId = Convert.ToInt32(row["RightID"]); + var rightName = Enum.GetName(typeof(Models.Rights), rightId); + + if (rightName != null) + { + rights.Add(rightName); + } + + } + } + + return rights; + } + } +} diff --git a/OpenImis.RestApi/Controllers/LoginController.cs b/OpenImis.RestApi/Controllers/LoginController.cs new file mode 100644 index 00000000..cfd799c1 --- /dev/null +++ b/OpenImis.RestApi/Controllers/LoginController.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; +using System.Linq; +using System.Security.Claims; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Cors; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Tokens; +using OpenImis.Modules; +using OpenImis.Modules.LoginModule.Models; + +namespace OpenImis.RestApi.Controllers +{ + [ApiController] + [EnableCors("AllowSpecificOrigin")] + public class LoginController : Controller + { + private readonly IConfiguration _configuration; + private readonly IImisModules _imisModules; + + public LoginController(IConfiguration configuration, IImisModules imisModules) + { + _configuration = configuration; + _imisModules = imisModules; + } + + [AllowAnonymous] + [HttpPost] + [Route("login")] + public IActionResult Index([FromBody]LoginModel model) + { + var user = _imisModules.GetLoginModule().GetLoginLogic().FindUser(model.UserName, model.Password); + + if (user != null) + { + DateTime expirationDate = DateTime.Now.AddDays(double.Parse(_configuration["JwtExpireDays"])); + + List claims = new List() + { + new Claim("UserId", user.UserID) + }; + + foreach (var right in user.Rights) + { + claims.Add(new Claim(ClaimTypes.Role, right)); + } + + var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(user.PrivateKey)); + var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); + + var token = new JwtSecurityToken( + issuer: _configuration["JwtIssuer"], + audience: _configuration["JwtIssuer"], + claims: claims, + expires: expirationDate, + signingCredentials: creds); + + return Ok(new + { + access_token = new JwtSecurityTokenHandler().WriteToken(token), + expires_on = expirationDate + }); + } + + return Unauthorized(); + } + } +} \ No newline at end of file From 4005fd6974b3a8cff87026508af7f176c728dabb Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 26 Jun 2019 14:24:25 +0200 Subject: [PATCH 07/86] OS-24: Added endpoint - Validate Credentials --- .../LoginModule/Models/UserLogin.cs | 16 +++++++++ .../Models/ValidateCredentialsResponse.cs | 12 +++++++ .../Controllers/LoginController.cs | 36 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 OpenImis.Modules/LoginModule/Models/UserLogin.cs create mode 100644 OpenImis.Modules/LoginModule/Models/ValidateCredentialsResponse.cs diff --git a/OpenImis.Modules/LoginModule/Models/UserLogin.cs b/OpenImis.Modules/LoginModule/Models/UserLogin.cs new file mode 100644 index 00000000..ac795f1f --- /dev/null +++ b/OpenImis.Modules/LoginModule/Models/UserLogin.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.LoginModule.Models +{ + public class UserLogin + { + [Required] + public string UserID { get; set; } + [Required] + [MaxLength(15)] + public string Password { get; set; } + } +} diff --git a/OpenImis.Modules/LoginModule/Models/ValidateCredentialsResponse.cs b/OpenImis.Modules/LoginModule/Models/ValidateCredentialsResponse.cs new file mode 100644 index 00000000..ceb2733a --- /dev/null +++ b/OpenImis.Modules/LoginModule/Models/ValidateCredentialsResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.LoginModule.Models +{ + public class ValidateCredentialsResponse + { + public bool ErrorOccured { get; set; } + public bool success { get; set; } + } +} diff --git a/OpenImis.RestApi/Controllers/LoginController.cs b/OpenImis.RestApi/Controllers/LoginController.cs index cfd799c1..6d9e8de5 100644 --- a/OpenImis.RestApi/Controllers/LoginController.cs +++ b/OpenImis.RestApi/Controllers/LoginController.cs @@ -69,5 +69,41 @@ public IActionResult Index([FromBody]LoginModel model) return Unauthorized(); } + + [AllowAnonymous] + [HttpPost] + [Route("api/Validate/Credentials")] + public virtual IActionResult Validate_Credentials([FromBody]UserLogin userlogin) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + ValidateCredentialsResponse response = new ValidateCredentialsResponse(); + + try + { + var user = _imisModules.GetLoginModule().GetLoginLogic().FindUser(userlogin.UserID, userlogin.Password); + + if (user != null) + { + response.success = true; + response.ErrorOccured = false; + } + else + { + throw new Exception(); + } + } + catch (Exception) + { + response.success = false; + response.ErrorOccured = true; + } + + return Json(response); + } } } \ No newline at end of file From 5a0a21e5cfbfd49082a4069a3fc3dd5b4fd9f2ff Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 27 Jun 2019 10:14:29 +0200 Subject: [PATCH 08/86] OS-22: The Insuree Module has been added --- OpenImis.DB.SqlServer/TblPremium.cs | 2 + OpenImis.DB.SqlServer/TblReporting.cs | 4 + OpenImis.Modules/IImisModules.cs | 17 +- OpenImis.Modules/ImisModules.cs | 16 +- .../Helpers/DeleteMamberFamilyResponse.cs | 49 +++ .../Helpers/EditFamilyResponse.cs | 99 +++++ .../Helpers/EditMemberFamilyResponse.cs | 96 +++++ .../Helpers/EnterContibutionResponse.cs | 82 ++++ .../Helpers/EnterFamilyResponse.cs | 120 ++++++ .../Helpers/EnterMemberFamilyResponse.cs | 112 ++++++ .../Helpers/EnterPolicyResponse.cs | 62 +++ .../Helpers/GetCommissionResponse.cs | 50 +++ .../Helpers/GetFamilyResponse.cs | 57 +++ .../Helpers/GetMemberFamilyResponse.cs | 62 +++ .../InsureeModule/Helpers/ImisApiResponse.cs | 49 +++ .../Helpers/Messages/Language.cs | 33 ++ .../Helpers/Messages/PrimaryLanguage.cs | 107 +++++ .../Helpers/Messages/SecondaryLanguage.cs | 88 +++++ .../Helpers/RenewPolicyResponse.cs | 62 +++ .../InsureeModule/IInsureeModule.cs | 14 + .../InsureeModule/InsureeModule.cs | 48 +++ .../InsureeModule/Logic/ContributionLogic.cs | 35 ++ .../InsureeModule/Logic/FamilyLogic.cs | 90 +++++ .../InsureeModule/Logic/IContributionLogic.cs | 13 + .../InsureeModule/Logic/IFamilyLogic.cs | 19 + .../InsureeModule/Logic/IPolicyLogic.cs | 15 + .../InsureeModule/Logic/PolicyLogic.cs | 53 +++ .../InsureeModule/Models/CommissionMode.cs | 12 + .../InsureeModule/Models/Contribution.cs | 32 ++ .../InsureeModule/Models/DataMessage.cs | 14 + .../InsureeModule/Models/EditFamilyMember.cs | 34 ++ .../InsureeModule/Models/EditFamilyModel.cs | 37 ++ .../InsureeModule/Models/Family.cs | 29 ++ .../InsureeModule/Models/FamilyMember.cs | 40 ++ .../InsureeModule/Models/FamilyModel.cs | 11 + .../InsureeModule/Models/FamilyModelv2.cs | 11 + .../InsureeModule/Models/FamilyModelv3.cs | 52 +++ .../Models/GetCommissionInputs.cs | 21 + .../InsureeModule/Models/Policy.cs | 21 + .../InsureeModule/Models/ReactionType.cs | 12 + .../Repositories/ContributionRepository.cs | 52 +++ .../Repositories/FamilyRepository.cs | 371 ++++++++++++++++++ .../Repositories/IContributionRepository.cs | 13 + .../Repositories/IFamilyRepository.cs | 19 + .../Repositories/IPolicyRepository.cs | 15 + .../Repositories/PolicyRepository.cs | 136 +++++++ .../Controllers/ContributionController.cs | 46 +++ .../Controllers/FamilyController.cs | 208 ++++++++++ .../Controllers/PolicyController.cs | 105 +++++ 49 files changed, 2736 insertions(+), 9 deletions(-) create mode 100644 OpenImis.Modules/InsureeModule/Helpers/DeleteMamberFamilyResponse.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/EditFamilyResponse.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/EditMemberFamilyResponse.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/EnterContibutionResponse.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/EnterFamilyResponse.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/EnterMemberFamilyResponse.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/EnterPolicyResponse.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/GetCommissionResponse.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/GetFamilyResponse.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/GetMemberFamilyResponse.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/ImisApiResponse.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/Messages/Language.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/Messages/PrimaryLanguage.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/Messages/SecondaryLanguage.cs create mode 100644 OpenImis.Modules/InsureeModule/Helpers/RenewPolicyResponse.cs create mode 100644 OpenImis.Modules/InsureeModule/IInsureeModule.cs create mode 100644 OpenImis.Modules/InsureeModule/InsureeModule.cs create mode 100644 OpenImis.Modules/InsureeModule/Logic/ContributionLogic.cs create mode 100644 OpenImis.Modules/InsureeModule/Logic/FamilyLogic.cs create mode 100644 OpenImis.Modules/InsureeModule/Logic/IContributionLogic.cs create mode 100644 OpenImis.Modules/InsureeModule/Logic/IFamilyLogic.cs create mode 100644 OpenImis.Modules/InsureeModule/Logic/IPolicyLogic.cs create mode 100644 OpenImis.Modules/InsureeModule/Logic/PolicyLogic.cs create mode 100644 OpenImis.Modules/InsureeModule/Models/CommissionMode.cs create mode 100644 OpenImis.Modules/InsureeModule/Models/Contribution.cs create mode 100644 OpenImis.Modules/InsureeModule/Models/DataMessage.cs create mode 100644 OpenImis.Modules/InsureeModule/Models/EditFamilyMember.cs create mode 100644 OpenImis.Modules/InsureeModule/Models/EditFamilyModel.cs create mode 100644 OpenImis.Modules/InsureeModule/Models/Family.cs create mode 100644 OpenImis.Modules/InsureeModule/Models/FamilyMember.cs create mode 100644 OpenImis.Modules/InsureeModule/Models/FamilyModel.cs create mode 100644 OpenImis.Modules/InsureeModule/Models/FamilyModelv2.cs create mode 100644 OpenImis.Modules/InsureeModule/Models/FamilyModelv3.cs create mode 100644 OpenImis.Modules/InsureeModule/Models/GetCommissionInputs.cs create mode 100644 OpenImis.Modules/InsureeModule/Models/Policy.cs create mode 100644 OpenImis.Modules/InsureeModule/Models/ReactionType.cs create mode 100644 OpenImis.Modules/InsureeModule/Repositories/ContributionRepository.cs create mode 100644 OpenImis.Modules/InsureeModule/Repositories/FamilyRepository.cs create mode 100644 OpenImis.Modules/InsureeModule/Repositories/IContributionRepository.cs create mode 100644 OpenImis.Modules/InsureeModule/Repositories/IFamilyRepository.cs create mode 100644 OpenImis.Modules/InsureeModule/Repositories/IPolicyRepository.cs create mode 100644 OpenImis.Modules/InsureeModule/Repositories/PolicyRepository.cs create mode 100644 OpenImis.RestApi/Controllers/ContributionController.cs create mode 100644 OpenImis.RestApi/Controllers/FamilyController.cs create mode 100644 OpenImis.RestApi/Controllers/PolicyController.cs diff --git a/OpenImis.DB.SqlServer/TblPremium.cs b/OpenImis.DB.SqlServer/TblPremium.cs index a27a36b3..b20e194e 100644 --- a/OpenImis.DB.SqlServer/TblPremium.cs +++ b/OpenImis.DB.SqlServer/TblPremium.cs @@ -20,6 +20,8 @@ public partial class TblPremium public bool? IsPhotoFee { get; set; } public bool? IsOffline { get; set; } public int? ReportingId { get; set; } + public int? ReportingCommissionID { get; set; } + public int? ReportingCommisionID { get; set; } public TblPayer Payer { get; set; } public TblPolicy Policy { get; set; } diff --git a/OpenImis.DB.SqlServer/TblReporting.cs b/OpenImis.DB.SqlServer/TblReporting.cs index 63c0d101..28eef483 100644 --- a/OpenImis.DB.SqlServer/TblReporting.cs +++ b/OpenImis.DB.SqlServer/TblReporting.cs @@ -13,5 +13,9 @@ public partial class TblReporting public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } public int RecordFound { get; set; } + public int? OfficerID { get; set; } + public int? ReportType { get; set; } + public decimal? CammissionRate { get; set; } + public decimal? CommissionRate { get; set; } } } diff --git a/OpenImis.Modules/IImisModules.cs b/OpenImis.Modules/IImisModules.cs index 32ae87b1..ad06d50d 100644 --- a/OpenImis.Modules/IImisModules.cs +++ b/OpenImis.Modules/IImisModules.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using OpenImis.Modules.MasterDataManagementModule; +using OpenImis.Modules.InsureeModule; namespace OpenImis.Modules { @@ -13,13 +14,15 @@ namespace OpenImis.Modules /// public interface IImisModules { - /// - /// Creates and returns the user management module. - /// - /// - /// The User module. - /// - IUserModule GetUserModule(); + IInsureeModule GetInsureeModule(); + + /// + /// Creates and returns the user management module. + /// + /// + /// The User module. + /// + IUserModule GetUserModule(); IInsureeManagementModule GetInsureeManagementModule(); diff --git a/OpenImis.Modules/ImisModules.cs b/OpenImis.Modules/ImisModules.cs index 820427c4..ee836be6 100644 --- a/OpenImis.Modules/ImisModules.cs +++ b/OpenImis.Modules/ImisModules.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Configuration; using OpenImis.Modules.MasterDataManagementModule; using OpenImis.Modules.MasterDataManagementModule.Logic; +using OpenImis.Modules.InsureeModule; namespace OpenImis.Modules { @@ -36,7 +37,9 @@ public class ImisModules: IImisModules private IInsureeManagementModule insureeManagementModule; private IMasterDataManagementModule masterDataManagementModule; - private readonly IConfiguration _configuration; + private IInsureeModule insureeModule; + + private readonly IConfiguration _configuration; private readonly ILogger logger; public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory) @@ -45,7 +48,16 @@ public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory) logger = loggerFactory.CreateLogger("LoggerCategory"); } - /// + public IInsureeModule GetInsureeModule() + { + if (insureeModule == null) + { + insureeModule = new InsureeModule.InsureeModule(_configuration); + } + return insureeModule; + } + + /// /// Creates and returns the user management module. /// /// diff --git a/OpenImis.Modules/InsureeModule/Helpers/DeleteMamberFamilyResponse.cs b/OpenImis.Modules/InsureeModule/Helpers/DeleteMamberFamilyResponse.cs new file mode 100644 index 00000000..759af700 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/DeleteMamberFamilyResponse.cs @@ -0,0 +1,49 @@ +using OpenImis.Modules.InsureeModule.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers +{ + public class DeleteMamberFamilyResponse : ImisApiResponse + { + public DeleteMamberFamilyResponse(Exception e) : base(e) { } + + public DeleteMamberFamilyResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + public DeleteMamberFamilyResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongFormatMissingIN"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "INNotFount"); + Message = msg; + break; + case 3: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "MemberNotHead"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/EditFamilyResponse.cs b/OpenImis.Modules/InsureeModule/Helpers/EditFamilyResponse.cs new file mode 100644 index 00000000..3c853689 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/EditFamilyResponse.cs @@ -0,0 +1,99 @@ +using OpenImis.Modules.InsureeModule.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers +{ + public class EditFamilyResponse : ImisApiResponse + { + public EditFamilyResponse(Exception e) : base(e) + { + + } + public EditFamilyResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + + } + + public EditFamilyResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingHeadIN"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "HeadINNotFound"); + Message = msg; + break; + case 3: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongPVillageCode"); + Message = msg; + break; + case 4: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongCVillageCode"); + Message = msg; + break; + case 5: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongGender"); + Message = msg; + break; + case 6: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongConfirmationType"); + Message = msg; + break; + case 7: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongGroupType"); + Message = msg; + break; + case 8: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongMaritalStatus"); + Message = msg; + break; + case 9: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongEducation"); + Message = msg; + break; + case 10: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongProfession"); + Message = msg; + break; + case 11: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "FSPCodeNotFound"); + Message = msg; + break; + case 12: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongIdentificationType"); + Message = msg; + break; + } + } + + + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/EditMemberFamilyResponse.cs b/OpenImis.Modules/InsureeModule/Helpers/EditMemberFamilyResponse.cs new file mode 100644 index 00000000..6d650e14 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/EditMemberFamilyResponse.cs @@ -0,0 +1,96 @@ +using OpenImis.Modules.InsureeModule.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers +{ + public class EditMemberFamilyResponse : ImisApiResponse + { + public EditMemberFamilyResponse(Exception e) : base(e) + { + + } + public EditMemberFamilyResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + public EditMemberFamilyResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingHeadIN"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "HeadINNotFound"); + Message = msg; + break; + case 3: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongINMember"); + Message = msg; + break; + case 4: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "NotFountINMember"); + Message = msg; + break; + case 5: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongVillageCode"); + Message = msg; + break; + case 6: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongGender"); + Message = msg; + break; + case 7: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongMaritalStatus"); + Message = msg; + break; + case 8: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongEducation"); + Message = msg; + break; + case 9: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongProfession"); + Message = msg; + break; + case 10: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "FSPCodeNotFound"); + Message = msg; + break; + case 11: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongIdentificationType"); + Message = msg; + break; + case 12: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongRelationship"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/EnterContibutionResponse.cs b/OpenImis.Modules/InsureeModule/Helpers/EnterContibutionResponse.cs new file mode 100644 index 00000000..c6728e60 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/EnterContibutionResponse.cs @@ -0,0 +1,82 @@ +using OpenImis.Modules.InsureeModule.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers +{ + public class EnterContibutionResponse : ImisApiResponse + { + public EnterContibutionResponse(Exception e) : base(e) + { + + } + + public EnterContibutionResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + public EnterContibutionResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingHeadIN"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "INNotFount"); + Message = msg; + break; + case 3: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingPC"); + Message = msg; + break; + case 4: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingPayDate"); + Message = msg; + break; + case 5: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongContributionCat"); + Message = msg; + break; + case 6: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingPayType"); + Message = msg; + break; + case 7: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingPayer"); + Message = msg; + break; + case 8: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "MissingReceiptNumber"); + Message = msg; + break; + case 9: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "DuplicateReceiptNumber"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/EnterFamilyResponse.cs b/OpenImis.Modules/InsureeModule/Helpers/EnterFamilyResponse.cs new file mode 100644 index 00000000..cf1654a1 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/EnterFamilyResponse.cs @@ -0,0 +1,120 @@ +using OpenImis.Modules.InsureeModule.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers +{ + public class EnterFamilyResponse : ImisApiResponse + { + public EnterFamilyResponse(Exception e) : base(e) + { + } + + public EnterFamilyResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + + public EnterFamilyResponse(int value, bool error, object data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingHeadIN"); + Message = msg; + break; + case 2: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "DuplicateINHead"); + Message = msg; + break; + case 3: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingPVC"); + Message = msg; + break; + case 4: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongCVillageCode"); + Message = msg; + break; + case 5: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingGender"); + Message = msg; + break; + case 6: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongFrOrMissingBd"); + Message = msg; + break; + case 7: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "MissingLastName"); + Message = msg; + break; + case 8: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "MissingOtherName"); + Message = msg; + break; + case 9: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongConfirmationType"); + Message = msg; + break; + case 10: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongGroupType"); + Message = msg; + break; + case 11: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongMaritalStatus"); + Message = msg; + break; + case 12: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongEducation"); + Message = msg; + break; + case 13: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongProfession"); + Message = msg; + break; + case 14: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "FSPCodeNotFound"); + Message = msg; + break; + case 15: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongIdentificationType"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/EnterMemberFamilyResponse.cs b/OpenImis.Modules/InsureeModule/Helpers/EnterMemberFamilyResponse.cs new file mode 100644 index 00000000..bfbb6fdc --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/EnterMemberFamilyResponse.cs @@ -0,0 +1,112 @@ +using OpenImis.Modules.InsureeModule.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers +{ + public class EnterMemberFamilyResponse : ImisApiResponse + { + public EnterMemberFamilyResponse(Exception e) : base(e) + { + + } + public EnterMemberFamilyResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + public EnterMemberFamilyResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingHeadIN"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "HeadINNotFound"); + Message = msg; + break; + case 3: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongINMember"); + Message = msg; + break; + case 4: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingGender"); + Message = msg; + break; + case 5: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongFrOrMissingBd"); + Message = msg; + break; + case 6: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "MissingLastName"); + Message = msg; + break; + case 7: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "MissingOtherName"); + Message = msg; + break; + case 8: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "DuplicatedMemberIN"); + Message = msg; + break; + case 9: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongVillageCode"); + Message = msg; + break; + case 10: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongMaritalStatus"); + Message = msg; + break; + case 11: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongEducation"); + Message = msg; + break; + case 12: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongProfession"); + Message = msg; + break; + case 13: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "FSPCodeNotFound"); + Message = msg; + break; + case 14: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongRelationship"); + Message = msg; + break; + case 15: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongIdentificationType"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/EnterPolicyResponse.cs b/OpenImis.Modules/InsureeModule/Helpers/EnterPolicyResponse.cs new file mode 100644 index 00000000..c598aa75 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/EnterPolicyResponse.cs @@ -0,0 +1,62 @@ +using OpenImis.Modules.InsureeModule.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers +{ + public class EnterPolicyResponse : ImisApiResponse + { + public EnterPolicyResponse(Exception e) : base(e) + { + + } + + public EnterPolicyResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + public EnterPolicyResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongINMember"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "NotFountINMember"); + Message = msg; + break; + case 3: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingPC"); + Message = msg; + break; + case 4: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingEnrolDate"); + Message = msg; + break; + case 5: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingEOcode"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/GetCommissionResponse.cs b/OpenImis.Modules/InsureeModule/Helpers/GetCommissionResponse.cs new file mode 100644 index 00000000..2e1a397d --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/GetCommissionResponse.cs @@ -0,0 +1,50 @@ +using OpenImis.Modules.InsureeModule.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers +{ + public class GetCommissionResponse : ImisApiResponse + { + public GetCommissionResponse(Exception error) : base(error) + { + + } + public GetCommissionResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + + public GetCommissionResponse(int value, bool error, object data, int lang) : base(value, error, data, lang) + { + msg.Data = data; + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingHeadIN"); + Message = msg; + break; + case 2: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "HeadINNotFound"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/GetFamilyResponse.cs b/OpenImis.Modules/InsureeModule/Helpers/GetFamilyResponse.cs new file mode 100644 index 00000000..35fdfed7 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/GetFamilyResponse.cs @@ -0,0 +1,57 @@ +using Newtonsoft.Json; +using OpenImis.Modules.InsureeModule.Helpers.Messages; +using OpenImis.Modules.InsureeModule.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers +{ + public class GetFamilyResponse : ImisApiResponse + { + public GetFamilyResponse(Exception error) : base(error) + { + } + + public GetFamilyResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + + public GetFamilyResponse(int value, bool error, List data, int lang) : base(value, error, data, lang) + { + if (data.Count > 0) + { + var jsonString = JsonConvert.SerializeObject(data); + var ObjectList = JsonConvert.DeserializeObject>(jsonString); + msg.Data = ObjectList.FirstOrDefault(); + } + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingHeadIN"); + Message = msg; + break; + case 2: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "HeadINNotFound"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/GetMemberFamilyResponse.cs b/OpenImis.Modules/InsureeModule/Helpers/GetMemberFamilyResponse.cs new file mode 100644 index 00000000..3e581d0a --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/GetMemberFamilyResponse.cs @@ -0,0 +1,62 @@ +using Newtonsoft.Json; +using OpenImis.Modules.InsureeModule.Helpers.Messages; +using OpenImis.Modules.InsureeModule.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers +{ + public class GetMemberFamilyResponse : ImisApiResponse + { + public GetMemberFamilyResponse(Exception e) : base(e) + { + + } + public GetMemberFamilyResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + public GetMemberFamilyResponse(int value, bool error, List data, int lang) : base(value, error, data, lang) + { + if (data.Count > 0) + { + var jsonString = JsonConvert.SerializeObject(data); + var ObjectList = JsonConvert.DeserializeObject>(jsonString); + msg.Data = ObjectList.FirstOrDefault(); + } + + SetMessage(value); + + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingHeadIN"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "HeadINNotFound"); + Message = msg; + break; + case 3: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "NoMemberOfOrder"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/ImisApiResponse.cs b/OpenImis.Modules/InsureeModule/Helpers/ImisApiResponse.cs new file mode 100644 index 00000000..ac063faa --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/ImisApiResponse.cs @@ -0,0 +1,49 @@ +using Newtonsoft.Json; +using OpenImis.Modules.InsureeModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers +{ + public class ImisApiResponse + { + public DataMessage msg = new DataMessage(); + public int language { get; set; } + + public ImisApiResponse(Exception e) + { + msg.Code = -1; + msg.ErrorOccured = true; + msg.MessageValue = e.Message; + Message = msg; + } + + public ImisApiResponse(int value, bool error, int lang) + { + if (value != 0) + error = true; + + language = lang; + + msg.Code = value; + msg.ErrorOccured = error; + Message = msg; + } + + public ImisApiResponse(int value, bool error, object data, int lang) + { + if (value != 0) + error = true; + + language = lang; + + msg.Code = value; + msg.ErrorOccured = error; + msg.Data = JsonConvert.SerializeObject(data); + Message = msg; + } + + public DataMessage Message { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/Messages/Language.cs b/OpenImis.Modules/InsureeModule/Helpers/Messages/Language.cs new file mode 100644 index 00000000..788cf00e --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/Messages/Language.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers.Messages +{ + public class Language + { + public string GetMessage(int language, string name) + { + FieldInfo fieldInfos; + + switch (language) + { + + case 0: + fieldInfos = typeof(PrimaryLanguage).GetField(name); + break; + case 1: + fieldInfos = typeof(SecondaryLanguage).GetField(name); + + break; + default: + fieldInfos = typeof(PrimaryLanguage).GetField(name); + + break; + } + var val = (string)fieldInfos.GetValue(null); + return val; + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/Messages/PrimaryLanguage.cs b/OpenImis.Modules/InsureeModule/Helpers/Messages/PrimaryLanguage.cs new file mode 100644 index 00000000..77669c0b --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/Messages/PrimaryLanguage.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers.Messages +{ + public static class PrimaryLanguage + { + public static string Success = "Success"; + + //CtrlNumberResponse + public static string CantAssignCN = "1-Control number cannot be assigned by the external payment gateway"; + public static string DuplicateCN = "2-Duplicate Control Number"; + + //DeleteMemberFamilyResponse + public static string WrongFormatMissingIN = "Wrong Format or Missing Insurance Number of Member"; + public static string INNotFount = "Insurance number of member not found"; + public static string MemberNotHead = "Mamber is head of family"; + + //EditFamilyResponse + public static string WrongOrMissingHeadIN = "Wrong Format or Missing Insurance Number of head."; + public static string HeadINNotFound = "Insurance Number of head not found."; + public static string WrongPVillageCode = "Wrong permanent village code."; + public static string WrongCVillageCode = "Wrong current village Code."; + public static string WrongGender = "Wrong gender."; + public static string WrongConfirmationType = "Wrong confirmation type"; + public static string WrongGroupType = "Wrong group type"; + public static string WrongMaritalStatus = "Wrong marital status"; + public static string WrongEducation = "Wrong education"; + public static string WrongProfession = "Wrong profession."; + public static string FSPCodeNotFound = "FSP code not found"; + public static string WrongIdentificationType = "Wrong Identification Type"; + + //EditMemberFamilyResponse + public static string WrongINMember = "Wrong format of insurance number of member"; + public static string NotFountINMember = "Insurance number of member not found"; + public static string WrongVillageCode = "Wrong current village code"; + public static string WrongRelationship = "Wrong Relationship"; + + //EnterContributionResponse + public static string WrongOrMissingPC = "Wrong or missing product code (not existing or not applicable to the family/group)"; + public static string WrongOrMissingPayDate = "Wrong or missing payment date"; + public static string WrongContributionCat = "Wrong contribution category"; + public static string WrongOrMissingPayType = "Wrong or missing payment type"; + public static string WrongOrMissingPayer = "Wrong or missing payer"; + public static string MissingReceiptNumber = "Missing receipt no."; + public static string DuplicateReceiptNumber = "Duplicated receipt no."; + + //EnterFamilyResponse + public static string DuplicateINHead = "Duplicated Insurance Number of head."; + public static string WrongOrMissingPVC = "Wrong or missing permanent village code."; + public static string WrongOrMissingGender = "Wrong or missing gender."; + public static string WrongFrOrMissingBd = "Wrong format or missing birth date."; + public static string MissingLastName = "Missing last name."; + public static string MissingOtherName = "Missing other name"; + + //EnterMemberFamilyResponse + public static string DuplicatedMemberIN = "Insurance number of member duplicated "; + + //EnterPolicyResponse + public static string WrongOrMissingEnrolDate = "Wrong or missing enrolment date"; + public static string WrongOrMissingEOcode = "Wrong or missing enrolment officer code (not existing or not applicable to the family/group)"; + + //GetCoverageResponse + + //GetFamilyResponse + + //GetMemberFamilyResponse + public static string NoMemberOfOrder = "No member of the specified order number in the family/group"; + + //MatchPayResponse + public static string PayIdDoesntExist = "1-The paymentId does not exist"; + + //RenewPolicyResponse + public static string WrongOrMissingRenDate = "Wrong or missing renewal date"; + + //RequestedCNResponse + public static string WrongInternalIdFormat = "1-Wrong format of internal identifier"; + public static string InvalidInternalId = "2-Not valid internal identifier "; + + //SaveAckResponse + public static string CantPostReq = "1-Request for control number cannot be posted in the external payment gateway"; + + //SaveIntentResponse + public static string WrongFormatInsureeNo = "1-Wrong format of insurance number"; + public static string InValidINmissingPC = "2-Not valid insurance or missing product code"; + public static string InValidEOC = "3-Not valid enrolment officer code"; + public static string IncompatibleEO_PC = "4-Enrolment officer code and insurance product code are not compatible"; + public static string NoRenewalProduct = "5-Beneficiary has no policy of specified insurance product for renewal"; + public static string InsureeNoMissing = "6-Missing insurance number"; + public static string InsureeNotEnrolled = "7-Insuree not enrolled while prior enrolment mandatory."; + public static string DuplicateCNAssigned = "8-Duplicated control number assigned"; + public static string CantAssignCn2 = "9-Control number cannot be assigned"; + public static string UnknownPaymentType = "10-Uknown type of payment"; + + //SavePayResponse + public static string WrongOrMissingRecDate = "1-Wrong or missing receiving date"; + public static string WrongFormatInputData = "2-Wrong format of input data"; + public static string WrongControlNumber = "3-Wrong control_number"; + public static string WrongAmount = "4-Wrong Amount"; + public static string DuplicatePayAmount = "5-Duplicate Payment Amount"; + public static string DoesntExistEO = "6-Enrolment Officer Code does not exist"; + public static string DoesntExistPC = "7-Product Code Does not Exist"; + public static string NoPolicyForRenewal = "8-Beneficiary has no policy of specified insurance product for renewal"; + public static string UnknownTypeOfPay = "9-Uknown type of payment"; + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/Messages/SecondaryLanguage.cs b/OpenImis.Modules/InsureeModule/Helpers/Messages/SecondaryLanguage.cs new file mode 100644 index 00000000..5600c788 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/Messages/SecondaryLanguage.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers.Messages +{ + public static class SecondaryLanguage + { + public static string Success = "Imefanikiwa"; + + public static string CantAssignCN = "1-Na. ya ankara imeshindikana kutotelewa na mfumo wa malipo"; + public static string DuplicateCN = "2-Na. ya ankara imejirudia"; + + public static string WrongFormatMissingIN = "Umekosea namba ya mwanachama au namba haipo"; + public static string INNotFount = "Namba ya mwanachama haipo"; + public static string MemberNotHead = "Mwanachama ni mkuu wa kaya"; + + public static string WrongOrMissingHeadIN = "Umekosea namba ya mkuu wa kaya au namba haipo"; + public static string HeadINNotFound = "Namba ya mkuu wa kaya haipo"; + public static string WrongPVillageCode = "Umekosea namba ya kijiji"; + public static string WrongCVillageCode = "Umekosea namba ya kijiji"; + public static string WrongGender = "Umekosea jinsia"; + public static string WrongConfirmationType = "Wrong confirmation type"; + public static string WrongGroupType = "Umekosea aina ya kundi"; + public static string WrongMaritalStatus = "Umekosea hali ya ndoa"; + public static string WrongEducation = "Umekosea elimu"; + public static string WrongProfession = "Umekosea elimu"; + public static string FSPCodeNotFound = "Na. ya FSP haipo"; + public static string WrongIdentificationType = "Umekosea aina ya kitambulisho"; + + public static string WrongINMember = "Umekosea namba ya mwanachama"; + public static string NotFountINMember = "Namba ya mwanachama haipo kwenye kompuyta kuu"; + public static string WrongVillageCode = "Umekosea namba ya kijiji"; + public static string WrongRelationship = "Umekosea uhusiano"; + + public static string WrongOrMissingPC = "Umekosea namba ya bidhaa au haitumiki kwenye familia husika"; + public static string WrongOrMissingPayDate = "Umekosea tarehe ya malipo"; + public static string WrongContributionCat = "Umekosea kundi la malipo"; + public static string WrongOrMissingPayType = "Umekosea aina ya malipo"; + public static string WrongOrMissingPayer = "Umekosea mlipaji"; + public static string MissingReceiptNumber = "Jaza namba ya risiti"; + public static string DuplicateReceiptNumber = "Namba ya risiti imejirudia"; + + public static string DuplicateINHead = "Namba ya mwachama imejirudia"; + public static string WrongOrMissingPVC = "Umekosea/Jaza namba ya kijiji"; + public static string WrongOrMissingGender = "Umekosea/Jaza Jinsia"; + public static string WrongFrOrMissingBd = "Jaza/Umekosea tarehe"; + public static string MissingLastName = "Jaza jina la ukoo"; + public static string MissingOtherName = "Jaza majina mengine"; + + public static string DuplicatedMemberIN = "Namba ya mwanachama imejirudia"; + + public static string WrongOrMissingEnrolDate = "Jaza/Umekosea tarehe ya kujiunga"; + public static string WrongOrMissingEOcode = "Jaza/Umekosea namba ya msimbo ya afisa mwandikishaji"; + + public static string NoMemberOfOrder = "Na ya mwanchama kwenye familia haipo"; + public static string PayIdDoesntExist = "1-Namba ya malipo haipo"; + + public static string WrongOrMissingRenDate = "Jaza/Umekosea tarehe ya kuhuisha"; + + public static string WrongInternalIdFormat = "1-Wrong format of internal identifier"; + public static string InvalidInternalId = "2-Not valid internal identifier "; + + public static string CantPostReq = "1-Maombi ya Na. ya ankara yameshindikana, jaribu tena"; + + public static string WrongFormatInsureeNo = "1-Namba ya mwanachama imekosewa"; + public static string InValidINmissingPC = "2-Umekosea namba ya mwanachama au namba ya bidhaa"; + public static string InValidEOC = "3-Umekosea namba ya msimbo ya afisa mwandikishaji"; + public static string IncompatibleEO_PC = "4-Namba ya mwanachama na namba ya bidhaa haviendani"; + public static string NoRenewalProduct = "5-Mwanachama hajajiunga na bidhaa husika"; + + public static string InsureeNoMissing = "6-Jaza namba ya mwanachama"; + public static string InsureeNotEnrolled = "7-Insuree not enrolled while prior enrolment mandatory."; + public static string DuplicateCNAssigned = "8-Umepatiwa namba ya ankara iliyojirudia, jaribu tena"; + public static string CantAssignCn2 = "9-Na. ya ankara imeshishindikana kutolewa, jaribu tena"; + public static string UnknownPaymentType = "10-Aina ya malipo uliyochagua hayapo"; + + public static string WrongOrMissingRecDate = "1-Umekosea tarehe ya kupokea"; + public static string WrongFormatInputData = "2-Umekosea taarifa uliyojaza"; + public static string WrongControlNumber = "3-Umekosea Na. ya ankara"; + public static string WrongAmount = "4-Umekosea kiasi"; + public static string DuplicatePayAmount = "5-Umerudia malipo"; + public static string DoesntExistEO = "6-Namba ya msimbo ya afisa mwandikishaji haipo"; + public static string DoesntExistPC = "7-Namba ya bidhaa haipo"; + public static string NoPolicyForRenewal = "8-Mwanachama hajajiunga na bidhaa husika"; + public static string UnknownTypeOfPay = "9-Aina ya malipo uliyochagua haipo"; + } +} diff --git a/OpenImis.Modules/InsureeModule/Helpers/RenewPolicyResponse.cs b/OpenImis.Modules/InsureeModule/Helpers/RenewPolicyResponse.cs new file mode 100644 index 00000000..27ec3fb8 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Helpers/RenewPolicyResponse.cs @@ -0,0 +1,62 @@ +using OpenImis.Modules.InsureeModule.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Helpers +{ + public class RenewPolicyResponse : ImisApiResponse + { + public RenewPolicyResponse(Exception e) : base(e) + { + + } + public RenewPolicyResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + public RenewPolicyResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongINMember"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "NotFountINMember"); + Message = msg; + break; + case 3: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingPC"); + Message = msg; + break; + case 4: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingRenDate"); + Message = msg; + break; + case 5: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingEOcode"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/InsureeModule/IInsureeModule.cs b/OpenImis.Modules/InsureeModule/IInsureeModule.cs new file mode 100644 index 00000000..651fcae4 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/IInsureeModule.cs @@ -0,0 +1,14 @@ +using OpenImis.Modules.InsureeModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule +{ + public interface IInsureeModule + { + IFamilyLogic GetFamilyLogic(); + IContributionLogic GetContributionLogic(); + IPolicyLogic GetPolicyLogic(); + } +} diff --git a/OpenImis.Modules/InsureeModule/InsureeModule.cs b/OpenImis.Modules/InsureeModule/InsureeModule.cs new file mode 100644 index 00000000..ed09b9c6 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/InsureeModule.cs @@ -0,0 +1,48 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.Modules.InsureeModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule +{ + public class InsureeModule : IInsureeModule + { + private IConfiguration Configuration; + private IFamilyLogic _familyLogic; + private IContributionLogic _contributionLogic; + private IPolicyLogic _policyLogic; + + public InsureeModule(IConfiguration configuration) + { + Configuration = configuration; + } + + public IFamilyLogic GetFamilyLogic() + { + if (_familyLogic == null) + { + _familyLogic = new FamilyLogic(Configuration); + } + return _familyLogic; + } + + public IContributionLogic GetContributionLogic() + { + if (_contributionLogic == null) + { + _contributionLogic = new ContributionLogic(Configuration); + } + return _contributionLogic; + } + + public IPolicyLogic GetPolicyLogic() + { + if (_policyLogic == null) + { + _policyLogic = new PolicyLogic(Configuration); + } + return _policyLogic; + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Logic/ContributionLogic.cs b/OpenImis.Modules/InsureeModule/Logic/ContributionLogic.cs new file mode 100644 index 00000000..0a029c55 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Logic/ContributionLogic.cs @@ -0,0 +1,35 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.Modules.InsureeModule.Models; +using OpenImis.Modules.InsureeModule.Repositories; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Logic +{ + public class ContributionLogic : IContributionLogic + { + private IConfiguration Configuration; + protected IContributionRepository contributionRepository; + + public ContributionLogic(IConfiguration configuration) + { + Configuration = configuration; + contributionRepository = new ContributionRepository(Configuration); + } + + public void SetUserId(int userId) + { + contributionRepository.UserId = userId; + } + + public DataMessage Enter(Contribution model) + { + DataMessage message; + + message = contributionRepository.Enter(model); + + return message; + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Logic/FamilyLogic.cs b/OpenImis.Modules/InsureeModule/Logic/FamilyLogic.cs new file mode 100644 index 00000000..62297819 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Logic/FamilyLogic.cs @@ -0,0 +1,90 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.Modules.InsureeModule.Models; +using OpenImis.Modules.InsureeModule.Repositories; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Logic +{ + public class FamilyLogic : IFamilyLogic + { + private IConfiguration Configuration; + protected IFamilyRepository familyRepository; + + public FamilyLogic(IConfiguration configuration) + { + Configuration = configuration; + familyRepository = new FamilyRepository(Configuration); + } + + public void SetUserId(int userId) + { + familyRepository.UserId = userId; + } + + public List Get(string insureeNumber) + { + List response; + + response = familyRepository.Get(insureeNumber); + + return response; + } + + public List GetMember(string insureeNumber, int order) + { + List response; + + response = familyRepository.GetMember(insureeNumber, order); + + return response; + } + + public DataMessage AddNew(FamilyModelv3 model) + { + DataMessage message; + + message = familyRepository.AddNew(model); + + return message; + } + + public DataMessage Edit(EditFamily model) + { + DataMessage message; + + message = familyRepository.Edit(model); + + return message; + } + + public DataMessage AddMember(FamilyMember model) + { + DataMessage message; + + message = familyRepository.AddMember(model); + + return message; + } + + public DataMessage EditMember(EditFamilyMember model) + { + DataMessage message; + + message = familyRepository.EditMember(model); + + return message; + } + + public DataMessage DeleteMember(string insureeNumber) + { + DataMessage message; + + message = familyRepository.DeleteMember(insureeNumber); + + return message; + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Logic/IContributionLogic.cs b/OpenImis.Modules/InsureeModule/Logic/IContributionLogic.cs new file mode 100644 index 00000000..15c60549 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Logic/IContributionLogic.cs @@ -0,0 +1,13 @@ +using OpenImis.Modules.InsureeModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Logic +{ + public interface IContributionLogic + { + DataMessage Enter(Contribution model); + void SetUserId(int userId); + } +} diff --git a/OpenImis.Modules/InsureeModule/Logic/IFamilyLogic.cs b/OpenImis.Modules/InsureeModule/Logic/IFamilyLogic.cs new file mode 100644 index 00000000..e93cb81b --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Logic/IFamilyLogic.cs @@ -0,0 +1,19 @@ +using OpenImis.Modules.InsureeModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Logic +{ + public interface IFamilyLogic + { + List Get(string insureeNumber); + List GetMember(string insureeNumber, int order); + DataMessage AddNew(FamilyModelv3 model); + void SetUserId(int userId); + DataMessage Edit(EditFamily model); + DataMessage AddMember(FamilyMember model); + DataMessage EditMember(EditFamilyMember model); + DataMessage DeleteMember(string insureeNumber); + } +} diff --git a/OpenImis.Modules/InsureeModule/Logic/IPolicyLogic.cs b/OpenImis.Modules/InsureeModule/Logic/IPolicyLogic.cs new file mode 100644 index 00000000..183ec25a --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Logic/IPolicyLogic.cs @@ -0,0 +1,15 @@ +using OpenImis.Modules.InsureeModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Logic +{ + public interface IPolicyLogic + { + void SetUserId(int userId); + DataMessage Enter(Policy model); + DataMessage Renew(Policy model); + DataMessage GetCommissions(GetCommissionInputs model); + } +} diff --git a/OpenImis.Modules/InsureeModule/Logic/PolicyLogic.cs b/OpenImis.Modules/InsureeModule/Logic/PolicyLogic.cs new file mode 100644 index 00000000..7bfe6421 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Logic/PolicyLogic.cs @@ -0,0 +1,53 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.Modules.InsureeModule.Models; +using OpenImis.Modules.InsureeModule.Repositories; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Logic +{ + public class PolicyLogic : IPolicyLogic + { + private IConfiguration Configuration; + protected IPolicyRepository policyRepository; + + public PolicyLogic(IConfiguration configuration) + { + Configuration = configuration; + policyRepository = new PolicyRepository(Configuration); + } + + public void SetUserId(int userId) + { + policyRepository.UserId = userId; + } + + public DataMessage Enter(Policy model) + { + DataMessage message; + + message = policyRepository.Enter(model); + + return message; + } + + public DataMessage Renew(Policy model) + { + DataMessage message; + + message = policyRepository.Renew(model); + + return message; + } + + public DataMessage GetCommissions(GetCommissionInputs model) + { + DataMessage message; + + message = policyRepository.GetCommissions(model); + + return message; + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/CommissionMode.cs b/OpenImis.Modules/InsureeModule/Models/CommissionMode.cs new file mode 100644 index 00000000..a7d90dfa --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Models/CommissionMode.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Models +{ + public enum CommissionMode + { + Prescribed, + Paid + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/Contribution.cs b/OpenImis.Modules/InsureeModule/Models/Contribution.cs new file mode 100644 index 00000000..6dae93b9 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Models/Contribution.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Models +{ + public class Contribution + { + [Required] + //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number ")] + public string InsuranceNumber { get; set; } + [Required(ErrorMessage = "7-Wrong or missing payer")] + public string Payer { get; set; } + [Required(ErrorMessage = "4:Wrong or missing payment date")] + //[ValidDate(ErrorMessage = "4:Wrong or missing payment date")] + public string PaymentDate { get; set; } + [Required(ErrorMessage = "3:Wrong or missing product ")] + public string ProductCode { get; set; } + [Required] + public decimal Amount { get; set; } + [Required(ErrorMessage = "8:Missing receipt no.")] + public string ReceiptNumber { get; set; } + [Required(ErrorMessage = "6:Wrong or missing payment type")] + [StringLength(1, ErrorMessage = "6:Wrong or missing payment type")] + public string PaymentType { get; set; } + [Required] + public ReactionType ReactionType { get; set; } + [StringLength(1, ErrorMessage = "5:Wrong contribution category")] + public string ContributionCategory { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/DataMessage.cs b/OpenImis.Modules/InsureeModule/Models/DataMessage.cs new file mode 100644 index 00000000..acfc03d2 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Models/DataMessage.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Models +{ + public class DataMessage + { + public int Code { get; set; } + public string MessageValue { get; set; } + public bool ErrorOccured { get; set; } + public object Data { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/EditFamilyMember.cs b/OpenImis.Modules/InsureeModule/Models/EditFamilyMember.cs new file mode 100644 index 00000000..0cf63d9c --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Models/EditFamilyMember.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Models +{ + public class EditFamilyMember + { + [Required] + //[InsureeNumber(ErrorMessage = "3:Wrong format or missing insurance number of member")] + public string InsureeNumber { get; set; } + public string OtherName { get; set; } + public string LastName { get; set; } + //[ValidDate(ErrorMessage = "5:Wrong format or missing birth date")] + public string BirthDate { get; set; } + [StringLength(1, ErrorMessage = "6:Wrong gender")] + public string Gender { get; set; } + + public string Relationship { get; set; } + [StringLength(1, ErrorMessage = "7:Wrong marital status")] + public string MaritalStatus { get; set; } + public bool Beneficiary_Card { get; set; } + public string CurrentVillageCode { get; set; } + public string CurrentAddressDetails { get; set; } + public string Profession { get; set; } + public string Education { get; set; } + public string PhoneNumber { get; set; } + public string Email { get; set; } + public string IdentificationType { get; set; } + public string IdentificationNumber { get; set; } + public string FspCode { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/EditFamilyModel.cs b/OpenImis.Modules/InsureeModule/Models/EditFamilyModel.cs new file mode 100644 index 00000000..f7532460 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Models/EditFamilyModel.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Models +{ + public class EditFamily + { + public string VillageCode { get; set; } + [Required(ErrorMessage = "1:Wrong format or missing insurance number of head")] + //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] + public string HeadOfFamilyId { get; set; } + public string OtherName { get; set; } + public string LastName { get; set; } + //[ValidDate(ErrorMessage = "6:Wrong format or missing birth date")] + public string BirthDate { get; set; } + public string Gender { get; set; } + public bool PovertyStatus { get; set; } + public string ConfirmationType { get; set; } + public string GroupType { get; set; } + public string ConfrimationNo { get; set; } + public string PermanentAddressDetails { get; set; } + [StringLength(1, ErrorMessage = "11:Wrong marital status")] + public string MaritalStatus { get; set; } + public bool BeneficiaryCard { get; set; } + public string CurrentVillageCode { get; set; } + public string CurrentAddressDetails { get; set; } + public string Profession { get; set; } + public string Education { get; set; } + public string PhoneNumber { get; set; } + public string Email { get; set; } + public string IdentificationType { get; set; } + public string IdentificationNumber { get; set; } + public string FspCode { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/Family.cs b/OpenImis.Modules/InsureeModule/Models/Family.cs new file mode 100644 index 00000000..5a5f4d3f --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Models/Family.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Models +{ + public abstract class Family + { + public string InsuranceNumber { get; set; } + public string OtherNames { get; set; } + public string LastName { get; set; } + public DateTime BirthDate { get; set; } + public string Gender { get; set; } + public bool? PoveryStatus { get; set; } + public string ConfirmationType { get; set; } + public string PermanentAddress { get; set; } + public string MaritalStatus { get; set; } + public bool BeneficiaryCard { get; set; } + public string CurrentVillageCode { get; set; } + public string CurrentAddress { get; set; } + public string Profession { get; set; } + public short? Education { get; set; } + public string PhoneNumber { get; set; } + public string Email { get; set; } + public string IdentificationType { get; set; } + public string IdentificationNumber { get; set; } + public string FSPCode { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/FamilyMember.cs b/OpenImis.Modules/InsureeModule/Models/FamilyMember.cs new file mode 100644 index 00000000..34fa331f --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Models/FamilyMember.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Models +{ + public class FamilyMember + { + [Required] + //[InsureeNumber(ErrorMessage = "3:Wrong format or missing insurance number of member")] + public string InsureeNumber { get; set; } + [Required] + //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] + public string HeadInsureeNumber { get; set; } + [Required(ErrorMessage = "7:Missing other name", AllowEmptyStrings = false)] + public string OtherName { get; set; } + [Required(ErrorMessage = "6:Missing last name", AllowEmptyStrings = false)] + public string LastName { get; set; } + [Required(ErrorMessage = "5:Wrong format or missing birth date")] + //[ValidDate] + public string BirthDate { get; set; } + [StringLength(1, ErrorMessage = "4:Wrong or missing gender")] + public string Gender { get; set; } + + public string Relationship { get; set; } + [StringLength(1, ErrorMessage = "10:Wrong marital status")] + public string MaritalStatus { get; set; } + public bool Beneficiary_Card { get; set; } + public string CurrentVillageCode { get; set; } + public string CurrentAddressDetails { get; set; } + public string Profession { get; set; } + public string Education { get; set; } + public string PhoneNumber { get; set; } + public string Email { get; set; } + public string IdentificationType { get; set; } + public string IdentificationNumber { get; set; } + public string FspCode { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/FamilyModel.cs b/OpenImis.Modules/InsureeModule/Models/FamilyModel.cs new file mode 100644 index 00000000..d7a1b018 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Models/FamilyModel.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Models +{ + public class FamilyModel : Family + { + public string GroupType { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/FamilyModelv2.cs b/OpenImis.Modules/InsureeModule/Models/FamilyModelv2.cs new file mode 100644 index 00000000..cdae2feb --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Models/FamilyModelv2.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Models +{ + public class FamilyModelv2 : Family + { + public string ConfirmationNo { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/FamilyModelv3.cs b/OpenImis.Modules/InsureeModule/Models/FamilyModelv3.cs new file mode 100644 index 00000000..02d214a3 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Models/FamilyModelv3.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Models +{ + public class FamilyModelv3 : Family + { + /// + /// 4 digit string that represents a village + /// + [Required(ErrorMessage = "3:Wrong or missing permanent village code")] + public string VillageCode { get; set; } + + /// + /// An insuree number belonging to the head of a family + /// + [Required(ErrorMessage = "1:Wrong format or missing insurance number of head")] + //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] + public string HeadOfFamilyId { get; set; } + + [Required(ErrorMessage = "8:Missing other name", AllowEmptyStrings = false)] + public string OtherName { get; set; } + + //[Required(ErrorMessage = "7:Missing last name", AllowEmptyStrings = false)] + //public string LastName { get; set; } + + //[Required(ErrorMessage = "6:Wrong format or missing birth date")] + //[ValidDate] + //public string BirthDate { get; set; } + + //[Required(ErrorMessage = "5:Wrong or missing gender"), StringLength(1, ErrorMessage = "5:Wrong or missing gender")] + //[BindRequired] + //public string Gender { get; set; } + + public bool PovertyStatus { get; set; } + + public string GroupType { get; set; } + + public string ConfrimationNo { get; set; } + + public string PermanentAddressDetails { get; set; } + + //[StringLength(1, ErrorMessage = "11:Wrong marital status")] + //public string MaritalStatus { get; set; } + + public string CurrentAddressDetails { get; set; } + + public string FspCode { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/GetCommissionInputs.cs b/OpenImis.Modules/InsureeModule/Models/GetCommissionInputs.cs new file mode 100644 index 00000000..95f49ae6 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Models/GetCommissionInputs.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Models +{ + public class GetCommissionInputs + { + [Required] + public string enrolment_officer_code { get; set; } + [Required] + public string month { get; set; } + [Required] + public string year { get; set; } + [Required] + public CommissionMode mode { get; set; } + public string insrance_product_code { get; set; } + public string payer { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/Policy.cs b/OpenImis.Modules/InsureeModule/Models/Policy.cs new file mode 100644 index 00000000..778c1fe7 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Models/Policy.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Models +{ + public class Policy + { + [Required] + //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number")] + public string InsuranceNumber { get; set; } + [Required(ErrorMessage = "4:Wrong or missing enrolment date")] + //[ValidDate(ErrorMessage = "4:Wrong or missing enrolment date")] + public string Date { get; set; } + [Required] + public string ProductCode { get; set; } + [Required] + public string EnrollmentOfficerCode { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/ReactionType.cs b/OpenImis.Modules/InsureeModule/Models/ReactionType.cs new file mode 100644 index 00000000..628cfdf7 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Models/ReactionType.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Models +{ + public enum ReactionType + { + Active, + NotActive + } +} diff --git a/OpenImis.Modules/InsureeModule/Repositories/ContributionRepository.cs b/OpenImis.Modules/InsureeModule/Repositories/ContributionRepository.cs new file mode 100644 index 00000000..4115a42e --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Repositories/ContributionRepository.cs @@ -0,0 +1,52 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer.DataHelper; +using OpenImis.Modules.InsureeModule.Helpers; +using OpenImis.Modules.InsureeModule.Models; +using System; +using System.Data.SqlClient; + +namespace OpenImis.Modules.InsureeModule.Repositories +{ + public class ContributionRepository : IContributionRepository + { + private IConfiguration Configuration; + public int UserId { get; set; } + + public ContributionRepository(IConfiguration configuration) + { + Configuration = configuration; + } + + public DataMessage Enter(Contribution model) + { + DataHelper helper = new DataHelper(Configuration); + + SqlParameter[] sqlParameters = { + new SqlParameter("@AuditUserID", UserId), + new SqlParameter("@InsuranceNumber", model.InsuranceNumber), + new SqlParameter("@Payer", model.Payer), + new SqlParameter("@PaymentDate", model.PaymentDate), + new SqlParameter("@ProductCode", model.ProductCode), + new SqlParameter("@ReceiptNo", model.ReceiptNumber), + new SqlParameter("@ReactionType", model.ReactionType), + new SqlParameter("@ContributionCategory", model.ContributionCategory), + new SqlParameter("@ContributionAmount", model.Amount), + new SqlParameter("@PaymentType", model.PaymentType) + }; + + DataMessage message; + + try + { + var response = helper.Procedure("uspAPIEnterContribution", sqlParameters, 1); + message = new EnterContibutionResponse(response.Code, false, response.Data, 0).Message; + } + catch (Exception e) + { + message = new EditFamilyResponse(e).Message; + } + + return message; + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Repositories/FamilyRepository.cs b/OpenImis.Modules/InsureeModule/Repositories/FamilyRepository.cs new file mode 100644 index 00000000..0b325414 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Repositories/FamilyRepository.cs @@ -0,0 +1,371 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using OpenImis.DB.SqlServer.DataHelper; +using OpenImis.Modules.InsureeModule.Helpers; +using OpenImis.Modules.InsureeModule.Models; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; + +namespace OpenImis.Modules.InsureeModule.Repositories +{ + public class FamilyRepository : IFamilyRepository + { + private IConfiguration Configuration; + + public int UserId { get; set; } + + public FamilyRepository(IConfiguration configuration) + { + Configuration = configuration; + } + + public List Get(string insureeNumber) + { + List response = new List(); + + try + { + using (var imisContext = new ImisDB()) + { + response = (from F in imisContext.TblFamilies + join I in imisContext.TblInsuree on F.InsureeId equals I.InsureeId into tmpI + from I in tmpI.DefaultIfEmpty() + join L in imisContext.TblLocations on F.LocationId equals L.LocationId into tmpL + from L in tmpL.DefaultIfEmpty() + join C in imisContext.TblConfirmationTypes on F.ConfirmationType equals C.ConfirmationTypeCode into tmpC + from C in tmpC.DefaultIfEmpty() + join G in imisContext.TblFamilyTypes on F.FamilyType equals G.FamilyTypeCode into tmpG + from G in tmpG.DefaultIfEmpty() + join P in imisContext.TblProfessions on I.Profession equals P.ProfessionId into tmpP + from P in tmpP.DefaultIfEmpty() + join HF in imisContext.TblHf on I.Hfid equals HF.HfId into tmpHF + from HF in tmpHF.DefaultIfEmpty() + where (I.Chfid == insureeNumber + && F.ValidityTo == null + && I.ValidityTo == null + && L.ValidityTo == null + && HF.ValidityTo == null) + select new FamilyModel() + { + InsuranceNumber = I.Chfid, + OtherNames = I.OtherNames, + LastName = I.LastName, + BirthDate = I.Dob, + Gender = I.Gender, + PoveryStatus = F.Poverty, + ConfirmationType = C.ConfirmationTypeCode, + GroupType = F.FamilyType, + PermanentAddress = F.FamilyAddress, + MaritalStatus = I.Marital, + BeneficiaryCard = I.CardIssued, + CurrentVillageCode = L.LocationCode, + CurrentAddress = I.CurrentAddress, + Profession = P.Profession, + Education = I.Education, + PhoneNumber = I.Phone, + Email = I.Email, + IdentificationType = I.TypeOfId, + IdentificationNumber = I.Passport, + FSPCode = HF.Hfcode + }) + .ToList(); + } + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + + public List GetMember(string insureeNumber, int order) + { + List response = new List(); + + try + { + using (var imisContext = new ImisDB()) + { + var tblOrder = (from I in imisContext.TblInsuree + join H in imisContext.TblInsuree.Where(a => a.ValidityTo == null + && a.Chfid == insureeNumber + && a.IsHead == true) on I.FamilyId equals H.FamilyId + where I.ValidityTo == null + orderby I.IsHead descending, I.InsureeId ascending + select I.InsureeId) + .ToArray() + .Select((InsureeID, RowNo) => new + { + RowNo = RowNo + 1, + InsureeID + }) + .ToArray(); + + response = (from I in imisContext.TblInsuree + join O in tblOrder on I.InsureeId equals O.InsureeID + join F in imisContext.TblFamilies on I.FamilyId equals F.FamilyId + join L in imisContext.TblLocations on F.LocationId equals L.LocationId into tmpL + from L in tmpL.DefaultIfEmpty() + join C in imisContext.TblConfirmationTypes on F.ConfirmationType equals C.ConfirmationTypeCode into tmpC + from C in tmpC.DefaultIfEmpty() + join G in imisContext.TblFamilyTypes on F.FamilyType equals G.FamilyTypeCode into tmpG + from G in tmpG.DefaultIfEmpty() + join P in imisContext.TblProfessions on I.Profession equals P.ProfessionId into tmpP + from P in tmpP.DefaultIfEmpty() + join HF in imisContext.TblHf on I.Hfid equals HF.HfId into tmpHF + from HF in tmpHF.DefaultIfEmpty() + where (O.RowNo == order + && F.ValidityTo == null + && I.ValidityTo == null + && L.ValidityTo == null + && HF.ValidityTo == null) + select new FamilyModelv2 + { + InsuranceNumber = I.Chfid, + OtherNames = I.OtherNames, + LastName = I.LastName, + BirthDate = I.Dob, + Gender = I.Gender, + PoveryStatus = F.Poverty, + ConfirmationType = C.ConfirmationTypeCode, + ConfirmationNo = F.ConfirmationNo, + PermanentAddress = F.FamilyAddress, + MaritalStatus = I.Marital, + BeneficiaryCard = I.CardIssued, + CurrentVillageCode = L.LocationCode, + CurrentAddress = I.CurrentAddress, + Profession = P.Profession, + Education = I.Education, + PhoneNumber = I.Phone, + Email = I.Email, + IdentificationType = I.TypeOfId, + IdentificationNumber = I.Passport, + FSPCode = HF.Hfcode + }) + .ToList(); + } + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + + public DataMessage AddNew(FamilyModelv3 model) + { + DataMessage message; + + try + { + SqlParameter[] sqlParameters = { + new SqlParameter("@AuditUserID", UserId), + new SqlParameter("@PermanentVillageCode", model.VillageCode), + new SqlParameter("@InsuranceNumber", model.HeadOfFamilyId), + new SqlParameter("@OtherNames", model.OtherName), + new SqlParameter("@LastName", model.LastName), + new SqlParameter("@BirthDate", model.BirthDate), + new SqlParameter("@Gender", model.Gender), + new SqlParameter("@PovertyStatus", model.PovertyStatus), + new SqlParameter("@ConfirmationType", model.ConfirmationType), + new SqlParameter("@GroupType", model.GroupType), + new SqlParameter("@ConfirmationNo", model.ConfrimationNo), + new SqlParameter("@PermanentAddress", model.PermanentAddressDetails), + new SqlParameter("@MaritalStatus", model.MaritalStatus), + new SqlParameter("@BeneficiaryCard", model.BeneficiaryCard), + new SqlParameter("@CurrentVillageCode", model.CurrentVillageCode), + new SqlParameter("@CurrentAddress", model.CurrentAddressDetails), + new SqlParameter("@Proffesion", model.Profession), + new SqlParameter("@Education", model.Education), + new SqlParameter("@PhoneNumber", model.PhoneNumber), + new SqlParameter("@Email", model.Email), + new SqlParameter("@IdentificationType", model.IdentificationType), + new SqlParameter("@IdentificationNumber", model.IdentificationNumber), + new SqlParameter("@FspCode", model.FspCode), + }; + + DataHelper helper = new DataHelper(Configuration); + + using (var imisContext = new ImisDB()) + { + var response = helper.Procedure("uspAPIEnterFamily", sqlParameters); + + message = new EnterFamilyResponse(response.Code, false, response.Data, 0).Message; + } + + return message; + } + catch (Exception e) + { + message = new EditFamilyResponse(e).Message; + } + return message; + } + + public DataMessage Edit(EditFamily model) + { + DataHelper helper = new DataHelper(Configuration); + + DataMessage message; + + SqlParameter[] sqlParameters = { + new SqlParameter("@AuditUserID", UserId), + new SqlParameter("@InsuranceNumberOfHead", model.HeadOfFamilyId), + new SqlParameter("@VillageCode", model.VillageCode), + new SqlParameter("@OtherNames", model.OtherName), + new SqlParameter("@LastName", model.LastName), + new SqlParameter("@BirthDate", model.BirthDate), + new SqlParameter("@Gender", model.Gender), + new SqlParameter("@PovertyStatus", model.PovertyStatus), + new SqlParameter("@ConfirmationType", model.ConfirmationType), + new SqlParameter("@GroupType", model.GroupType), + new SqlParameter("@ConfirmationNumber", model.ConfrimationNo), + new SqlParameter("@PermanentAddress", model.PermanentAddressDetails), + new SqlParameter("@MaritalStatus", model.MaritalStatus), + new SqlParameter("@BeneficiaryCard", model.BeneficiaryCard), + new SqlParameter("@CurrentVillageCode", model.CurrentVillageCode), + new SqlParameter("@CurrentAddress", model.CurrentAddressDetails), + new SqlParameter("@Proffesion", model.Profession), + new SqlParameter("@Education", model.Education), + new SqlParameter("@PhoneNumber", model.PhoneNumber), + new SqlParameter("@Email", model.Email), + new SqlParameter("@IdentificationType", model.IdentificationType), + new SqlParameter("@IdentificationNumber", model.IdentificationNumber), + new SqlParameter("@FSPCode", model.FspCode), + }; + + try + { + var response = helper.Procedure("uspAPIEditFamily", sqlParameters); + message = new EditFamilyResponse(response.Code, false, response.Data, 0).Message; + + return message; + } + catch (Exception e) + { + message = new EditFamilyResponse(e).Message; + } + return message; + } + + public DataMessage AddMember(FamilyMember model) + { + DataHelper helper = new DataHelper(Configuration); + + SqlParameter[] sqlParameters = { + new SqlParameter("@AuditUserID", UserId), + new SqlParameter("@InsureeNumber", model.InsureeNumber), + new SqlParameter("@InsureeNumberOfHead", model.HeadInsureeNumber), + new SqlParameter("@OtherNames", model.OtherName), + new SqlParameter("@LastName", model.LastName), + new SqlParameter("@BirthDate", model.BirthDate), + new SqlParameter("@Gender", model.Gender), + new SqlParameter("@Relationship", model.Relationship), + new SqlParameter("@MaritalStatus", model.MaritalStatus), + new SqlParameter("@BeneficiaryCard", model.Beneficiary_Card), + new SqlParameter("@VillageCode", model.CurrentVillageCode), + new SqlParameter("@CurrentAddress", model.CurrentAddressDetails), + new SqlParameter("@Proffesion", model.Profession), + new SqlParameter("@Education", model.Education), + new SqlParameter("@PhoneNumber", model.PhoneNumber), + new SqlParameter("@Email", model.Email), + new SqlParameter("@IdentificationType", model.IdentificationType), + new SqlParameter("@IdentificationNumber", model.IdentificationNumber), + new SqlParameter("@FspCode", model.FspCode) + }; + + DataMessage message; + + try + { + var response = helper.Procedure("uspAPIEnterMemberFamily", sqlParameters); + message = new EnterMemberFamilyResponse(response.Code, false, response.Data, 0).Message; + } + catch (Exception e) + { + + message = new EnterMemberFamilyResponse(e).Message; + } + + return message; + } + + public DataMessage EditMember(EditFamilyMember model) + { + DataHelper helper = new DataHelper(Configuration); + + SqlParameter[] sqlParameters = { + new SqlParameter("@AuditUserID", UserId), + new SqlParameter("@InsureeNumber", model.InsureeNumber), + new SqlParameter("@OtherNames", model.OtherName), + new SqlParameter("@LastName", model.LastName), + new SqlParameter("@BirthDate", model.BirthDate), + new SqlParameter("@Gender", model.Gender), + new SqlParameter("@Relationship", model.Relationship), + new SqlParameter("@MaritalStatus",model.MaritalStatus), + new SqlParameter("@BeneficiaryCard", model.Beneficiary_Card), + new SqlParameter("@VillageCode", model.CurrentVillageCode), + new SqlParameter("@CurrentAddress", model.CurrentAddressDetails), + new SqlParameter("@Proffesion", model.Profession), + new SqlParameter("@Education", model.Education), + new SqlParameter("@PhoneNumber", model.PhoneNumber), + new SqlParameter("@Email", model.Email), + new SqlParameter("@IdentificationType", model.IdentificationType), + new SqlParameter("@IdentificationNumber", model.IdentificationNumber), + new SqlParameter("@FspCode", model.FspCode) + }; + + DataMessage message; + + try + { + var response = helper.Procedure("uspAPIEditMemberFamily", sqlParameters); + message = new EditMemberFamilyResponse(response.Code, false, response.Data, 0).Message; + } + catch (Exception e) + { + + message = new EditFamilyResponse(e).Message; + } + + return message; + } + + public DataMessage DeleteMember(string insureeNumber) + { + SqlParameter[] parameters = { + new SqlParameter("@InsuranceNumber", insureeNumber), + new SqlParameter("@AuditUserID", UserId) + }; + + var data = new DataHelper(Configuration); + + DataMessage message; + + try + { + var response = data.Procedure("uspAPIDeleteMemberFamily", parameters); + message = new DeleteMamberFamilyResponse(response.Code, false, response.Data, 0).Message; + } + catch (Exception e) + { + message = new DeleteMamberFamilyResponse(e).Message; + } + + + return message; + } + } +} \ No newline at end of file diff --git a/OpenImis.Modules/InsureeModule/Repositories/IContributionRepository.cs b/OpenImis.Modules/InsureeModule/Repositories/IContributionRepository.cs new file mode 100644 index 00000000..bd4527a7 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Repositories/IContributionRepository.cs @@ -0,0 +1,13 @@ +using OpenImis.Modules.InsureeModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Repositories +{ + public interface IContributionRepository + { + DataMessage Enter(Contribution model); + int UserId { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Repositories/IFamilyRepository.cs b/OpenImis.Modules/InsureeModule/Repositories/IFamilyRepository.cs new file mode 100644 index 00000000..51a3df53 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Repositories/IFamilyRepository.cs @@ -0,0 +1,19 @@ +using OpenImis.Modules.InsureeModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Repositories +{ + public interface IFamilyRepository + { + List Get(string insureeNumber); + List GetMember(string insureeNumber, int order); + DataMessage AddNew(FamilyModelv3 model); + int UserId { get; set; } + DataMessage Edit(EditFamily model); + DataMessage AddMember(FamilyMember model); + DataMessage EditMember(EditFamilyMember model); + DataMessage DeleteMember(string insureeNumber); + } +} diff --git a/OpenImis.Modules/InsureeModule/Repositories/IPolicyRepository.cs b/OpenImis.Modules/InsureeModule/Repositories/IPolicyRepository.cs new file mode 100644 index 00000000..13f8a1b1 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Repositories/IPolicyRepository.cs @@ -0,0 +1,15 @@ +using OpenImis.Modules.InsureeModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.InsureeModule.Repositories +{ + public interface IPolicyRepository + { + DataMessage Enter(Policy model); + DataMessage Renew(Policy model); + DataMessage GetCommissions(GetCommissionInputs model); + int UserId { get; set; } + } +} diff --git a/OpenImis.Modules/InsureeModule/Repositories/PolicyRepository.cs b/OpenImis.Modules/InsureeModule/Repositories/PolicyRepository.cs new file mode 100644 index 00000000..40c7ce95 --- /dev/null +++ b/OpenImis.Modules/InsureeModule/Repositories/PolicyRepository.cs @@ -0,0 +1,136 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using OpenImis.DB.SqlServer.DataHelper; +using OpenImis.Modules.InsureeModule.Helpers; +using OpenImis.Modules.InsureeModule.Models; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; + +namespace OpenImis.Modules.InsureeModule.Repositories +{ + public class PolicyRepository : IPolicyRepository + { + private IConfiguration Configuration; + + public int UserId { get; set; } + + public PolicyRepository(IConfiguration configuration) + { + Configuration = configuration; + } + + public DataMessage Enter(Policy model) + { + DataHelper helper = new DataHelper(Configuration); + + SqlParameter[] sqlParameters = { + new SqlParameter("@AuditUserID", UserId), + new SqlParameter("@InsuranceNumber", model.InsuranceNumber), + new SqlParameter("@EnrollmentDate", model.Date), + new SqlParameter("@ProductCode", model.ProductCode), + new SqlParameter("@EnrollmentOfficerCode", model.EnrollmentOfficerCode) + }; + + DataMessage message; + + try + { + var response = helper.Procedure("uspAPIEnterPolicy", sqlParameters); + message = new EnterPolicyResponse(response.Code, false, response.Data, 0).Message; + } + catch (Exception e) + { + message = new EditFamilyResponse(e).Message; + } + + return message; + } + + public DataMessage Renew(Policy model) + { + DataHelper helper = new DataHelper(Configuration); + + SqlParameter[] sqlParameters = { + new SqlParameter("@AuditUserID", UserId), + new SqlParameter("@InsuranceNumber", model.InsuranceNumber), + new SqlParameter("@RenewalDate", model.Date), + new SqlParameter("@ProductCode", model.ProductCode), + new SqlParameter("@EnrollmentOfficerCode", model.EnrollmentOfficerCode) + }; + + DataMessage message; + + try + { + var response = helper.GetDataTable("uspAPIRenewPolicy", sqlParameters, System.Data.CommandType.StoredProcedure); + message = new RenewPolicyResponse(0, false, 0).Message; + } + catch (Exception e) + { + + message = new EditFamilyResponse(e).Message; + } + + return message; + } + + public DataMessage GetCommissions(GetCommissionInputs model) + { + dynamic response; + + int year = DateTime.UtcNow.Year; + int month = DateTime.UtcNow.Month; + + try + { + year = Convert.ToInt32(model.year); + month = Convert.ToInt32(model.month); + } + catch (Exception) + { + throw; + } + + DateTime minDate = new DateTime(year, month, 1); + DateTime maxDate = new DateTime(year, month, DateTime.DaysInMonth(year, month)); + + DataMessage message; + + try + { + using (var imisContext = new ImisDB()) + { + var res = (from PR in imisContext.TblPremium + join P in imisContext.TblPolicy.Where(p => p.ValidityTo == null) on PR.PolicyId equals P.PolicyId + join R in imisContext.TblReporting on PR.ReportingCommissionID equals R.ReportingId + join O in imisContext.TblOfficer on P.OfficerId equals O.OfficerId + where (PR.ReportingCommissionID == null + && (PR.PayDate >= minDate && PR.PayDate <= maxDate) + && PR.ValidityTo == null + && O.Code == model.enrolment_officer_code) + select new + { + Commission = (R.CammissionRate == null ? 0.00M : R.CammissionRate) * PR.Amount, + PR.Amount + }) + .ToList(); + + var c = res.Count > 0 ? res.Sum(x => x.Commission) : null; + var a = res.Count > 0 ? res.Sum(x => (decimal?)x.Amount) : null; + + response = new List(){ new { Commission = c, Amount = a } }; + + message = new GetCommissionResponse(0, false, response, 0).Message; + } + } + catch (Exception e) + { + message = new GetCommissionResponse(e).Message; + } + + return message; + } + } +} \ No newline at end of file diff --git a/OpenImis.RestApi/Controllers/ContributionController.cs b/OpenImis.RestApi/Controllers/ContributionController.cs new file mode 100644 index 00000000..0a919858 --- /dev/null +++ b/OpenImis.RestApi/Controllers/ContributionController.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Cors; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using OpenImis.Modules; +using OpenImis.Modules.InsureeModule.Models; + +namespace OpenImis.RestApi.Controllers +{ + [Route("api/")] + [ApiController] + [EnableCors("AllowSpecificOrigin")] + public class ContributionController : Controller + { + private readonly IImisModules _imisModules; + public ContributionController(IImisModules imisModules) + { + _imisModules = imisModules; + } + + [HttpPost] + [Route("Contributions/Enter_Contribution")] + public virtual IActionResult Enter_Contribution([FromBody]Contribution model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + //var identity = HttpContext.User.Identity as ClaimsIdentity; + //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + + // Temporary + var userId = 1; + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + + var response = _imisModules.GetInsureeModule().GetContributionLogic().Enter(model); + + return Json(response); + } + } +} \ No newline at end of file diff --git a/OpenImis.RestApi/Controllers/FamilyController.cs b/OpenImis.RestApi/Controllers/FamilyController.cs new file mode 100644 index 00000000..98ff6214 --- /dev/null +++ b/OpenImis.RestApi/Controllers/FamilyController.cs @@ -0,0 +1,208 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Cors; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using OpenImis.Modules; +using OpenImis.Modules.InsureeModule.Helpers; +using OpenImis.Modules.InsureeModule.Models; + +namespace OpenImis.RestApi.Controllers +{ + [Route("api/")] + [ApiController] + [EnableCors("AllowSpecificOrigin")] + public class FamilyController : Controller + { + private readonly IImisModules _imisModules; + public FamilyController(IImisModules imisModules) + { + _imisModules = imisModules; + } + + [HttpGet] + [Route("Families/Get_Family")] + public IActionResult Get(string insureeNumber) + { + DataMessage response; + try + { + if (insureeNumber != null || insureeNumber.Length != 0) + { + var data = _imisModules.GetInsureeModule().GetFamilyLogic().Get(insureeNumber); + + if (data.Count > 0) + { + response = new GetFamilyResponse(0, false, data, 0).Message; + } + else + { + response = new GetFamilyResponse(2, false, 0).Message; + } + } + else + { + response = new GetFamilyResponse(1, true, 0).Message; + } + } + catch (Exception e) + { + response = new GetFamilyResponse(e).Message; + } + + return Json(response); + } + + [HttpGet] + [Route("Families/Get_Member_Family")] + public IActionResult Get_Member_Family(string insureeNumber, int order) + { + DataMessage response; + try + { + if (insureeNumber != null || insureeNumber.Length != 0) + { + var data = _imisModules.GetInsureeModule().GetFamilyLogic().GetMember(insureeNumber, order); + + if (data.Count > 0) + { + response = new GetMemberFamilyResponse(0, false, data, 0).Message; + } + else + { + response = new GetMemberFamilyResponse(2, true, 0).Message; + } + } + else + { + response = new GetMemberFamilyResponse(1, true, 0).Message; + } + } + catch (Exception e) + { + response = new GetMemberFamilyResponse(e).Message; + } + + var serializerSettings = new JsonSerializerSettings(); + serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + + return Json(response, serializerSettings); + } + + [HttpPost] + [Route("Families/Enter_Family")] + public IActionResult Enter_Family([FromBody]FamilyModelv3 model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + //var identity = HttpContext.User.Identity as ClaimsIdentity; + //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + + // Temporary + var userId = 1; + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + + var response = _imisModules.GetInsureeModule().GetFamilyLogic().AddNew(model); + + return Json(response); + } + + [HttpPost] + [Route("Families/Edit_Family")] + public IActionResult Edit_Family([FromBody]EditFamily model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + //var identity = HttpContext.User.Identity as ClaimsIdentity; + //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + + // Temporary + var userId = 1; + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + + var response = _imisModules.GetInsureeModule().GetFamilyLogic().Edit(model); + + return Json(response); + } + + [HttpPost] + [Route("Families/Enter_Member_Family")] + public IActionResult Enter_Member_Family([FromBody]FamilyMember model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + //var identity = HttpContext.User.Identity as ClaimsIdentity; + //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + + // Temporary + var userId = 1; + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + + var response = _imisModules.GetInsureeModule().GetFamilyLogic().AddMember(model); + + return Json(response); + } + + [HttpPost] + [Route("Families/Edit_Member_Family")] + public IActionResult Edit_Member_Family([FromBody]EditFamilyMember model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + //var identity = HttpContext.User.Identity as ClaimsIdentity; + //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + + // Temporary + var userId = 1; + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + + var response = _imisModules.GetInsureeModule().GetFamilyLogic().EditMember(model); + + return Json(response); + } + + [HttpPost] + [Route("Families/Delete_Member_Family")] + public IActionResult Delete_Member_Family([FromBody]string insureeNumber) + { + //if (new ValidationBase().InsureeNumber(insureeNumber) != ValidationResult.Success) + //{ + // return BadRequest(new { error_occured = true, error_message = "1:Wrong format or missing insurance number of insuree" }); + //} + + //var identity = HttpContext.User.Identity as ClaimsIdentity; + //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + + // Temporary + var userId = 1; + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + + var response = _imisModules.GetInsureeModule().GetFamilyLogic().DeleteMember(insureeNumber); + + return Json(response); + } + } +} \ No newline at end of file diff --git a/OpenImis.RestApi/Controllers/PolicyController.cs b/OpenImis.RestApi/Controllers/PolicyController.cs new file mode 100644 index 00000000..f021024d --- /dev/null +++ b/OpenImis.RestApi/Controllers/PolicyController.cs @@ -0,0 +1,105 @@ +using System.Diagnostics; +using System.Linq; +using Microsoft.AspNetCore.Cors; +using Microsoft.AspNetCore.Mvc; +using OpenImis.Modules; +using OpenImis.Modules.InsureeModule.Models; + +namespace OpenImis.RestApi.Controllers +{ + [Route("api/")] + [ApiController] + [EnableCors("AllowSpecificOrigin")] + public class PolicyController : Controller + { + private readonly IImisModules _imisModules; + public PolicyController(IImisModules imisModules) + { + _imisModules = imisModules; + } + + [HttpPost] + [Route("Policies/Enter_Policy")] + public virtual IActionResult Enter_Policy([FromBody]Policy model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + //var identity = HttpContext.User.Identity as ClaimsIdentity; + //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + + // Temporary + var userId = 1; + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + + var response = _imisModules.GetInsureeModule().GetPolicyLogic().Enter(model); + + return Json(response); + } + + [HttpPost] + [Route("Policies/Renew_Policy")] + public virtual IActionResult Renew_Policy([FromBody]Policy model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + //var identity = HttpContext.User.Identity as ClaimsIdentity; + //var iden = identity.FindFirst("UserId"); + + //try + //{ + // policies.UserId = Convert.ToInt32(iden.Value); + //} + //catch (Exception e) + //{ + // policies.UserId = -1; + //} + + // Temporary + var userId = 1; + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + + var response = _imisModules.GetInsureeModule().GetPolicyLogic().Renew(model); + + return Json(response); + } + + [HttpPost] + [Route("Policies/Get_Commissions")] + public virtual IActionResult Get_Commissions([FromBody]GetCommissionInputs model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + //var identity = HttpContext.User.Identity as ClaimsIdentity; + //var iden = identity.FindFirst("UserId"); + + //try + //{ + // policies.UserId = Convert.ToInt32(iden.Value); + //} + //catch (Exception e) + //{ + // policies.UserId = -1; + //} + + // Temporary + var userId = 1; + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + + var response = _imisModules.GetInsureeModule().GetPolicyLogic().GetCommissions(model); + + return Json(response); + } + } +} \ No newline at end of file From 11b546e7826ae9e6bc660fc6e58f634924cb1780 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 27 Jun 2019 13:02:09 +0200 Subject: [PATCH 09/86] OS-24: Fixed typo --- OpenImis.Modules/ImisModules.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/OpenImis.Modules/ImisModules.cs b/OpenImis.Modules/ImisModules.cs index 24560ef4..f4a74f1f 100644 --- a/OpenImis.Modules/ImisModules.cs +++ b/OpenImis.Modules/ImisModules.cs @@ -57,6 +57,7 @@ public ILoginModule GetLoginModule() loginModule = new LoginModule.LoginModule(_configuration); } return loginModule; + } public ICoverageModule GetCoverageModule() { From 5ae4bb8a4e530edb95795edf7a51e53f991351b7 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 4 Jul 2019 10:41:20 +0200 Subject: [PATCH 10/86] OS-25: The Payment Module has been added --- OpenImis.Modules/IImisModules.cs | 3 + OpenImis.Modules/ImisModules.cs | 20 +- .../Helpers/CtrlNumberResponse.cs | 49 ++ .../Helpers/Extensions/StringExtensions.cs | 53 ++ .../PaymentModule/Helpers/FamilyDefaults.cs | 14 + .../PaymentModule/Helpers/ImisApiResponse.cs | 50 ++ .../PaymentModule/Helpers/LocalDefault.cs | 131 ++++ .../PaymentModule/Helpers/MatchPayResponse.cs | 50 ++ .../Helpers/Messages/Language.cs | 33 + .../Helpers/Messages/PrimaryLanguage.cs | 107 +++ .../Helpers/Messages/SecondaryLanguage.cs | 88 +++ .../Helpers/RequestedCNResponse.cs | 59 ++ .../PaymentModule/Helpers/SMS/ImisBaseSms.cs | 91 +++ .../PaymentModule/Helpers/SMS/ImisSms.cs | 17 + .../PaymentModule/Helpers/SaveAckResponse.cs | 43 ++ .../Helpers/SaveIntentResponse.cs | 89 +++ .../PaymentModule/Helpers/SavePayResponse.cs | 83 ++ .../PaymentModule/IPaymentModule.cs | 12 + .../PaymentModule/Logic/IPaymentLogic.cs | 24 + .../PaymentModule/Logic/PaymentLogic.cs | 455 +++++++++++ .../PaymentModule/Models/Acknowledgement.cs | 15 + .../PaymentModule/Models/CnStatus.cs | 15 + .../PaymentModule/Models/ControlNumberResp.cs | 17 + .../PaymentModule/Models/DataMessage.cs | 14 + .../PaymentModule/Models/EnrolmentType.cs | 12 + .../PaymentModule/Models/InsureeProduct.cs | 18 + .../PaymentModule/Models/IntentOfPay.cs | 24 + .../PaymentModule/Models/Language.cs | 12 + .../PaymentModule/Models/MatchModel.cs | 14 + .../PaymentModule/Models/MatchSms.cs | 13 + .../PaymentModule/Models/MatchedPayment.cs | 16 + .../PaymentModule/Models/PaymentData.cs | 35 + .../PaymentModule/Models/PaymentDetail.cs | 30 + .../PaymentModule/Models/PaymentRequest.cs | 11 + .../PaymentModule/Models/Request.cs | 13 + .../Response/AsignedControlNumbersResponse.cs | 12 + .../Models/Response/AssignedControlNumber.cs | 12 + .../Models/Response/ErrorResponse.cs | 11 + .../Models/Response/ErrorResponseV2.cs | 12 + .../Models/Response/GetControlNumberResp.cs | 14 + .../Models/Response/PaymentDataBadResp.cs | 11 + .../Models/Response/PostReqCNResponse.cs | 17 + .../PaymentModule/Models/Rights.cs | 23 + .../PaymentModule/Models/SMS/SmsContainer.cs | 12 + .../PaymentModule/Models/TypeOfPayment.cs | 13 + .../PaymentModule/PaymentModule.cs | 31 + .../Repositories/IPaymentRepository.cs | 47 ++ .../Repositories/PaymentRepository.cs | 717 ++++++++++++++++++ .../Controllers/PaymentController.cs | 229 ++++++ OpenImis.RestApi/Escape/Sms/Headers.cs | 63 ++ .../Sms/Strings/ControlNumberAssigned.txt | 1 + .../Sms/Strings/ControlNumberAssignedV2.txt | 1 + .../Escape/Sms/Strings/ControlNumberError.txt | 1 + .../Sms/Strings/ControlNumberErrorV2.txt | 1 + .../Escape/Sms/Strings/PaidAndActivated.txt | 1 + .../Sms/Strings/PaidAndNotActivated.txt | 1 + .../Escape/Sms/Strings/PaidAndNotMatched.txt | 1 + .../Sms/Strings/PaidAndNotMatchedV2.txt | 1 + .../ControlNumberAssigned.txt | 1 + .../ControlNumberAssignedV2.txt | 1 + .../ControlNumberError.txt | 1 + .../ControlNumberErrorV2.txt | 1 + .../PaidAndActivated.txt | 1 + .../PaidAndNotActivated.txt | 1 + .../PaidAndNotMatched.txt | 1 + .../PaidAndNotMatchedV2.txt | 1 + 66 files changed, 2967 insertions(+), 3 deletions(-) create mode 100644 OpenImis.Modules/PaymentModule/Helpers/CtrlNumberResponse.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/Extensions/StringExtensions.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/FamilyDefaults.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/ImisApiResponse.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/LocalDefault.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/MatchPayResponse.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/Messages/Language.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/Messages/PrimaryLanguage.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/Messages/SecondaryLanguage.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/RequestedCNResponse.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/SMS/ImisBaseSms.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/SMS/ImisSms.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/SaveAckResponse.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/SaveIntentResponse.cs create mode 100644 OpenImis.Modules/PaymentModule/Helpers/SavePayResponse.cs create mode 100644 OpenImis.Modules/PaymentModule/IPaymentModule.cs create mode 100644 OpenImis.Modules/PaymentModule/Logic/IPaymentLogic.cs create mode 100644 OpenImis.Modules/PaymentModule/Logic/PaymentLogic.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/Acknowledgement.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/CnStatus.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/ControlNumberResp.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/DataMessage.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/EnrolmentType.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/InsureeProduct.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/IntentOfPay.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/Language.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/MatchModel.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/MatchSms.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/MatchedPayment.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/PaymentData.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/PaymentDetail.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/PaymentRequest.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/Request.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/Response/AssignedControlNumber.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/Response/ErrorResponse.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/Response/ErrorResponseV2.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/Response/GetControlNumberResp.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/Response/PaymentDataBadResp.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/Response/PostReqCNResponse.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/Rights.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/SMS/SmsContainer.cs create mode 100644 OpenImis.Modules/PaymentModule/Models/TypeOfPayment.cs create mode 100644 OpenImis.Modules/PaymentModule/PaymentModule.cs create mode 100644 OpenImis.Modules/PaymentModule/Repositories/IPaymentRepository.cs create mode 100644 OpenImis.Modules/PaymentModule/Repositories/PaymentRepository.cs create mode 100644 OpenImis.RestApi/Controllers/PaymentController.cs create mode 100644 OpenImis.RestApi/Escape/Sms/Headers.cs create mode 100644 OpenImis.RestApi/Escape/Sms/Strings/ControlNumberAssigned.txt create mode 100644 OpenImis.RestApi/Escape/Sms/Strings/ControlNumberAssignedV2.txt create mode 100644 OpenImis.RestApi/Escape/Sms/Strings/ControlNumberError.txt create mode 100644 OpenImis.RestApi/Escape/Sms/Strings/ControlNumberErrorV2.txt create mode 100644 OpenImis.RestApi/Escape/Sms/Strings/PaidAndActivated.txt create mode 100644 OpenImis.RestApi/Escape/Sms/Strings/PaidAndNotActivated.txt create mode 100644 OpenImis.RestApi/Escape/Sms/Strings/PaidAndNotMatched.txt create mode 100644 OpenImis.RestApi/Escape/Sms/Strings/PaidAndNotMatchedV2.txt create mode 100644 OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberAssigned.txt create mode 100644 OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberAssignedV2.txt create mode 100644 OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberError.txt create mode 100644 OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberErrorV2.txt create mode 100644 OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndActivated.txt create mode 100644 OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndNotActivated.txt create mode 100644 OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndNotMatched.txt create mode 100644 OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndNotMatchedV2.txt diff --git a/OpenImis.Modules/IImisModules.cs b/OpenImis.Modules/IImisModules.cs index 84379e83..93f96892 100644 --- a/OpenImis.Modules/IImisModules.cs +++ b/OpenImis.Modules/IImisModules.cs @@ -9,6 +9,7 @@ using OpenImis.Modules.InsureeModule; using OpenImis.Modules.LoginModule; using OpenImis.Modules.CoverageModule; +using OpenImis.Modules.PaymentModule; namespace OpenImis.Modules { @@ -25,6 +26,8 @@ public interface IImisModules ICoverageModule GetCoverageModule(); + IPaymentModule GetPaymentModule(); + /// /// Creates and returns the user management module. /// diff --git a/OpenImis.Modules/ImisModules.cs b/OpenImis.Modules/ImisModules.cs index 1fdcf92b..f583af08 100644 --- a/OpenImis.Modules/ImisModules.cs +++ b/OpenImis.Modules/ImisModules.cs @@ -12,6 +12,8 @@ using OpenImis.Modules.InsureeModule; using OpenImis.Modules.LoginModule; using OpenImis.Modules.CoverageModule; +using OpenImis.Modules.PaymentModule; +using Microsoft.AspNetCore.Hosting; namespace OpenImis.Modules { @@ -44,14 +46,17 @@ public class ImisModules: IImisModules private IInsureeModule insureeModule; private ILoginModule loginModule; private ICoverageModule coverageModule; + private IPaymentModule paymentModule; private readonly IConfiguration _configuration; - private readonly ILogger logger; + public readonly IHostingEnvironment _hostingEnvironment; + private readonly ILogger logger; - public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory) + public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory, IHostingEnvironment hostingEnvironment) { _configuration = configuration; - logger = loggerFactory.CreateLogger("LoggerCategory"); + _hostingEnvironment = hostingEnvironment; + logger = loggerFactory.CreateLogger("LoggerCategory"); } public IClaimModule GetClaimModule() @@ -90,6 +95,15 @@ public ICoverageModule GetCoverageModule() return coverageModule; } + public IPaymentModule GetPaymentModule() + { + if (paymentModule == null) + { + paymentModule = new PaymentModule.PaymentModule(_configuration, _hostingEnvironment); + } + return paymentModule; + } + /// /// Creates and returns the user management module. /// diff --git a/OpenImis.Modules/PaymentModule/Helpers/CtrlNumberResponse.cs b/OpenImis.Modules/PaymentModule/Helpers/CtrlNumberResponse.cs new file mode 100644 index 00000000..436b7838 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/CtrlNumberResponse.cs @@ -0,0 +1,49 @@ +using OpenImis.Modules.PaymentModule.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers +{ + public class CtrlNumberResponse : ImisApiResponse + { + public CtrlNumberResponse(Exception e) : base(e) + { + + } + + public CtrlNumberResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + + } + + public CtrlNumberResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "CantAssignCN"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "DuplicateCN"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/Extensions/StringExtensions.cs b/OpenImis.Modules/PaymentModule/Helpers/Extensions/StringExtensions.cs new file mode 100644 index 00000000..af155ffb --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/Extensions/StringExtensions.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers.Extensions +{ + public static class StringExtensions + { + public static int? GetErrorNumber(this string str) + { + if (String.IsNullOrEmpty(str)) + { + return null; + } + else + { + try + { + var error = str.Split(":"); + var errorNumber = int.Parse(error[0]); + return errorNumber; + } + catch (Exception) + { + return null; + } + } + } + + public static string GetErrorMessage(this string str) + { + if (String.IsNullOrEmpty(str)) + { + return str; + } + else + { + try + { + var error = str.Split(":"); + int.Parse(error[0]); + var errorMessae = error[1]; + return errorMessae; + } + catch (Exception) + { + + return str; + } + } + } + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/FamilyDefaults.cs b/OpenImis.Modules/PaymentModule/Helpers/FamilyDefaults.cs new file mode 100644 index 00000000..56d57577 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/FamilyDefaults.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers +{ + public class FamilyDefaults + { + public int Adults { get; set; } + public int Children { get; set; } + public int OtherAdults { get; internal set; } + public int OtherChildren { get; internal set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/ImisApiResponse.cs b/OpenImis.Modules/PaymentModule/Helpers/ImisApiResponse.cs new file mode 100644 index 00000000..8d05bd4f --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/ImisApiResponse.cs @@ -0,0 +1,50 @@ +using Newtonsoft.Json; +using OpenImis.Modules.PaymentModule.Models; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers +{ + public class ImisApiResponse + { + public DataMessage msg = new DataMessage(); + public int language { get; set; } + + public ImisApiResponse(Exception e) + { + msg.Code = -1; + msg.ErrorOccured = true; + msg.MessageValue = e.Message; + Message = msg; + } + + public ImisApiResponse(int value, bool error, int lang) + { + if (value != 0) + error = true; + + language = lang; + + msg.Code = value; + msg.ErrorOccured = error; + Message = msg; + } + + public ImisApiResponse(int value, bool error, DataTable data, int lang) + { + if (value != 0) + error = true; + + language = lang; + + msg.Code = value; + msg.ErrorOccured = error; + msg.Data = JsonConvert.SerializeObject(data); + Message = msg; + } + + public DataMessage Message { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/LocalDefault.cs b/OpenImis.Modules/PaymentModule/Helpers/LocalDefault.cs new file mode 100644 index 00000000..eccba393 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/LocalDefault.cs @@ -0,0 +1,131 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.Modules.PaymentModule.Repositories; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers +{ + public static class LocalDefault + { + public static FamilyDefaults FamilyMembers(IConfiguration config) + { + try + { + var adults = Convert.ToInt32(config["Defaults:Family:Adults"]); + var children = Convert.ToInt32(config["Defaults:Family:Children"]); + var other_adults = Convert.ToInt32(config["Defaults:Family:OtherAdults"]); + var other_children = Convert.ToInt32(config["Defaults:Family:OtherChildren"]); + + FamilyDefaults fam = new FamilyDefaults() { Adults = adults, Children = children, OtherAdults = other_adults, OtherChildren = other_children }; + return fam; + } + catch (Exception) + { + + throw new Exception("A Family property is not properly defined in config file"); + } + } + + public static bool PriorEnrolmentRequired(IConfiguration config) + { + try + { + var value = Convert.ToBoolean(config["Defaults:PriorEnrolment"]); + return value; + } + catch (Exception) + { + throw new Exception("This property is not properly defined in config file"); + } + } + + public static bool ShouldSendSms(IConfiguration config, DateTime? lastSmsDate, DateTime? matchedDate) + { + try + { + var value = Convert.ToInt32(config["Defaults:PeriodPayNotMatchedSms"]); + if (value == 0) + return false; + + DateTime today = DateTime.UtcNow; + + if (lastSmsDate != null) + { + DateTime thatday = (DateTime)lastSmsDate; + int interval = (today - thatday).Days; + + if (value > 0) + { + return false; + } + else + { + value *= -1; + if (interval % value == 0) + { + return true; + } + else + { + return false; + } + } + } + else + { + if (matchedDate != null) + { + DateTime thatday = (DateTime)matchedDate; + int interval = (today - thatday).Days; + + if (interval / value >= 1) + { + return true; + } + else + { + return false; + } + } + else + { + return false; + } + } + + } + catch (Exception) + { + throw new Exception("This property is not properly defined in config file"); + } + } + + public static string[] PrimaryLangReprisantations(IConfiguration config) + { + List langs = new List(); + try + { + var def_langs = config["Language:Primary"].Split(','); + + foreach (var def_lang in def_langs) + { + try + { + langs.Add(def_lang.ToLower()); + } + catch (Exception) + { + langs.Add(def_lang); + } + } + } + catch (Exception) + { + langs.Add("en"); + } + + return langs.ToArray(); + } + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/MatchPayResponse.cs b/OpenImis.Modules/PaymentModule/Helpers/MatchPayResponse.cs new file mode 100644 index 00000000..5ead6d03 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/MatchPayResponse.cs @@ -0,0 +1,50 @@ +using Newtonsoft.Json; +using OpenImis.Modules.PaymentModule.Helpers.Messages; +using OpenImis.Modules.PaymentModule.Models; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers +{ + public class MatchPayResponse : ImisApiResponse + { + public MatchPayResponse(Exception e) : base(e) + { + + } + public MatchPayResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + + } + + public MatchPayResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + var jsonString = JsonConvert.SerializeObject(data); + var matched_payments = JsonConvert.DeserializeObject>(jsonString); + var _data = matched_payments; + msg.Data = _data; + + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Messages.Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Messages.Language().GetMessage(language, "PayIdDoesntExist"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/Messages/Language.cs b/OpenImis.Modules/PaymentModule/Helpers/Messages/Language.cs new file mode 100644 index 00000000..94e28837 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/Messages/Language.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers.Messages +{ + public class Language + { + public string GetMessage(int language, string name) + { + FieldInfo fieldInfos; + + switch (language) + { + + case 0: + fieldInfos = typeof(PrimaryLanguage).GetField(name); + break; + case 1: + fieldInfos = typeof(SecondaryLanguage).GetField(name); + + break; + default: + fieldInfos = typeof(PrimaryLanguage).GetField(name); + + break; + } + var val = (string)fieldInfos.GetValue(null); + return val; + } + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/Messages/PrimaryLanguage.cs b/OpenImis.Modules/PaymentModule/Helpers/Messages/PrimaryLanguage.cs new file mode 100644 index 00000000..be4701e9 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/Messages/PrimaryLanguage.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers.Messages +{ + public static class PrimaryLanguage + { + public static string Success = "Success"; + + //CtrlNumberResponse + public static string CantAssignCN = "1-Control number cannot be assigned by the external payment gateway"; + public static string DuplicateCN = "2-Duplicate Control Number"; + + //DeleteMemberFamilyResponse + public static string WrongFormatMissingIN = "Wrong Format or Missing Insurance Number of Member"; + public static string INNotFount = "Insurance number of member not found"; + public static string MemberNotHead = "Mamber is head of family"; + + //EditFamilyResponse + public static string WrongOrMissingHeadIN = "Wrong Format or Missing Insurance Number of head."; + public static string HeadINNotFound = "Insurance Number of head not found."; + public static string WrongPVillageCode = "Wrong permanent village code."; + public static string WrongCVillageCode = "Wrong current village Code."; + public static string WrongGender = "Wrong gender."; + public static string WrongConfirmationType = "Wrong confirmation type"; + public static string WrongGroupType = "Wrong group type"; + public static string WrongMaritalStatus = "Wrong marital status"; + public static string WrongEducation = "Wrong education"; + public static string WrongProfession = "Wrong profession."; + public static string FSPCodeNotFound = "FSP code not found"; + public static string WrongIdentificationType = "Wrong Identification Type"; + + //EditMemberFamilyResponse + public static string WrongINMember = "Wrong format of insurance number of member"; + public static string NotFountINMember = "Insurance number of member not found"; + public static string WrongVillageCode = "Wrong current village code"; + public static string WrongRelationship = "Wrong Relationship"; + + //EnterContributionResponse + public static string WrongOrMissingPC = "Wrong or missing product code (not existing or not applicable to the family/group)"; + public static string WrongOrMissingPayDate = "Wrong or missing payment date"; + public static string WrongContributionCat = "Wrong contribution category"; + public static string WrongOrMissingPayType = "Wrong or missing payment type"; + public static string WrongOrMissingPayer = "Wrong or missing payer"; + public static string MissingReceiptNumber = "Missing receipt no."; + public static string DuplicateReceiptNumber = "Duplicated receipt no."; + + //EnterFamilyResponse + public static string DuplicateINHead = "Duplicated Insurance Number of head."; + public static string WrongOrMissingPVC = "Wrong or missing permanent village code."; + public static string WrongOrMissingGender = "Wrong or missing gender."; + public static string WrongFrOrMissingBd = "Wrong format or missing birth date."; + public static string MissingLastName = "Missing last name."; + public static string MissingOtherName = "Missing other name"; + + //EnterMemberFamilyResponse + public static string DuplicatedMemberIN = "Insurance number of member duplicated "; + + //EnterPolicyResponse + public static string WrongOrMissingEnrolDate = "Wrong or missing enrolment date"; + public static string WrongOrMissingEOcode = "Wrong or missing enrolment officer code (not existing or not applicable to the family/group)"; + + //GetCoverageResponse + + //GetFamilyResponse + + //GetMemberFamilyResponse + public static string NoMemberOfOrder = "No member of the specified order number in the family/group"; + + //MatchPayResponse + public static string PayIdDoesntExist = "1-The paymentId does not exist"; + + //RenewPolicyResponse + public static string WrongOrMissingRenDate = "Wrong or missing renewal date"; + + //RequestedCNResponse + public static string WrongInternalIdFormat = "1-Wrong format of internal identifier"; + public static string InvalidInternalId = "2-Not valid internal identifier "; + + //SaveAckResponse + public static string CantPostReq = "1-Request for control number cannot be posted in the external payment gateway"; + + //SaveIntentResponse + public static string WrongFormatInsureeNo = "1-Wrong format of insurance number"; + public static string InValidINmissingPC = "2-Not valid insurance or missing product code"; + public static string InValidEOC = "3-Not valid enrolment officer code"; + public static string IncompatibleEO_PC = "4-Enrolment officer code and insurance product code are not compatible"; + public static string NoRenewalProduct = "5-Beneficiary has no policy of specified insurance product for renewal"; + public static string InsureeNoMissing = "6-Missing insurance number"; + public static string InsureeNotEnrolled = "7-Insuree not enrolled while prior enrolment mandatory."; + public static string DuplicateCNAssigned = "8-Duplicated control number assigned"; + public static string CantAssignCn2 = "9-Control number cannot be assigned"; + public static string UnknownPaymentType = "10-Uknown type of payment"; + + //SavePayResponse + public static string WrongOrMissingRecDate = "1-Wrong or missing receiving date"; + public static string WrongFormatInputData = "2-Wrong format of input data"; + public static string WrongControlNumber = "3-Wrong control_number"; + public static string WrongAmount = "4-Wrong Amount"; + public static string DuplicatePayAmount = "5-Duplicate Payment Amount"; + public static string DoesntExistEO = "6-Enrolment Officer Code does not exist"; + public static string DoesntExistPC = "7-Product Code Does not Exist"; + public static string NoPolicyForRenewal = "8-Beneficiary has no policy of specified insurance product for renewal"; + public static string UnknownTypeOfPay = "9-Uknown type of payment"; + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/Messages/SecondaryLanguage.cs b/OpenImis.Modules/PaymentModule/Helpers/Messages/SecondaryLanguage.cs new file mode 100644 index 00000000..8b781d18 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/Messages/SecondaryLanguage.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers.Messages +{ + public static class SecondaryLanguage + { + public static string Success = "Imefanikiwa"; + + public static string CantAssignCN = "1-Na. ya ankara imeshindikana kutotelewa na mfumo wa malipo"; + public static string DuplicateCN = "2-Na. ya ankara imejirudia"; + + public static string WrongFormatMissingIN = "Umekosea namba ya mwanachama au namba haipo"; + public static string INNotFount = "Namba ya mwanachama haipo"; + public static string MemberNotHead = "Mwanachama ni mkuu wa kaya"; + + public static string WrongOrMissingHeadIN = "Umekosea namba ya mkuu wa kaya au namba haipo"; + public static string HeadINNotFound = "Namba ya mkuu wa kaya haipo"; + public static string WrongPVillageCode = "Umekosea namba ya kijiji"; + public static string WrongCVillageCode = "Umekosea namba ya kijiji"; + public static string WrongGender = "Umekosea jinsia"; + public static string WrongConfirmationType = "Wrong confirmation type"; + public static string WrongGroupType = "Umekosea aina ya kundi"; + public static string WrongMaritalStatus = "Umekosea hali ya ndoa"; + public static string WrongEducation = "Umekosea elimu"; + public static string WrongProfession = "Umekosea elimu"; + public static string FSPCodeNotFound = "Na. ya FSP haipo"; + public static string WrongIdentificationType = "Umekosea aina ya kitambulisho"; + + public static string WrongINMember = "Umekosea namba ya mwanachama"; + public static string NotFountINMember = "Namba ya mwanachama haipo kwenye kompuyta kuu"; + public static string WrongVillageCode = "Umekosea namba ya kijiji"; + public static string WrongRelationship = "Umekosea uhusiano"; + + public static string WrongOrMissingPC = "Umekosea namba ya bidhaa au haitumiki kwenye familia husika"; + public static string WrongOrMissingPayDate = "Umekosea tarehe ya malipo"; + public static string WrongContributionCat = "Umekosea kundi la malipo"; + public static string WrongOrMissingPayType = "Umekosea aina ya malipo"; + public static string WrongOrMissingPayer = "Umekosea mlipaji"; + public static string MissingReceiptNumber = "Jaza namba ya risiti"; + public static string DuplicateReceiptNumber = "Namba ya risiti imejirudia"; + + public static string DuplicateINHead = "Namba ya mwachama imejirudia"; + public static string WrongOrMissingPVC = "Umekosea/Jaza namba ya kijiji"; + public static string WrongOrMissingGender = "Umekosea/Jaza Jinsia"; + public static string WrongFrOrMissingBd = "Jaza/Umekosea tarehe"; + public static string MissingLastName = "Jaza jina la ukoo"; + public static string MissingOtherName = "Jaza majina mengine"; + + public static string DuplicatedMemberIN = "Namba ya mwanachama imejirudia"; + + public static string WrongOrMissingEnrolDate = "Jaza/Umekosea tarehe ya kujiunga"; + public static string WrongOrMissingEOcode = "Jaza/Umekosea namba ya msimbo ya afisa mwandikishaji"; + + public static string NoMemberOfOrder = "Na ya mwanchama kwenye familia haipo"; + public static string PayIdDoesntExist = "1-Namba ya malipo haipo"; + + public static string WrongOrMissingRenDate = "Jaza/Umekosea tarehe ya kuhuisha"; + + public static string WrongInternalIdFormat = "1-Wrong format of internal identifier"; + public static string InvalidInternalId = "2-Not valid internal identifier "; + + public static string CantPostReq = "1-Maombi ya Na. ya ankara yameshindikana, jaribu tena"; + + public static string WrongFormatInsureeNo = "1-Namba ya mwanachama imekosewa"; + public static string InValidINmissingPC = "2-Umekosea namba ya mwanachama au namba ya bidhaa"; + public static string InValidEOC = "3-Umekosea namba ya msimbo ya afisa mwandikishaji"; + public static string IncompatibleEO_PC = "4-Namba ya mwanachama na namba ya bidhaa haviendani"; + public static string NoRenewalProduct = "5-Mwanachama hajajiunga na bidhaa husika"; + + public static string InsureeNoMissing = "6-Jaza namba ya mwanachama"; + public static string InsureeNotEnrolled = "7-Insuree not enrolled while prior enrolment mandatory."; + public static string DuplicateCNAssigned = "8-Umepatiwa namba ya ankara iliyojirudia, jaribu tena"; + public static string CantAssignCn2 = "9-Na. ya ankara imeshishindikana kutolewa, jaribu tena"; + public static string UnknownPaymentType = "10-Aina ya malipo uliyochagua hayapo"; + + public static string WrongOrMissingRecDate = "1-Umekosea tarehe ya kupokea"; + public static string WrongFormatInputData = "2-Umekosea taarifa uliyojaza"; + public static string WrongControlNumber = "3-Umekosea Na. ya ankara"; + public static string WrongAmount = "4-Umekosea kiasi"; + public static string DuplicatePayAmount = "5-Umerudia malipo"; + public static string DoesntExistEO = "6-Namba ya msimbo ya afisa mwandikishaji haipo"; + public static string DoesntExistPC = "7-Namba ya bidhaa haipo"; + public static string NoPolicyForRenewal = "8-Mwanachama hajajiunga na bidhaa husika"; + public static string UnknownTypeOfPay = "9-Aina ya malipo uliyochagua haipo"; + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/RequestedCNResponse.cs b/OpenImis.Modules/PaymentModule/Helpers/RequestedCNResponse.cs new file mode 100644 index 00000000..8fd6c34f --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/RequestedCNResponse.cs @@ -0,0 +1,59 @@ +using Newtonsoft.Json; +using OpenImis.Modules.PaymentModule.Helpers.Messages; +using OpenImis.Modules.PaymentModule.Models; +using OpenImis.Modules.PaymentModule.Models.Response; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers +{ + public class RequestedCNResponse : ImisApiResponse + { + public RequestedCNResponse(Exception e) : base(e) + { + } + + public RequestedCNResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + + public RequestedCNResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + var jsonString = JsonConvert.SerializeObject(data); + var reqs = JsonConvert.DeserializeObject>(jsonString); + msg.Data = reqs; + + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Messages.Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Messages.Language().GetMessage(language, "WrongInternalIdFormat"); + Message = msg; + break; + case 2: + var jsonString = JsonConvert.SerializeObject(msg.Data); + var reqs = JsonConvert.DeserializeObject>(jsonString).Select(x => x.internal_identifier).ToArray(); + var Ids_string = string.Join(",", reqs); + + msg.Code = value; + msg.MessageValue = new Messages.Language().GetMessage(language, "InvalidInternalId") + Ids_string; + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisBaseSms.cs b/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisBaseSms.cs new file mode 100644 index 00000000..3ec3f777 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisBaseSms.cs @@ -0,0 +1,91 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; +using OpenImis.Modules.PaymentModule.Models; +using OpenImis.Modules.PaymentModule.Models.SMS; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace OpenImis.Modules.PaymentModule.Helpers.SMS +{ + public class ImisBaseSms + { + private string SmsTampletes = string.Empty; + private IHostingEnvironment env; + + public ImisBaseSms(IConfiguration config, IHostingEnvironment environment, Language language = Language.Primary) + { + env = environment; + + if (language == Language.Primary) + SmsTampletes = environment.ContentRootPath + @"\Escape\Sms\Strings\"; + else + SmsTampletes = environment.ContentRootPath + @"\Escape\Sms\StringsSecondaryLanguage\"; + } + + public virtual async Task SendSMS(List containers, string filename) + { + string response_message = string.Empty; + + + HttpClient client = new HttpClient(); + + var param = new { data = containers, datetime = DateTime.Now.ToString() }; + var content = new StringContent(JsonConvert.SerializeObject(param), Encoding.ASCII, "application/json"); + + try + { + var response = await client.PostAsync("url", content); + var ret = await response.Content.ReadAsStringAsync(); + response_message = ret; + } + catch (Exception e) + { + response_message = e.ToString(); + } + + var msg = JsonConvert.SerializeObject(containers); + SaveMessage(msg, filename); + + return response_message; + + } + + public virtual void SaveMessage(string message, string name) + { + //string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + string mydocpath = System.IO.Path.Combine(env.WebRootPath, "SentMessages"); + string namepart = new Random().Next(100000, 999999).ToString(); + + using (StreamWriter outputFile = new StreamWriter(Path.Combine(mydocpath, name + namepart + ".json"))) + { + outputFile.WriteLine(message); + } + } + + public virtual string GetMessage(string filename) + { + string text = File.ReadAllText(SmsTampletes + filename + ".txt", Encoding.UTF8); + return text; + } + + public virtual async void QuickSms(string txtmsg, string phoneNumber, Language language = Language.Primary) + { + + + var txtmsgTemplate = string.Empty; + string othersCount = string.Empty; + + List message = new List(); + message.Add(new SmsContainer() { Message = txtmsg, Recipient = phoneNumber }); + + var fileName = "QuickSms_" + phoneNumber; + + string test = await SendSMS(message, fileName); + } + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisSms.cs b/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisSms.cs new file mode 100644 index 00000000..683798c3 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisSms.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using OpenImis.Modules.PaymentModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers.SMS +{ + public class ImisSms : ImisBaseSms + { + public ImisSms(IConfiguration config, IHostingEnvironment env, Language language = Language.Primary) : base(config, env, language) + { + + } + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/SaveAckResponse.cs b/OpenImis.Modules/PaymentModule/Helpers/SaveAckResponse.cs new file mode 100644 index 00000000..849d1f6c --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/SaveAckResponse.cs @@ -0,0 +1,43 @@ +using OpenImis.Modules.PaymentModule.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers +{ + public class SaveAckResponse : ImisApiResponse + { + public SaveAckResponse(Exception e) : base(e) + { + + } + + public SaveAckResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + + public SaveAckResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); ; + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "CantPostReq"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/SaveIntentResponse.cs b/OpenImis.Modules/PaymentModule/Helpers/SaveIntentResponse.cs new file mode 100644 index 00000000..a601eb95 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/SaveIntentResponse.cs @@ -0,0 +1,89 @@ +using OpenImis.Modules.PaymentModule.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers +{ + public class SaveIntentResponse : ImisApiResponse + { + public SaveIntentResponse(Exception e) : base(e) + { + + } + + public SaveIntentResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + + } + + public SaveIntentResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongFormatInsureeNo"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "InValidINmissingPC"); + Message = msg; + break; + case 3: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "InValidEOC"); + Message = msg; + break; + case 4: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "IncompatibleEO_PC"); + Message = msg; + break; + case 5: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "NoRenewalProduct"); + Message = msg; + break; + case 6: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "InsureeNoMissing"); + Message = msg; + break; + case 7: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "InsureeNotEnrolled"); + Message = msg; + break; + case 8: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "DuplicateCNAssigned"); + Message = msg; + break; + case 9: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "CantAssignCn2"); + Message = msg; + break; + case 10: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "UnknownPaymentType"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/PaymentModule/Helpers/SavePayResponse.cs b/OpenImis.Modules/PaymentModule/Helpers/SavePayResponse.cs new file mode 100644 index 00000000..5d3bf7f6 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Helpers/SavePayResponse.cs @@ -0,0 +1,83 @@ +using OpenImis.Modules.PaymentModule.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Helpers +{ + public class SavePayResponse : ImisApiResponse + { + public SavePayResponse(Exception e) : base(e) + { + + } + public SavePayResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + + } + + public SavePayResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingRecDate"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongFormatInputData"); + Message = msg; + break; + case 3: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongControlNumber"); + Message = msg; + break; + case 4: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongAmount"); + Message = msg; + break; + case 5: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "DuplicatePayAmount"); + Message = msg; + break; + case 6: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "DoesntExistEO"); + Message = msg; + break; + case 7: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "DoesntExistPC"); + Message = msg; + break; + case 8: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "NoPolicyForRenewal"); + Message = msg; + break; + case 9: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "UnknownTypeOfPay"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.Modules/PaymentModule/IPaymentModule.cs b/OpenImis.Modules/PaymentModule/IPaymentModule.cs new file mode 100644 index 00000000..eae4def0 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/IPaymentModule.cs @@ -0,0 +1,12 @@ +using OpenImis.Modules.PaymentModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule +{ + public interface IPaymentModule + { + IPaymentLogic GetPaymentLogic(); + } +} diff --git a/OpenImis.Modules/PaymentModule/Logic/IPaymentLogic.cs b/OpenImis.Modules/PaymentModule/Logic/IPaymentLogic.cs new file mode 100644 index 00000000..0e86c587 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Logic/IPaymentLogic.cs @@ -0,0 +1,24 @@ +using OpenImis.Modules.PaymentModule.Models; +using OpenImis.Modules.PaymentModule.Repositories; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace OpenImis.Modules.PaymentModule.Logic +{ + public interface IPaymentLogic + { + Task SaveIntent(IntentOfPay intent, int? errorNumber = 0, string errorMessage = null); + Task MatchPayment(MatchModel model); + DataMessage SaveAcknowledgement(Acknowledgement model); + Task SavePayment(PaymentData model); + DataMessage SaveControlNumber(ControlNumberResp model); + void ControlNumberAssignedSms(IPaymentRepository payment); + Task GetControlNumbers(PaymentRequest requests); + void ControlNumberNotassignedSms(IPaymentRepository payment, string error); + void SendPaymentSms(PaymentRepository payment); + void SendMatchSms(PaymentRepository payment); + void SendMatchSms(List Ids); + } +} diff --git a/OpenImis.Modules/PaymentModule/Logic/PaymentLogic.cs b/OpenImis.Modules/PaymentModule/Logic/PaymentLogic.cs new file mode 100644 index 00000000..26f5e82d --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Logic/PaymentLogic.cs @@ -0,0 +1,455 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; +using OpenImis.Modules.PaymentModule.Helpers; +using OpenImis.Modules.PaymentModule.Helpers.SMS; +using OpenImis.Modules.PaymentModule.Models; +using OpenImis.Modules.PaymentModule.Models.Response; +using OpenImis.Modules.PaymentModule.Models.SMS; +using OpenImis.Modules.PaymentModule.Repositories; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenImis.Modules.PaymentModule.Logic +{ + public class PaymentLogic : IPaymentLogic + { + private IConfiguration Configuration; + private readonly IHostingEnvironment _hostingEnvironment; + + protected IPaymentRepository paymentRepository; + + public PaymentLogic(IConfiguration configuration, IHostingEnvironment hostingEnvironment) + { + Configuration = configuration; + _hostingEnvironment = hostingEnvironment; + paymentRepository = new PaymentRepository(Configuration, _hostingEnvironment); + } + + public async Task SaveIntent(IntentOfPay intent, int? errorNumber = 0, string errorMessage = null) + { + IPaymentRepository payment = new PaymentRepository(Configuration, _hostingEnvironment); + var intentResponse = payment.SaveIntent(intent, errorNumber, errorMessage); + + DataMessage return_message = new DataMessage(); + return_message.Code = intentResponse.Code; + return_message.MessageValue = intentResponse.MessageValue; + + if (intentResponse.Code == 0) + { + var objstring = intentResponse.Data.ToString(); + List data = JsonConvert.DeserializeObject>(objstring); + var ret_data = data.FirstOrDefault(); + + decimal transferFee = 0; + //Get the transfer Fee + if (intent.type_of_payment != null) + { + transferFee = payment.determineTransferFee(payment.ExpectedAmount, (TypeOfPayment)intent.type_of_payment); + + var success = payment.UpdatePaymentTransferFee(payment.PaymentId, transferFee, (TypeOfPayment)intent.type_of_payment); + + } + + var amountToBePaid = payment.GetToBePaidAmount(payment.ExpectedAmount, transferFee); + var response = payment.PostReqControlNumber(intent.enrolment_officer_code, payment.PaymentId, intent.phone_number, amountToBePaid, intent.policies); + + if (response.ControlNumber != null) + { + var controlNumberExists = payment.CheckControlNumber(payment.PaymentId, response.ControlNumber); + return_message = payment.SaveControlNumber(response.ControlNumber, controlNumberExists); + if (payment.PaymentId != null) + { + if (!return_message.ErrorOccured && !controlNumberExists) + { + ret_data.control_number = response.ControlNumber; + ControlNumberAssignedSms(payment); + } + else + { + ControlNumberNotassignedSms(payment, return_message.MessageValue); + } + } + } + else if (response.Posted == true) + { + return_message = payment.SaveControlNumberAkn(response.ErrorOccured, response.ErrorMessage); + } + else if (response.ErrorOccured == true) + { + return_message = payment.SaveControlNumberAkn(response.ErrorOccured, response.ErrorMessage); + ControlNumberNotassignedSms(payment, response.ErrorMessage); + + } + + return_message.Data = ret_data; + } + else + { + return_message = intentResponse; + return_message.Data = new AssignedControlNumber(); + } + + return return_message; + } + + public async Task MatchPayment(MatchModel model) + { + PaymentRepository payment = new PaymentRepository(Configuration, _hostingEnvironment); + var response = payment.MatchPayment(model); + + List PaymentIds = new List(); + + PaymentIds = payment.GetPaymentIdsForSms(); + + if (PaymentIds != null) + SendMatchSms(PaymentIds); + + return response; + } + + public DataMessage SaveAcknowledgement(Acknowledgement model) + { + PaymentRepository payment = new PaymentRepository(Configuration, _hostingEnvironment) { PaymentId = model.internal_identifier }; + var response = payment.SaveControlNumberAkn(model.error_occured, model.error_message); + + return response; + } + + public async Task SavePayment(PaymentData model) + { + + PaymentRepository payment = new PaymentRepository(Configuration, _hostingEnvironment); + //var controlNumberExists = payment.CheckControlNumber(model.internal_identifier, model.control_number); + + if (model.control_number != null) + { + model.type_of_payment = null; + + var paymentId = payment.GetPaymentId(model.control_number); + + if (paymentId != null && paymentId != string.Empty) + { + payment.GetPaymentInfo(paymentId); + } + else + { + DataMessage dm = new DataMessage + { + Code = 3, + ErrorOccured = true, + MessageValue = "3-Wrong control_number", + }; + + return dm; + } + } + + + if (model.type_of_payment == null && payment.typeOfPayment != null) + { + var transferFee = payment.determineTransferFeeReverse(Convert.ToDecimal(model.received_amount), (TypeOfPayment)payment.typeOfPayment); + var success = payment.UpdatePaymentTransferFee(payment.PaymentId, transferFee, (TypeOfPayment)payment.typeOfPayment); + model.received_amount = model.received_amount + Convert.ToDouble(transferFee); + } + else if (model.type_of_payment != null && payment.typeOfPayment == null) + { + var transferFee = payment.determineTransferFeeReverse(Convert.ToDecimal(model.received_amount), (TypeOfPayment)model.type_of_payment); + var success = payment.UpdatePaymentTransferFee(payment.PaymentId, transferFee, (TypeOfPayment)model.type_of_payment); + model.received_amount = model.received_amount + Convert.ToDouble(transferFee); + } + + var response = payment.SavePayment(model); + + + + if (payment.PaymentId != null && !response.ErrorOccured) + { + var ackResponse = payment.GetPaymentDataAck(payment.PaymentId, payment.ControlNum); + + MatchModel matchModel = new MatchModel() { internal_identifier = payment.PaymentId, audit_user_id = -3 }; + + var matchresponse = await MatchPayment(matchModel); + + var matchdata = JsonConvert.SerializeObject(matchresponse.Data); + var matchedPayments = JsonConvert.DeserializeObject>(matchdata); + + if (matchedPayments.Select(x => x.PaymentId).Contains(payment.PaymentId)) + { + SendPaymentSms(payment); + } + + } + + return response; + } + + public DataMessage SaveControlNumber(ControlNumberResp model) + { + + PaymentRepository payment = new PaymentRepository(Configuration, _hostingEnvironment); + var controlNumberExists = payment.CheckControlNumber(model.internal_identifier, model.control_number); + var response = payment.SaveControlNumber(model, controlNumberExists); + + if (payment.PaymentId != null) + { + var ackResponse = payment.GetReqControlNumberAck(payment.PaymentId); + + if (!response.ErrorOccured && !controlNumberExists) + { + ControlNumberAssignedSms(payment); + } + else + { + ControlNumberNotassignedSms(payment, response.MessageValue); + } + } + + return response; + } + + public async void ControlNumberAssignedSms(IPaymentRepository payment) + { + //Language lang = payment.Language.ToLower() == "en" || payment.Language.ToLower() == "english" || payment.Language.ToLower() == "primary" ? Language.Primary : Language.Secondary; + ImisSms sms = new ImisSms(Configuration, _hostingEnvironment, payment.Language); + var txtmsgTemplate = string.Empty; + string othersCount = string.Empty; + + if (payment.InsureeProducts.Count > 1) + { + txtmsgTemplate = sms.GetMessage("ControlNumberAssignedV2"); + othersCount = Convert.ToString(payment.InsureeProducts.Count - 1); + } + else + { + txtmsgTemplate = sms.GetMessage("ControlNumberAssigned"); + } + + decimal transferFee = 0; + + if (payment.typeOfPayment != null) + { + transferFee = payment.determineTransferFee(payment.ExpectedAmount, (TypeOfPayment)payment.typeOfPayment); + + } + + var txtmsg = string.Format(txtmsgTemplate, + payment.ControlNum, + DateTime.UtcNow.ToLongDateString(), + DateTime.UtcNow.ToLongTimeString(), + payment.InsureeProducts.FirstOrDefault().InsureeNumber, + payment.InsureeProducts.FirstOrDefault().InsureeName, + payment.InsureeProducts.FirstOrDefault().ProductCode, + payment.InsureeProducts.FirstOrDefault().ProductName, + payment.GetToBePaidAmount(payment.ExpectedAmount, transferFee), + othersCount); + + List message = new List(); + message.Add(new SmsContainer() { Message = txtmsg, Recipient = payment.PhoneNumber }); + + var fileName = "CnAssigned_" + payment.PhoneNumber; + + string test = await sms.SendSMS(message, fileName); + } + + public async Task GetControlNumbers(PaymentRequest requests) + { + PaymentRepository payment = new PaymentRepository(Configuration, _hostingEnvironment); + var PaymentIds = requests.requests.Select(x => x.internal_identifier).ToArray(); + + var PaymentIds_string = string.Join(",", PaymentIds); + + var response = await payment.GetControlNumbers(PaymentIds_string); + + return response; + } + + public async void ControlNumberNotassignedSms(IPaymentRepository payment, string error) + { + //Language lang = payment.Language.ToLower() == "en" || payment.Language.ToLower() == "english" || payment.Language.ToLower() == "primary" ? Language.Primary : Language.Secondary; + ImisSms sms = new ImisSms(Configuration, _hostingEnvironment, payment.Language); + var txtmsgTemplate = string.Empty; + string othersCount = string.Empty; + + if (payment.InsureeProducts.Count > 1) + { + txtmsgTemplate = sms.GetMessage("ControlNumberErrorV2"); + othersCount = Convert.ToString(payment.InsureeProducts.Count - 1); + } + else + { + txtmsgTemplate = sms.GetMessage("ControlNumberError"); + } + + var txtmsg = string.Format(txtmsgTemplate, + payment.ControlNum, + DateTime.UtcNow.ToLongDateString(), + DateTime.UtcNow.ToLongTimeString(), + payment.InsureeProducts.FirstOrDefault().InsureeNumber, + payment.InsureeProducts.FirstOrDefault().ProductCode, + error, + othersCount); + + List message = new List(); + message.Add(new SmsContainer() { Message = txtmsg, Recipient = payment.PhoneNumber }); + + var fileName = "CnError_" + payment.PhoneNumber; + + string test = await sms.SendSMS(message, fileName); + } + + public async void SendPaymentSms(PaymentRepository payment) + { + // Language lang = payment.Language.ToLower() == "en" || payment.Language.ToLower() == "english" || payment.Language.ToLower() == "primary" ? Language.Primary : Language.Secondary; + ImisSms sms = new ImisSms(Configuration, _hostingEnvironment, payment.Language); + List message = new List(); + var familyproduct = payment.InsureeProducts.FirstOrDefault(); + + if (familyproduct.PolicyActivated) + { + + var txtmsg = string.Format(sms.GetMessage("PaidAndActivated"), + payment.PaidAmount, + DateTime.UtcNow.ToLongDateString(), + payment.ControlNum, + familyproduct.InsureeNumber, + familyproduct.InsureeName, + familyproduct.ProductCode, + familyproduct.ProductName, + familyproduct.EffectiveDate.Value.ToShortDateString(), + familyproduct.ExpiryDate.Value.ToShortDateString(), + payment.PaidAmount); + + + message.Add(new SmsContainer() { Message = txtmsg, Recipient = payment.PhoneNumber }); + + } + else + { + + decimal transferFee = 0; + + if (payment.typeOfPayment != null) + { + transferFee = payment.determineTransferFee(payment.ExpectedAmount, (TypeOfPayment)payment.typeOfPayment); + } + + var txtmsg = string.Format(sms.GetMessage("PaidAndNotActivated"), + payment.PaidAmount, + DateTime.UtcNow.ToLongDateString(), + payment.ControlNum, + familyproduct.InsureeNumber, + familyproduct.InsureeName, + familyproduct.ProductCode, + familyproduct.ProductName, + payment.GetToBePaidAmount(payment.ExpectedAmount, transferFee), + payment.OutStAmount); + + message.Add(new SmsContainer() { Message = txtmsg, Recipient = payment.PhoneNumber }); + + } + var fileName = "PayStatSms_" + payment.PhoneNumber; + + string test = await sms.SendSMS(message, fileName); + payment.MatchedSmsSent(); + } + + public async void SendMatchSms(PaymentRepository payment) + { + // Language lang = payment.Language.ToLower() == "en" || payment.Language.ToLower() == "english" || payment.Language.ToLower() == "primary" ? Language.Primary : Language.Secondary; + ImisSms sms = new ImisSms(Configuration, _hostingEnvironment, payment.Language); + List message = new List(); + + var txtmsgTemplate = string.Empty; + string othersCount = string.Empty; + + if (payment.InsureeProducts.Count > 1) + { + txtmsgTemplate = sms.GetMessage("PaidAndNotMatchedV2"); + othersCount = Convert.ToString(payment.InsureeProducts.Count - 1); + } + else + { + txtmsgTemplate = sms.GetMessage("PaidAndNotMatched"); + } + var familyproduct = payment.InsureeProducts.FirstOrDefault(); + var txtmsg = string.Format(txtmsgTemplate, + payment.PaidAmount, + DateTime.UtcNow.ToLongDateString(), + payment.ControlNum, + familyproduct.InsureeNumber, + familyproduct.InsureeName, + familyproduct.ProductCode, + familyproduct.ProductName, + othersCount); + + + message.Add(new SmsContainer() { Message = txtmsg, Recipient = payment.PhoneNumber }); + + var fileName = "PayNotMatched_" + payment.PhoneNumber; + + string test = await sms.SendSMS(message, fileName); + } + + public async void SendMatchSms(List Ids) + { + + List message = new List(); + + foreach (var m in Ids) + { + bool shoulSendSms = LocalDefault.ShouldSendSms(Configuration, m.DateLastSms, m.MatchedDate); + + if (shoulSendSms) + { + var txtmsgTemplate = string.Empty; + string othersCount = string.Empty; + + PaymentRepository _pay = new PaymentRepository(Configuration, _hostingEnvironment); + _pay.GetPaymentInfo(m.PaymentId.ToString()); + + //Language lang = _pay.Language.ToLower() == "en" || _pay.Language.ToLower() == "english" || _pay.Language.ToLower() == "primary" ? Language.Primary : Language.Secondary; + ImisSms sms = new ImisSms(Configuration, _hostingEnvironment, _pay.Language); + + if (_pay.PaymentId != null) + { + if (_pay.InsureeProducts.Count > 1) + { + txtmsgTemplate = sms.GetMessage("PaidAndNotMatchedV2"); + othersCount = Convert.ToString(_pay.InsureeProducts.Count - 1); + } + else + { + txtmsgTemplate = sms.GetMessage("PaidAndNotMatched"); + } + var familyproduct = _pay.InsureeProducts.FirstOrDefault(); + var txtmsg = string.Format(txtmsgTemplate, + _pay.PaidAmount, + DateTime.UtcNow.ToLongDateString(), + _pay.ControlNum, + familyproduct.InsureeNumber, + familyproduct.InsureeName, + familyproduct.ProductCode, + familyproduct.ProductName, + othersCount); + + + message.Add(new SmsContainer() { Message = txtmsg, Recipient = _pay.PhoneNumber }); + _pay.UnMatchedSmsSent(m.PaymentId); + } + else + { + throw new Exception(); + } + + var fileName = "PayNotMatched_"; + string test = await sms.SendSMS(message, fileName); + } + + } + } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/Acknowledgement.cs b/OpenImis.Modules/PaymentModule/Models/Acknowledgement.cs new file mode 100644 index 00000000..d54e0e06 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/Acknowledgement.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public class Acknowledgement + { + [Required] + public string internal_identifier { get; set; } + public string error_message { get; set; } + public bool error_occured { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/CnStatus.cs b/OpenImis.Modules/PaymentModule/Models/CnStatus.cs new file mode 100644 index 00000000..20235656 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/CnStatus.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public enum CnStatus + { + Sent, + Acknowledged, + Issued, + Paid, + Rejected + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/ControlNumberResp.cs b/OpenImis.Modules/PaymentModule/Models/ControlNumberResp.cs new file mode 100644 index 00000000..bfd30347 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/ControlNumberResp.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public class ControlNumberResp + { + [Required] + public string internal_identifier { get; set; } + public string control_number { get; set; } + [Required] + public bool error_occured { get; set; } + public string error_message { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/DataMessage.cs b/OpenImis.Modules/PaymentModule/Models/DataMessage.cs new file mode 100644 index 00000000..b30de232 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/DataMessage.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public class DataMessage + { + public int Code { get; set; } + public string MessageValue { get; set; } + public bool ErrorOccured { get; set; } + public object Data { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/EnrolmentType.cs b/OpenImis.Modules/PaymentModule/Models/EnrolmentType.cs new file mode 100644 index 00000000..e4910478 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/EnrolmentType.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public enum EnrolmentType + { + New, + Renewal + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/InsureeProduct.cs b/OpenImis.Modules/PaymentModule/Models/InsureeProduct.cs new file mode 100644 index 00000000..f8209281 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/InsureeProduct.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public class InsureeProduct + { + public string InsureeNumber { get; set; } + public string InsureeName { get; set; } + public string ProductCode { get; set; } + public string ProductName { get; set; } + public DateTime? EffectiveDate { get; set; } + public DateTime? ExpiryDate { get; set; } + public bool PolicyActivated { get; set; } + public decimal ExpectedProductAmount { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/IntentOfPay.cs b/OpenImis.Modules/PaymentModule/Models/IntentOfPay.cs new file mode 100644 index 00000000..c847d029 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/IntentOfPay.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public class IntentOfPay + { + [Required(ErrorMessage = "9: Phone number not provided")] + public virtual string phone_number { get; set; } + //[ValidDate(ErrorMessage = "10: Request Date not valid")] + [DataType(DataType.DateTime)] + public string request_date { get; set; } + //[OfficerCode] + public string enrolment_officer_code { get; set; } + public virtual List policies { get; set; } + //[RequiredIfEo("amunt to be paid")] + public decimal amount_to_be_paid { get; set; } + public string language { get; set; } + [Range(0, 2, ErrorMessage = "10-Uknown type of payment")] + public TypeOfPayment? type_of_payment { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/Language.cs b/OpenImis.Modules/PaymentModule/Models/Language.cs new file mode 100644 index 00000000..f2357886 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/Language.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public enum Language + { + Primary, + Secondary + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/MatchModel.cs b/OpenImis.Modules/PaymentModule/Models/MatchModel.cs new file mode 100644 index 00000000..34111ec3 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/MatchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public class MatchModel + { + public string internal_identifier { get; set; } + [Required] + public int audit_user_id { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/MatchSms.cs b/OpenImis.Modules/PaymentModule/Models/MatchSms.cs new file mode 100644 index 00000000..b3ed5849 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/MatchSms.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public class MatchSms + { + public int PaymentId { get; set; } + public DateTime? DateLastSms { get; set; } + public DateTime? MatchedDate { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/MatchedPayment.cs b/OpenImis.Modules/PaymentModule/Models/MatchedPayment.cs new file mode 100644 index 00000000..d4176357 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/MatchedPayment.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public class MatchedPayment + { + public string FdMsg { get; set; } + public string ProductCode { get; set; } + public string PaymentId { get; set; } + public string InsuranceNumber { get; set; } + public string isActivated { get; set; } + public int PaymentMatched { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/PaymentData.cs b/OpenImis.Modules/PaymentModule/Models/PaymentData.cs new file mode 100644 index 00000000..e3480bf9 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/PaymentData.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public class PaymentData + { + public string control_number { get; set; } + //[InsureeNumber] + //[RequiredIf("Insuree number")] //this attributes validates if control number is not provided + public string insurance_number { get; set; } + //[RequiredIf("Insurance Product Code")] + public string insurance_product_code { get; set; } + //[RequiredIf("Renewal")] + public EnrolmentType? renewal { get; set; } + //[RequiredIf("Enrolment Officer Code", 2)] + public string enrolment_officer_code { get; set; } + public string transaction_identification { get; set; } + public string receipt_identification { get; set; } + public double received_amount { get; set; } + [Required(ErrorMessage = "1-Wrong or missing receiving date")] + //[ValidDate(ErrorMessage = "1-Wrong or missing receiving date")] + [DataType(DataType.DateTime)] + public string received_date { get; set; } + //[ValidDate(ErrorMessage = "5-Invalid Payment Date")] + [DataType(DataType.DateTime)] + public string payment_date { get; set; } + public string payment_origin { get; set; } + public string language { get; set; } + [Range(0, 2, ErrorMessage = "10-Uknown type of payment")] + public TypeOfPayment? type_of_payment { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/PaymentDetail.cs b/OpenImis.Modules/PaymentModule/Models/PaymentDetail.cs new file mode 100644 index 00000000..8f3c7627 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/PaymentDetail.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public class PaymentDetail + { + //[InsureeNumber] + public string insurance_number { get; set; } + [Required(ErrorMessage = "2:Not valid insurance or missing product code")] + public string insurance_product_code { get; set; } + [Required(ErrorMessage = "10:EnrolmentType was not provided")] + [Range(0, 2)] + public EnrolmentType? renewal { get; set; } + public int IsRenewal() + { + switch (renewal) + { + case EnrolmentType.Renewal: + return 1; + case EnrolmentType.New: + return 0; + default: + return 0; + } + } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/PaymentRequest.cs b/OpenImis.Modules/PaymentModule/Models/PaymentRequest.cs new file mode 100644 index 00000000..517a96bc --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/PaymentRequest.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public class PaymentRequest + { + public List requests { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/Request.cs b/OpenImis.Modules/PaymentModule/Models/Request.cs new file mode 100644 index 00000000..9c41860c --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/Request.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public class Request + { + [Required(ErrorMessage = "1- Wrong format of internal identifier")] + public string internal_identifier { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs b/OpenImis.Modules/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs new file mode 100644 index 00000000..58fe97cb --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models.Response +{ + public class AsignedControlNumbersResponse + { + public bool error_occured { get; set; } + public List assigned_control_numbers { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/Response/AssignedControlNumber.cs b/OpenImis.Modules/PaymentModule/Models/Response/AssignedControlNumber.cs new file mode 100644 index 00000000..f5c3541d --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/Response/AssignedControlNumber.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models.Response +{ + public class AssignedControlNumber + { + public string internal_identifier { get; set; } + public string control_number { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/Response/ErrorResponse.cs b/OpenImis.Modules/PaymentModule/Models/Response/ErrorResponse.cs new file mode 100644 index 00000000..849dfc17 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/Response/ErrorResponse.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models.Response +{ + public class ErrorResponse + { + public string error_message { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/Response/ErrorResponseV2.cs b/OpenImis.Modules/PaymentModule/Models/Response/ErrorResponseV2.cs new file mode 100644 index 00000000..45b3ae36 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/Response/ErrorResponseV2.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models.Response +{ + public class ErrorResponseV2 + { + public bool error_occured { get; set; } + public string error_message { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/Response/GetControlNumberResp.cs b/OpenImis.Modules/PaymentModule/Models/Response/GetControlNumberResp.cs new file mode 100644 index 00000000..cf3e1540 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/Response/GetControlNumberResp.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models.Response +{ + public class GetControlNumberResp + { + public bool error_occured { get; set; } + public string error_message { get; set; } + public string internal_identifier { get; set; } + public string control_number { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/Response/PaymentDataBadResp.cs b/OpenImis.Modules/PaymentModule/Models/Response/PaymentDataBadResp.cs new file mode 100644 index 00000000..1bbd81ed --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/Response/PaymentDataBadResp.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models.Response +{ + public class PaymentDataBadResp + { + public string error_message { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/Response/PostReqCNResponse.cs b/OpenImis.Modules/PaymentModule/Models/Response/PostReqCNResponse.cs new file mode 100644 index 00000000..3f31add3 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/Response/PostReqCNResponse.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models.Response +{ + public class PostReqCNResponse + { + public string ControlNumber { get; set; } + public bool Posted { get; set; } + public bool Assigned { get; set; } + public int ErrorCode { get; set; } + + public bool ErrorOccured { get; set; } + public string ErrorMessage { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/Rights.cs b/OpenImis.Modules/PaymentModule/Models/Rights.cs new file mode 100644 index 00000000..e7c596b3 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/Rights.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public enum Rights + { + PaymentSearch = 101401, + PaymentAdd = 101402, + PaymentEdit = 101403, + PaymentDelete = 101404, + + InsureeSearch = 101101, + InsureeAdd = 101102, + InsureeEdit = 101103, + InsureeDelete = 101104, + InsureeEnquire = 101105, + + FindClaim = 111001, + ClaimAdd = 111002, + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/SMS/SmsContainer.cs b/OpenImis.Modules/PaymentModule/Models/SMS/SmsContainer.cs new file mode 100644 index 00000000..1775e56e --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/SMS/SmsContainer.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models.SMS +{ + public class SmsContainer + { + public string Message { get; set; } + public string Recipient { get; set; } + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/TypeOfPayment.cs b/OpenImis.Modules/PaymentModule/Models/TypeOfPayment.cs new file mode 100644 index 00000000..6dd292f4 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Models/TypeOfPayment.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule.Models +{ + public enum TypeOfPayment + { + Cash, + MobilePhone, + BankTransfer + } +} diff --git a/OpenImis.Modules/PaymentModule/PaymentModule.cs b/OpenImis.Modules/PaymentModule/PaymentModule.cs new file mode 100644 index 00000000..763a47c0 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/PaymentModule.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using OpenImis.Modules.PaymentModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.Modules.PaymentModule +{ + public class PaymentModule : IPaymentModule + { + private IConfiguration Configuration; + private readonly IHostingEnvironment _hostingEnvironment; + private IPaymentLogic _paymentLogic; + + public PaymentModule(IConfiguration configuration, IHostingEnvironment hostingEnvironment) + { + Configuration = configuration; + _hostingEnvironment = hostingEnvironment; + } + + public IPaymentLogic GetPaymentLogic() + { + if (_paymentLogic == null) + { + _paymentLogic = new PaymentLogic(Configuration, _hostingEnvironment); + } + return _paymentLogic; + } + } +} diff --git a/OpenImis.Modules/PaymentModule/Repositories/IPaymentRepository.cs b/OpenImis.Modules/PaymentModule/Repositories/IPaymentRepository.cs new file mode 100644 index 00000000..12b54530 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Repositories/IPaymentRepository.cs @@ -0,0 +1,47 @@ +using OpenImis.Modules.PaymentModule.Models; +using OpenImis.Modules.PaymentModule.Models.Response; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace OpenImis.Modules.PaymentModule.Repositories +{ + public interface IPaymentRepository + { + string PaymentId { get; set; } + decimal ExpectedAmount { get; set; } + string ControlNum { get; set; } + string PhoneNumber { get; set; } + Language Language { get; set; } + TypeOfPayment? typeOfPayment { get; set; } + + DateTime? PaymentDate { get; set; } + decimal? PaidAmount { get; set; } + decimal? OutStAmount { get; set; } + List InsureeProducts { get; set; } + + bool SaveControlNumberRequest(string BillId, bool failed); + PostReqCNResponse PostReqControlNumber(string OfficerCode, string PaymentId, string PhoneNumber, decimal ExpectedAmount, List products, string controlNumber = null, bool acknowledge = false, bool error = false); + bool UpdatePaymentTransferFee(string paymentId, decimal TransferFee, TypeOfPayment typeOfPayment); + decimal determineTransferFee(decimal expectedAmount, TypeOfPayment typeOfPayment); + decimal determineTransferFeeReverse(decimal expectedAmount, TypeOfPayment typeOfPayment); + int GetReqControlNumberAck(string paymentId); + int GetPaymentDataAck(string paymentId, string controlNumber); + decimal GetToBePaidAmount(decimal ExpectedAmount, decimal TransferFee); + DataMessage SaveIntent(IntentOfPay _intent, int? errorNumber = 0, string errorMessage = null); + DataMessage SaveControlNumber(string ControlNumber, bool failed); + DataMessage SaveControlNumber(ControlNumberResp model, bool failed); + bool CheckControlNumber(string PaymentID, string ControlNumber); + void UpdateControlNumberStatus(string ControlNumber, CnStatus status); + DataMessage SaveControlNumberAkn(bool error_occured, string Comment); + DataMessage SavePayment(PaymentData payment, bool failed = false); + DataMessage MatchPayment(MatchModel model); + Task GetControlNumbers(string PaymentIds); + void GetPaymentInfo(string Id); + List GetPaymentIdsForSms(); + void UnMatchedSmsSent(int Id); + void MatchedSmsSent(); + string GetPaymentId(string ControlNumber); + } +} diff --git a/OpenImis.Modules/PaymentModule/Repositories/PaymentRepository.cs b/OpenImis.Modules/PaymentModule/Repositories/PaymentRepository.cs new file mode 100644 index 00000000..08a41ff9 --- /dev/null +++ b/OpenImis.Modules/PaymentModule/Repositories/PaymentRepository.cs @@ -0,0 +1,717 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; +using OpenImis.DB.SqlServer.DataHelper; +using OpenImis.Modules.PaymentModule.Helpers; +using OpenImis.Modules.PaymentModule.Models; +using OpenImis.Modules.PaymentModule.Models.Response; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace OpenImis.Modules.PaymentModule.Repositories +{ + public class PaymentRepository : IPaymentRepository + { + private IConfiguration Configuration; + private readonly IHostingEnvironment _hostingEnvironment; + protected DataHelper dh; + + public string PaymentId { get; set; } + public decimal ExpectedAmount { get; set; } + public string ControlNum { get; set; } + public string PhoneNumber { get; set; } + public Language Language { get; set; } + public TypeOfPayment? typeOfPayment { get; set; } + + public DateTime? PaymentDate { get; set; } + public decimal? PaidAmount { get; set; } + public decimal? OutStAmount { get; set; } + public List InsureeProducts { get; set; } + + + public PaymentRepository(IConfiguration configuration, IHostingEnvironment hostingEnvironment) + { + Configuration = configuration; + _hostingEnvironment = hostingEnvironment; + dh = new DataHelper(configuration); + } + + public bool SaveControlNumberRequest(string BillId, bool failed) + { + + SqlParameter[] sqlParameters = { + new SqlParameter("@PaymentID", BillId), + new SqlParameter("@Failed", failed) + }; + + try + { + var data = dh.ExecProcedure("uspRequestGetControlNumber", sqlParameters); + GetPaymentInfo(BillId); + } + catch (Exception e) + { + throw e; + } + + return true; + } + + public virtual PostReqCNResponse PostReqControlNumber(string OfficerCode, string PaymentId, string PhoneNumber, decimal ExpectedAmount, List products, string controlNumber = null, bool acknowledge = false, bool error = false) + { + bool result = SaveControlNumberRequest(PaymentId, error); + string ctrlNumber = null; + + //BEGIN Temporary Control Number Generator(Simulation For Testing Only) + // var randomNumber = new Random().Next(100000, 999999); + + //if(randomNumber%2 == 0) + //{ + // ctrlNumber = randomNumber.ToString(); + //} + //END Temporary + + PostReqCNResponse response = new PostReqCNResponse() + { + + ControlNumber = ctrlNumber, + Posted = true, + ErrorCode = 0, + Assigned = error + }; + + return response; + } + + public virtual bool UpdatePaymentTransferFee(string paymentId, decimal TransferFee, TypeOfPayment typeOfPayment) + { + + var sSQL = @"UPDATE tblPayment SET TypeOfPayment = @TypeOfPayment,TransferFee = @TransferFee WHERE PaymentID = @paymentId"; + + SqlParameter[] parameters = { + new SqlParameter("@paymentId", paymentId), + new SqlParameter("@TransferFee", TransferFee), + new SqlParameter("@TypeOfPayment", Enum.GetName(typeof(TypeOfPayment),typeOfPayment)) + }; + + try + { + dh.Execute(sSQL, parameters, CommandType.Text); + + return true; + } + catch (Exception) + { + return false; + } + + } + + public virtual decimal determineTransferFee(decimal expectedAmount, TypeOfPayment typeOfPayment) + { + return 0; + } + + public virtual decimal determineTransferFeeReverse(decimal expectedAmount, TypeOfPayment typeOfPayment) + { + return 0; + } + + public virtual int GetReqControlNumberAck(string paymentId) + { + return 0; + + } + public virtual int GetPaymentDataAck(string paymentId, string controlNumber) + { + return 0; + } + + public virtual decimal GetToBePaidAmount(decimal ExpectedAmount, decimal TransferFee) + { + decimal amount = ExpectedAmount - TransferFee; + return Math.Round(amount, 2); + } + + public DataMessage SaveIntent(IntentOfPay _intent, int? errorNumber = 0, string errorMessage = null) + { + var Proxyfamily = LocalDefault.FamilyMembers(Configuration); + + List policies = new List(); + + if (_intent.policies != null) + { + policies = _intent.policies; + } + + XElement PaymentIntent = new XElement("PaymentIntent", + new XElement("Header", + new XElement("OfficerCode", _intent.enrolment_officer_code), + new XElement("RequestDate", _intent.request_date), + new XElement("PhoneNumber", _intent.phone_number), + new XElement("LanguageName", _intent.language), + new XElement("AuditUserId", -1) + ), + new XElement("Details", + policies.Select(x => + + new XElement("Detail", + new XElement("InsuranceNumber", x.insurance_number), + new XElement("ProductCode", x.insurance_product_code), + new XElement("EnrollmentDate", DateTime.UtcNow), + new XElement("IsRenewal", x.IsRenewal()) + ) + ) + ), + new XElement("ProxySettings", + new XElement("AdultMembers", Proxyfamily.Adults), + new XElement("ChildMembers", Proxyfamily.Children), + new XElement("OAdultMembers", Proxyfamily.OtherAdults), + new XElement("OChildMembers", Proxyfamily.OtherChildren) + ) + ); + + SqlParameter[] sqlParameters = { + new SqlParameter("@Xml", PaymentIntent.ToString()), + new SqlParameter("@ErrorNumber",errorNumber), + new SqlParameter("@ErrorMsg",errorMessage), + new SqlParameter("@PaymentID", SqlDbType.Int){Direction = ParameterDirection.Output }, + new SqlParameter("@ExpectedAmount", SqlDbType.Decimal){Direction = ParameterDirection.Output }, + new SqlParameter("@ProvidedAmount",_intent.amount_to_be_paid), + new SqlParameter("@PriorEnrollment",LocalDefault.PriorEnrolmentRequired(Configuration)) + }; + + DataMessage message; + + try + { + bool error = true; + var data = dh.ExecProcedure("uspInsertPaymentIntent", sqlParameters); + + var rv = int.Parse(data[2].Value.ToString()); + + if (rv == 0) + { + error = false; + } + + DataTable dt = new DataTable(); + dt.Clear(); + dt.Columns.Add("internal_identifier"); + dt.Columns.Add("control_number"); + + DataRow rw = dt.NewRow(); + var PaymentId = data[0].Value.ToString(); + rw["internal_identifier"] = PaymentId; + + dt.Rows.Add(rw); + + ExpectedAmount = decimal.Parse(data[1].Value.ToString()); + + var languages = LocalDefault.PrimaryLangReprisantations(Configuration); + + if (_intent.language == null || languages.Contains(_intent.language.ToLower())) + { + Language = Language.Primary; + } + else + { + Language = Language.Secondary; + } + + message = new SaveIntentResponse(rv, error, dt, (int)Language).Message; + GetPaymentInfo(PaymentId); + } + catch (Exception e) + { + + message = new SaveIntentResponse(e).Message; + } + + return message; + } + + public DataMessage SaveControlNumber(string ControlNumber, bool failed) + { + SqlParameter[] sqlParameters = { + new SqlParameter("@PaymentID", PaymentId), + new SqlParameter("@ControlNumber", ControlNumber), + new SqlParameter("@Failed", failed) + }; + + DataMessage message; + + try + { + var data = dh.ExecProcedure("uspReceiveControlNumber", sqlParameters); + message = new CtrlNumberResponse(int.Parse(data[0].Value.ToString()), false, (int)Language).Message; + GetPaymentInfo(PaymentId); + } + catch (Exception e) + { + message = new CtrlNumberResponse(e).Message; + } + + return message; + } + + public DataMessage SaveControlNumber(ControlNumberResp model, bool failed) + { + SqlParameter[] sqlParameters = { + new SqlParameter("@PaymentID", model.internal_identifier), + new SqlParameter("@ControlNumber", model.control_number), + new SqlParameter("@Failed", failed) + }; + + DataMessage message; + + try + { + var data = dh.ExecProcedure("uspReceiveControlNumber", sqlParameters); + message = new CtrlNumberResponse(int.Parse(data[0].Value.ToString()), false, (int)Language).Message; + GetPaymentInfo(model.internal_identifier); + } + catch (Exception e) + { + message = new CtrlNumberResponse(e).Message; + } + + return message; + } + + public bool CheckControlNumber(string PaymentID, string ControlNumber) + { + var sSQL = @"SELECT * FROM tblControlNumber WHERE PaymentID != @PaymentID AND ControlNumber = @ControlNumber"; + + SqlParameter[] parameters = { + new SqlParameter("@PaymentID", PaymentID), + new SqlParameter("@ControlNumber", ControlNumber) + }; + bool result = false; + + try + { + var data = dh.GetDataTable(sSQL, parameters, CommandType.Text); + if (data.Rows.Count > 0) + { + result = true; + } + //GetPaymentInfo(PaymentID); + } + catch (Exception) + { + return false; + } + + return result; + } + + public void UpdateControlNumberStatus(string ControlNumber, CnStatus status) + { + + SqlParameter[] sqlParameters = { + new SqlParameter("@ControlNumber", ControlNumber) + }; + + switch (status) + { + case CnStatus.Sent: + break; + case CnStatus.Acknowledged: + dh.ExecProcedure("uspAcknowledgeControlNumber", sqlParameters); + break; + case CnStatus.Issued: + dh.ExecProcedure("uspIssueControlNumber", sqlParameters); + break; + case CnStatus.Paid: + dh.ExecProcedure("uspPaidControlNumber", sqlParameters); + break; + case CnStatus.Rejected: + break; + default: + break; + } + } + + public DataMessage SaveControlNumberAkn(bool error_occured, string Comment) + { + XElement CNAcknowledgement = new XElement("ControlNumberAcknowledge", + new XElement("PaymentID", PaymentId), + new XElement("Success", Convert.ToInt32(!error_occured)), + new XElement("Comment", Comment) + ); + + SqlParameter[] sqlParameters = { + new SqlParameter("@Xml",CNAcknowledgement.ToString()) + }; + + + DataMessage message; + + try + { + var data = dh.ExecProcedure("uspAcknowledgeControlNumberRequest", sqlParameters); + message = new SaveAckResponse(int.Parse(data[0].Value.ToString()), false, (int)Language).Message; + GetPaymentInfo(PaymentId); + } + catch (Exception e) + { + + message = new SaveAckResponse(e).Message; + } + + return message; + } + + public DataMessage SavePayment(PaymentData payment, bool failed = false) + { + int? isRenewal = null; + + if ((payment.renewal != null)) + { + isRenewal = (int)payment.renewal; + } + + var paymentId = GetPaymentId(payment.control_number); + + XElement PaymentIntent = new XElement("PaymentData", + new XElement("PaymentID", paymentId), + new XElement("PaymentDate", payment.payment_date), + new XElement("ReceiveDate", payment.received_date), + new XElement("ControlNumber", payment.control_number), + new XElement("Amount", payment.received_amount), + new XElement("ReceiptNo", payment.receipt_identification), + new XElement("TransactionNo", payment.transaction_identification), + new XElement("PhoneNumber", payment.payment_origin), + new XElement("PaymentOrigin", payment.payment_origin), + new XElement("OfficerCode", payment.enrolment_officer_code), + new XElement("LanguageName", payment.language), + new XElement("Detail", + new XElement("InsureeNumber", payment.insurance_number), + new XElement("ProductCode", payment.insurance_product_code), + new XElement("IsRenewal", isRenewal) + ) + ); + + + SqlParameter[] sqlParameters = { + new SqlParameter("@Xml", PaymentIntent.ToString()), + new SqlParameter("@Payment_ID",SqlDbType.BigInt){Direction = ParameterDirection.Output } + }; + + DataMessage message; + + try + { + var data = dh.ExecProcedure("uspReceivePayment", sqlParameters); + message = new SavePayResponse(int.Parse(data[1].Value.ToString()), false, (int)Language).Message; + GetPaymentInfo(data[0].Value.ToString()); + + } + catch (Exception e) + { + message = new SavePayResponse(e).Message; + } + + return message; + } + + public DataMessage MatchPayment(MatchModel model) + { + SqlParameter[] sqlParameters = { + new SqlParameter("@PaymentID", model.internal_identifier), + new SqlParameter("@AuditUserId", model.audit_user_id) + }; + + DataMessage message; + + try + { + DataSet data = dh.FillDataSet("uspMatchPayment", sqlParameters, CommandType.StoredProcedure); + + //bool error = false; + DataTable dt = new DataTable(); + + if (data.Tables.Count > 0) + { + dt = data.Tables[data.Tables.Count - 1]; + } + + message = new MatchPayResponse(dh.ReturnValue, false, dt, (int)Language).Message; + if (model.internal_identifier != null && !message.ErrorOccured) + { + GetPaymentInfo(model.internal_identifier.ToString()); + } + } + catch (Exception e) + { + message = new ImisApiResponse(e).Message; + } + + return message; + } + + public async Task GetControlNumbers(string PaymentIds) + { + var sSQL = String.Format(@"SELECT PaymentID,ControlNumber + FROM tblControlNumber WHERE PaymentID IN({0})", PaymentIds); + + SqlParameter[] sqlParameters = { + + }; + + DataMessage dt = new DataMessage(); + try + { + DataTable data = dh.GetDataTable(sSQL, sqlParameters, CommandType.Text); + data.Columns["PaymentID"].ColumnName = "internal_identifier"; + data.Columns["ControlNumber"].ColumnName = "control_number"; + + var ids = PaymentIds.Split(","); + + if (ids.Distinct().Count() == data.Rows.Count) + { + dt = new RequestedCNResponse(0, false, data, (int)Language).Message; + } + else + { + var _datastring = JsonConvert.SerializeObject(data); + var _data = JsonConvert.DeserializeObject>(_datastring); + var _ids = _data.Select(x => x.internal_identifier).ToArray(); + + DataTable invalid = new DataTable(); + invalid.Clear(); + invalid.Columns.Add("internal_identifier"); + invalid.Columns.Add("control_number"); + + foreach (var id in ids.Except(_ids)) + { + DataRow rw = invalid.NewRow(); + + rw["internal_identifier"] = id; + + invalid.Rows.Add(rw); + } + + dt = new RequestedCNResponse(2, true, invalid, (int)Language).Message; + } + } + catch (Exception e) + { + throw e; + } + + return dt; + } + + public void GetPaymentInfo(string Id) + { + var sSQL = @"SELECT tblPayment.PaymentID, tblPayment.ExpectedAmount,tblPayment.LanguageName,tblPayment.TypeOfPayment, tblPaymentDetails.ExpectedAmount AS ExpectedDetailAmount, + tblPayment.ReceivedAmount, tblPayment.PaymentDate, tblInsuree.LastName, tblInsuree.OtherNames,tblPaymentDetails.InsuranceNumber,tblPayment.PhoneNumber, + tblProduct.ProductName, tblPaymentDetails.ProductCode, tblPolicy.ExpiryDate, tblPolicy.EffectiveDate,tblControlNumber.ControlNumber,tblPolicy.PolicyStatus, tblPolicy.PolicyValue - ISNULL(mp.PrPaid,0) Outstanding + FROM tblControlNumber + RIGHT OUTER JOIN tblInsuree + RIGHT OUTER JOIN tblProduct + RIGHT OUTER JOIN tblPayment + INNER JOIN tblPaymentDetails + ON tblPayment.PaymentID = tblPaymentDetails.PaymentID + ON tblProduct.ProductCode = tblPaymentDetails.ProductCode + ON tblInsuree.CHFID = tblPaymentDetails.InsuranceNumber + ON tblControlNumber.PaymentID = tblPayment.PaymentID + LEFT OUTER JOIN tblPremium + LEFT OUTER JOIN tblPolicy + LEFT OUTER JOIN ( + select P.PolicyID PolID, SUM(P.Amount) PrPaid from tblpremium P inner join tblPaymentDetails PD ON PD.PremiumID = P.PremiumId INNER JOIN tblPayment Pay ON Pay.PaymentID = PD.PaymentID where P.ValidityTo IS NULL AND Pay.PaymentStatus = 5 GROUP BY P.PolicyID + ) MP ON MP.PolID = tblPolicy.PolicyID + ON tblPremium.PolicyID = tblPolicy.PolicyID + ON tblPaymentDetails.PremiumID = tblPremium.PremiumId + WHERE (tblPayment.PaymentID = @PaymentID) AND (tblProduct.ValidityTo IS NULL) AND (tblInsuree.ValidityTo IS NULL)"; + + SqlParameter[] parameters = { + new SqlParameter("@PaymentID", Id) + }; + + try + { + var data = dh.GetDataTable(sSQL, parameters, CommandType.Text); + + if (data.Rows.Count > 0) + { + var row1 = data.Rows[0]; + PaymentId = Id; + ControlNum = row1["ControlNumber"] != System.DBNull.Value ? Convert.ToString(row1["ControlNumber"]) : null; + ExpectedAmount = row1["ExpectedAmount"] != System.DBNull.Value ? Convert.ToDecimal(row1["ExpectedAmount"]) : 0; + + var language = row1["LanguageName"] != System.DBNull.Value ? Convert.ToString(row1["LanguageName"]) : "en"; + var languages = LocalDefault.PrimaryLangReprisantations(Configuration); + + if (language == null || languages.Contains(language.ToLower())) + { + Language = Language.Primary; + } + else + { + Language = Language.Secondary; + } + typeOfPayment = row1["TypeOfPayment"] != System.DBNull.Value ? (TypeOfPayment?)Enum.Parse(typeof(TypeOfPayment), Convert.ToString(row1["TypeOfPayment"]), true) : null; + + PhoneNumber = row1["PhoneNumber"] != System.DBNull.Value ? Convert.ToString(row1["PhoneNumber"]) : null; + PaymentDate = (DateTime?)(row1["PaymentDate"] != System.DBNull.Value ? row1["PaymentDate"] : null); + PaidAmount = (decimal?)(row1["ReceivedAmount"] != System.DBNull.Value ? row1["ReceivedAmount"] : null); + OutStAmount = (decimal?)(row1["Outstanding"] != System.DBNull.Value ? row1["Outstanding"] : null); + InsureeProducts = new List(); + + for (int i = 0; i < data.Rows.Count; i++) + { + var rw = data.Rows[i]; + + bool active = false; + + if (rw["PolicyStatus"] != System.DBNull.Value && Convert.ToInt32(rw["PolicyStatus"]) == 2) + { + active = true; + } + + var othernames = rw["OtherNames"] != System.DBNull.Value ? Convert.ToString(rw["OtherNames"]) : null; + var lastname = rw["LastName"] != System.DBNull.Value ? Convert.ToString(rw["LastName"]) : null; + InsureeProducts.Add( + new InsureeProduct() + { + InsureeNumber = rw["InsuranceNumber"] != System.DBNull.Value ? Convert.ToString(rw["InsuranceNumber"]) : null, + InsureeName = othernames + " " + lastname, + ProductName = rw["ProductName"] != System.DBNull.Value ? Convert.ToString(rw["ProductName"]) : null, + ProductCode = rw["ProductCode"] != System.DBNull.Value ? Convert.ToString(rw["ProductCode"]) : null, + ExpiryDate = (DateTime?)(rw["ExpiryDate"] != System.DBNull.Value ? rw["ExpiryDate"] : null), + EffectiveDate = (DateTime?)(rw["EffectiveDate"] != System.DBNull.Value ? rw["EffectiveDate"] : null), + PolicyActivated = active, + ExpectedProductAmount = rw["ExpectedDetailAmount"] != System.DBNull.Value ? Convert.ToDecimal(rw["ExpectedDetailAmount"]) : 0 + } + ); + } + } + else + { + throw new DataException("3-Wrong Control Number"); + } + } + catch (Exception e) + { + throw e; + } + } + + public List GetPaymentIdsForSms() + { + var sSQl = @"SELECT tblPayment.PaymentID,tblPayment.DateLastSMS,tblPayment.MatchedDate + FROM tblControlNumber + RIGHT OUTER JOIN tblInsuree + RIGHT OUTER JOIN tblProduct + RIGHT OUTER JOIN tblPayment + INNER JOIN tblPaymentDetails + ON tblPayment.PaymentID = tblPaymentDetails.PaymentID + ON tblProduct.ProductCode = tblPaymentDetails.ProductCode + ON tblInsuree.CHFID = tblPaymentDetails.InsuranceNumber + ON tblControlNumber.PaymentID = tblPayment.PaymentID + LEFT OUTER JOIN tblPremium + LEFT OUTER JOIN tblPolicy + ON tblPremium.PolicyID = tblPolicy.PolicyID + ON tblPaymentDetails.PremiumID = tblPremium.PremiumId + WHERE (tblProduct.ValidityTo IS NULL) AND (tblInsuree.ValidityTo IS NULL) + AND tblPayment.PaymentStatus >= 4"; + + SqlParameter[] parameters = { }; + + try + { + var data = dh.GetDataTable(sSQl, parameters, CommandType.Text); + List Ids = null; + if (data.Rows.Count > 0) + { + var jsonString = JsonConvert.SerializeObject(data); + Ids = JsonConvert.DeserializeObject>(jsonString); + } + + return Ids; + } + catch (Exception e) + { + throw e; + } + } + + public void UnMatchedSmsSent(int Id) + { + var sSQL = @"UPDATE tblPayment + SET DateLastSMS = @Today + WHERE PaymentID = @PaymentID;"; + + SqlParameter[] parameters = { + new SqlParameter("@PaymentID", Id), + new SqlParameter("@Today",DateTime.UtcNow) + }; + + try + { + dh.Execute(sSQL, parameters, CommandType.Text); + } + catch (Exception) + { + throw; + } + } + + public void MatchedSmsSent() + { + var sSQL = @"UPDATE tblPayment + SET DateLastSMS = @Today + WHERE PaymentID = @PaymentID;"; + + SqlParameter[] parameters = { + new SqlParameter("@PaymentID", PaymentId), + new SqlParameter("@Today",DateTime.UtcNow) + }; + + try + { + dh.Execute(sSQL, parameters, CommandType.Text); + } + catch (Exception) + { + throw; + } + } + + public string GetPaymentId(string ControlNumber) + { + var sSQL = @"SELECT PaymentID FROM tblControlNumber WHERE ControlNumber = @ControlNumber"; + + SqlParameter[] parameters = { + new SqlParameter("@ControlNumber", ControlNumber) + }; + + string paymentId = string.Empty; + + try + { + var data = dh.GetDataTable(sSQL, parameters, CommandType.Text); + if (data.Rows.Count > 0) + { + var row = data.Rows[0]; + paymentId = row["PaymentID"].ToString(); + } + } + catch (Exception) + { + return string.Empty; + } + + return paymentId; + } + } +} diff --git a/OpenImis.RestApi/Controllers/PaymentController.cs b/OpenImis.RestApi/Controllers/PaymentController.cs new file mode 100644 index 00000000..23505e54 --- /dev/null +++ b/OpenImis.RestApi/Controllers/PaymentController.cs @@ -0,0 +1,229 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Cors; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using OpenImis.Modules; +using OpenImis.Modules.PaymentModule.Helpers.Extensions; +using OpenImis.Modules.PaymentModule.Models; +using OpenImis.Modules.PaymentModule.Models.Response; + +namespace OpenImis.RestApi.Controllers +{ + [Route("api/")] + [ApiController] + [EnableCors("AllowSpecificOrigin")] + public class PaymentController : Controller + { + private readonly IConfiguration _configuration; + private readonly IImisModules _imisModules; + public readonly IHostingEnvironment _hostingEnvironment; + + public PaymentController(IConfiguration configuration, IHostingEnvironment hostingEnvironment, IImisModules imisModules) + { + _configuration = configuration; + _hostingEnvironment = hostingEnvironment; + _imisModules = imisModules; + } + + //[Authorize(Roles = "PaymentAdd")] + [HttpPost] + [Route("MatchPayment")] + public virtual IActionResult MatchPayment([FromBody]MatchModel model) + { + if (!ModelState.IsValid) + return BadRequest(new { error_occured = true, error_message = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage }); + + try + { + var response = _imisModules.GetPaymentModule().GetPaymentLogic().MatchPayment(model); + return Ok(response); + } + catch (Exception) + { + return BadRequest(new { error_occured = true, error_message = "Unknown Error Occured" }); + } + } + + //Recieve Payment from Operator/ + //[Authorize(Roles = "PaymentAdd")] + [HttpPost] + [Route("GetControlNumber")] + //[ProducesResponseType(typeof(GetControlNumberResp), 200)] + [ProducesResponseType(typeof(ErrorResponseV2), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public virtual async Task GetControlNumber([FromBody]IntentOfPay intent) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + + if (intent != null) + { + var resp = await _imisModules.GetPaymentModule().GetPaymentLogic().SaveIntent(intent, error.GetErrorNumber(), error.GetErrorMessage()); + return BadRequest(new ErrorResponseV2() { error_occured = true, error_message = error }); + } + else + { + return BadRequest(new ErrorResponseV2() { error_occured = true, error_message = "10-Uknown type of payment" }); + } + + } + + try + { + var response = await _imisModules.GetPaymentModule().GetPaymentLogic().SaveIntent(intent); + + AssignedControlNumber data = (AssignedControlNumber)response.Data; + + return Ok(new GetControlNumberResp() { error_occured = response.ErrorOccured, error_message = response.MessageValue, internal_identifier = data.internal_identifier, control_number = data.control_number }); + + } + catch (Exception e) + { + return BadRequest(new ErrorResponseV2() { error_occured = true, error_message = e.Message }); + } + } + + //[Authorize(Roles = "PaymentAdd")] + [HttpPost] + [Route("PostReqControlNumberAck")] + [ProducesResponseType(typeof(void), 200)] + [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public virtual IActionResult PostReqControlNumberAck([FromBody]Acknowledgement model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new ErrorResponse() { error_message = error }); + } + + try + { + var response = _imisModules.GetPaymentModule().GetPaymentLogic().SaveAcknowledgement(model); + if (response.Code == 0) + { + return Ok(); + } + else + { + return BadRequest(new ErrorResponse() { error_message = response.MessageValue }); + } + + } + catch (Exception) + { + return BadRequest(new ErrorResponse() { error_message = "Unknown Error Occured" }); + } + } + + //[Authorize(Roles = "PaymentAdd")] + [HttpPost] + [Route("GetReqControlNumber")] + [ProducesResponseType(typeof(void), 200)] + [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public virtual IActionResult GetReqControlNumber([FromBody]ControlNumberResp model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new ErrorResponse() { error_message = error }); + } + + try + { + var response = _imisModules.GetPaymentModule().GetPaymentLogic().SaveControlNumber(model); + if (response.Code == 0) + { + return Ok(); + } + else + { + return BadRequest(new ErrorResponse() { error_message = response.MessageValue }); + } + + } + catch (Exception) + { + return BadRequest(new { error_occured = true, error_message = "Unknown Error Occured" }); + } + + } + + //[Authorize(Roles = "PaymentAdd")] + [HttpPost] + [Route("GetPaymentData")] + [ProducesResponseType(typeof(void), 200)] + [ProducesResponseType(typeof(PaymentDataBadResp), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public virtual async Task GetPaymentData([FromBody]PaymentData model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new PaymentDataBadResp() { error_message = error }); + } + + try + { + var response = await _imisModules.GetPaymentModule().GetPaymentLogic().SavePayment(model); + + if (response.Code == 0) + { + return Ok(); + } + else + { + return BadRequest(new PaymentDataBadResp() { error_message = response.MessageValue }); + } + + } + catch (Exception) + { + return BadRequest(new PaymentDataBadResp() { error_message = "Unknown Error Occured" }); + } + + } + + //[Authorize(Roles = "PaymentSearch")] + [HttpPost] + [Route("GetAssignedControlNumbers")] + [ProducesResponseType(typeof(AsignedControlNumbersResponse), 200)] + [ProducesResponseType(typeof(ErrorResponseV2), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public virtual async Task GetAssignedControlNumbers([FromBody]PaymentRequest requests) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new ErrorResponseV2() { error_occured = true, error_message = error }); + } + + try + { + var response = await _imisModules.GetPaymentModule().GetPaymentLogic().GetControlNumbers(requests); + + if (response.Code == 0) + { + var controlNumbers = (List)response.Data; + return Ok(new AsignedControlNumbersResponse() { error_occured = response.ErrorOccured, assigned_control_numbers = controlNumbers }); + } + else + { + return BadRequest(new ErrorResponseV2() { error_occured = true, error_message = response.MessageValue }); + } + + } + catch (Exception) + { + return BadRequest(new ErrorResponseV2() { error_occured = true, error_message = "Unknown Error Occured" }); + } + } + } +} \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/Headers.cs b/OpenImis.RestApi/Escape/Sms/Headers.cs new file mode 100644 index 00000000..68a01bb4 --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/Headers.cs @@ -0,0 +1,63 @@ +using Microsoft.Extensions.Configuration; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Security.Cryptography; +using System.Threading.Tasks; + +namespace ImisRestApi.Chanels.Sms +{ + public class Headers + { + private Dictionary OutputHeaders = new Dictionary(); + private string _userId; + private string _messageBody; + private string _privateKey; + private string _requestType; + private Type thisType; + + public Headers(string userId,string privateKey, string messageBody, string requestType) + { + _userId = userId; + _messageBody = messageBody; + _privateKey = privateKey; + _requestType = requestType; + thisType = this.GetType(); + } + public Dictionary GetHeaders(Dictionary requiredheaders) { + + foreach (var requiredheader in requiredheaders) + { + + MethodInfo _method = thisType.GetMethod(requiredheader.Value); + var headerVal =_method.Invoke(this,null); + + OutputHeaders.Add(requiredheader.Key, headerVal.ToString()); + } + + return OutputHeaders; + } + + public string UserId() + { + return _userId; + } + + public string HashMessage1() + { + var encoding = new System.Text.ASCIIEncoding(); + byte[] keyBytes = encoding.GetBytes(_privateKey); + byte[] messageBytes = encoding.GetBytes(_messageBody); + + byte[] hashBytes = new HMACSHA256(keyBytes).ComputeHash(messageBytes); + string hashmessage = Convert.ToBase64String(hashBytes); + + return hashmessage; + } + + public string RequestType() { + return _requestType; + } + } +} diff --git a/OpenImis.RestApi/Escape/Sms/Strings/ControlNumberAssigned.txt b/OpenImis.RestApi/Escape/Sms/Strings/ControlNumberAssigned.txt new file mode 100644 index 00000000..1929c9f1 --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/Strings/ControlNumberAssigned.txt @@ -0,0 +1 @@ +The control number {0} was assigned for the request issued on {1} at {2} for payment of the set of policies containing the family/group {3} - {4} with the insurance product {5} - {6}. The amount of payment associated with the request is {7}. \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/Strings/ControlNumberAssignedV2.txt b/OpenImis.RestApi/Escape/Sms/Strings/ControlNumberAssignedV2.txt new file mode 100644 index 00000000..7185ec8b --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/Strings/ControlNumberAssignedV2.txt @@ -0,0 +1 @@ +The control number {0} was assigned for the request issued on {1} at {2} for payment of the set of policies containing the family/group {3}-{4} with the insurance product {5}-{6} and {8} others. The amount of payment associated with the request is {7}. \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/Strings/ControlNumberError.txt b/OpenImis.RestApi/Escape/Sms/Strings/ControlNumberError.txt new file mode 100644 index 00000000..5c3dff44 --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/Strings/ControlNumberError.txt @@ -0,0 +1 @@ +The control number {0} cannot be assigned for the request issued on {1} at {2} for payment of the set of policies containing the family/group {3} with the insurance product {4}.The reason is {5} \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/Strings/ControlNumberErrorV2.txt b/OpenImis.RestApi/Escape/Sms/Strings/ControlNumberErrorV2.txt new file mode 100644 index 00000000..a5df7ad3 --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/Strings/ControlNumberErrorV2.txt @@ -0,0 +1 @@ +The control number {0} cannot be assigned for the request issued on {1} at {2} for payment of the set of policies containing the family/group {3} with the insurance product {4} and {6} others. The reason is {5} \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/Strings/PaidAndActivated.txt b/OpenImis.RestApi/Escape/Sms/Strings/PaidAndActivated.txt new file mode 100644 index 00000000..c087abc9 --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/Strings/PaidAndActivated.txt @@ -0,0 +1 @@ +The payment {0} performed on {1} for the control number {2} received and the policy for the family/group {3} - {4} with the insurance product {5} - {6} activated from the date {7} until the expiry date {8}. The allocated payment for the policy is {0}. \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/Strings/PaidAndNotActivated.txt b/OpenImis.RestApi/Escape/Sms/Strings/PaidAndNotActivated.txt new file mode 100644 index 00000000..9557d65d --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/Strings/PaidAndNotActivated.txt @@ -0,0 +1 @@ +The payment {0} performed on {1} for the control number {2} received but the policy for the family/group {3} - {4} with the insurance product {5} - {6} has not been activated.The allocated payment for the policy is {0} but still {8} should be paid for activation of the policy. \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/Strings/PaidAndNotMatched.txt b/OpenImis.RestApi/Escape/Sms/Strings/PaidAndNotMatched.txt new file mode 100644 index 00000000..d1dc411a --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/Strings/PaidAndNotMatched.txt @@ -0,0 +1 @@ +The payment {0} performed on {1} for the control number {2} received but the policies in the set containing the family/group {3} - {4} with the insurance product {5} - {6} cannot be matched for time being. \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/Strings/PaidAndNotMatchedV2.txt b/OpenImis.RestApi/Escape/Sms/Strings/PaidAndNotMatchedV2.txt new file mode 100644 index 00000000..e2086709 --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/Strings/PaidAndNotMatchedV2.txt @@ -0,0 +1 @@ +The payment {0} performed on {1} for the control number {2} received but the policies in the set containing the family/group {3} - {4} with the insurance product {5} - {6} and {7} others cannot be matched for time being. \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberAssigned.txt b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberAssigned.txt new file mode 100644 index 00000000..04028188 --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberAssigned.txt @@ -0,0 +1 @@ +fr The control number {0} was assigned for the request issued on {1} at {2} for payment of the set of policies containing the family/group {3} - {4} with the insurance product {5} - {6}. The amount of payment associated with the request is {7}. \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberAssignedV2.txt b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberAssignedV2.txt new file mode 100644 index 00000000..90e9d47e --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberAssignedV2.txt @@ -0,0 +1 @@ +fr The control number {0} was assigned for the request issued on {1} at {2} for payment of the set of policies containing the family/group {3}-{4} with the insurance product {5}-{6} and {8} others. The amount of payment associated with the request is {7}. \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberError.txt b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberError.txt new file mode 100644 index 00000000..8680578e --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberError.txt @@ -0,0 +1 @@ +fr The control number {0} cannot be assigned for the request issued on {1} at {2} for payment of the set of policies containing the family/group {3} with the insurance product {4}.The reason is {5} \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberErrorV2.txt b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberErrorV2.txt new file mode 100644 index 00000000..09a919bd --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/ControlNumberErrorV2.txt @@ -0,0 +1 @@ +fr The control number {0} cannot be assigned for the request issued on {1} at {2} for payment of the set of policies containing the family/group {3} with the insurance product {4} and {6} others. The reason is {5} \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndActivated.txt b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndActivated.txt new file mode 100644 index 00000000..39c98ea7 --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndActivated.txt @@ -0,0 +1 @@ +fr The payment {0} performed on {1} for the control number {2} received and the policy for the family/group {3} - {4} with the insurance product {5} - {6} activated from the date {7} until the expiry date {8}. The allocated payment for the policy is {0}. \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndNotActivated.txt b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndNotActivated.txt new file mode 100644 index 00000000..1879979d --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndNotActivated.txt @@ -0,0 +1 @@ +fr The payment {0} performed on {1} for the control number {2} received but the policy for the family/group {3} - {4} with the insurance product {5} - {6} has not been activated.The allocated payment for the policy is {0} but still {8} should be paid for activation of the policy. \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndNotMatched.txt b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndNotMatched.txt new file mode 100644 index 00000000..7d23d7ec --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndNotMatched.txt @@ -0,0 +1 @@ +fr The payment {0} performed on {1} for the control number {2} received but the policies in the set containing the family/group {3} - {4} with the insurance product {5} - {6} cannot be matched for time being. \ No newline at end of file diff --git a/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndNotMatchedV2.txt b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndNotMatchedV2.txt new file mode 100644 index 00000000..203d7a78 --- /dev/null +++ b/OpenImis.RestApi/Escape/Sms/StringsSecondaryLanguage/PaidAndNotMatchedV2.txt @@ -0,0 +1 @@ +fr The payment {0} performed on {1} for the control number {2} received but the policies in the set containing the family/group {3} - {4} with the insurance product {5} - {6} and {7} others cannot be matched for time being. \ No newline at end of file From 7695c22fd7862fe0638394c97287355302c4e1cd Mon Sep 17 00:00:00 2001 From: Dragos DOBRE Date: Thu, 4 Jul 2019 14:20:37 +0200 Subject: [PATCH 11/86] Fix typos --- .../PaymentModule/Helpers/Messages/PrimaryLanguage.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenImis.Modules/PaymentModule/Helpers/Messages/PrimaryLanguage.cs b/OpenImis.Modules/PaymentModule/Helpers/Messages/PrimaryLanguage.cs index be4701e9..0d49879a 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/Messages/PrimaryLanguage.cs +++ b/OpenImis.Modules/PaymentModule/Helpers/Messages/PrimaryLanguage.cs @@ -15,7 +15,7 @@ public static class PrimaryLanguage //DeleteMemberFamilyResponse public static string WrongFormatMissingIN = "Wrong Format or Missing Insurance Number of Member"; public static string INNotFount = "Insurance number of member not found"; - public static string MemberNotHead = "Mamber is head of family"; + public static string MemberNotHead = "Member is head of family"; //EditFamilyResponse public static string WrongOrMissingHeadIN = "Wrong Format or Missing Insurance Number of head."; @@ -91,7 +91,7 @@ public static class PrimaryLanguage public static string InsureeNotEnrolled = "7-Insuree not enrolled while prior enrolment mandatory."; public static string DuplicateCNAssigned = "8-Duplicated control number assigned"; public static string CantAssignCn2 = "9-Control number cannot be assigned"; - public static string UnknownPaymentType = "10-Uknown type of payment"; + public static string UnknownPaymentType = "10-Unknown type of payment"; //SavePayResponse public static string WrongOrMissingRecDate = "1-Wrong or missing receiving date"; @@ -102,6 +102,6 @@ public static class PrimaryLanguage public static string DoesntExistEO = "6-Enrolment Officer Code does not exist"; public static string DoesntExistPC = "7-Product Code Does not Exist"; public static string NoPolicyForRenewal = "8-Beneficiary has no policy of specified insurance product for renewal"; - public static string UnknownTypeOfPay = "9-Uknown type of payment"; + public static string UnknownTypeOfPay = "9-Unknown type of payment"; } } From 6a1defc0aba4ee12e58e3041fe7432383726693d Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 4 Jul 2019 16:23:54 +0200 Subject: [PATCH 12/86] OS-30: Replacing the SecondaryLanguage file with a French translation file --- .../Helpers/Messages/SecondaryLanguage.cs | 175 ++++++++++-------- 1 file changed, 97 insertions(+), 78 deletions(-) diff --git a/OpenImis.Modules/PaymentModule/Helpers/Messages/SecondaryLanguage.cs b/OpenImis.Modules/PaymentModule/Helpers/Messages/SecondaryLanguage.cs index 8b781d18..143c54ab 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/Messages/SecondaryLanguage.cs +++ b/OpenImis.Modules/PaymentModule/Helpers/Messages/SecondaryLanguage.cs @@ -6,83 +6,102 @@ namespace OpenImis.Modules.PaymentModule.Helpers.Messages { public static class SecondaryLanguage { - public static string Success = "Imefanikiwa"; - - public static string CantAssignCN = "1-Na. ya ankara imeshindikana kutotelewa na mfumo wa malipo"; - public static string DuplicateCN = "2-Na. ya ankara imejirudia"; - - public static string WrongFormatMissingIN = "Umekosea namba ya mwanachama au namba haipo"; - public static string INNotFount = "Namba ya mwanachama haipo"; - public static string MemberNotHead = "Mwanachama ni mkuu wa kaya"; - - public static string WrongOrMissingHeadIN = "Umekosea namba ya mkuu wa kaya au namba haipo"; - public static string HeadINNotFound = "Namba ya mkuu wa kaya haipo"; - public static string WrongPVillageCode = "Umekosea namba ya kijiji"; - public static string WrongCVillageCode = "Umekosea namba ya kijiji"; - public static string WrongGender = "Umekosea jinsia"; - public static string WrongConfirmationType = "Wrong confirmation type"; - public static string WrongGroupType = "Umekosea aina ya kundi"; - public static string WrongMaritalStatus = "Umekosea hali ya ndoa"; - public static string WrongEducation = "Umekosea elimu"; - public static string WrongProfession = "Umekosea elimu"; - public static string FSPCodeNotFound = "Na. ya FSP haipo"; - public static string WrongIdentificationType = "Umekosea aina ya kitambulisho"; - - public static string WrongINMember = "Umekosea namba ya mwanachama"; - public static string NotFountINMember = "Namba ya mwanachama haipo kwenye kompuyta kuu"; - public static string WrongVillageCode = "Umekosea namba ya kijiji"; - public static string WrongRelationship = "Umekosea uhusiano"; - - public static string WrongOrMissingPC = "Umekosea namba ya bidhaa au haitumiki kwenye familia husika"; - public static string WrongOrMissingPayDate = "Umekosea tarehe ya malipo"; - public static string WrongContributionCat = "Umekosea kundi la malipo"; - public static string WrongOrMissingPayType = "Umekosea aina ya malipo"; - public static string WrongOrMissingPayer = "Umekosea mlipaji"; - public static string MissingReceiptNumber = "Jaza namba ya risiti"; - public static string DuplicateReceiptNumber = "Namba ya risiti imejirudia"; - - public static string DuplicateINHead = "Namba ya mwachama imejirudia"; - public static string WrongOrMissingPVC = "Umekosea/Jaza namba ya kijiji"; - public static string WrongOrMissingGender = "Umekosea/Jaza Jinsia"; - public static string WrongFrOrMissingBd = "Jaza/Umekosea tarehe"; - public static string MissingLastName = "Jaza jina la ukoo"; - public static string MissingOtherName = "Jaza majina mengine"; - - public static string DuplicatedMemberIN = "Namba ya mwanachama imejirudia"; - - public static string WrongOrMissingEnrolDate = "Jaza/Umekosea tarehe ya kujiunga"; - public static string WrongOrMissingEOcode = "Jaza/Umekosea namba ya msimbo ya afisa mwandikishaji"; - - public static string NoMemberOfOrder = "Na ya mwanchama kwenye familia haipo"; - public static string PayIdDoesntExist = "1-Namba ya malipo haipo"; - - public static string WrongOrMissingRenDate = "Jaza/Umekosea tarehe ya kuhuisha"; - - public static string WrongInternalIdFormat = "1-Wrong format of internal identifier"; - public static string InvalidInternalId = "2-Not valid internal identifier "; - - public static string CantPostReq = "1-Maombi ya Na. ya ankara yameshindikana, jaribu tena"; - - public static string WrongFormatInsureeNo = "1-Namba ya mwanachama imekosewa"; - public static string InValidINmissingPC = "2-Umekosea namba ya mwanachama au namba ya bidhaa"; - public static string InValidEOC = "3-Umekosea namba ya msimbo ya afisa mwandikishaji"; - public static string IncompatibleEO_PC = "4-Namba ya mwanachama na namba ya bidhaa haviendani"; - public static string NoRenewalProduct = "5-Mwanachama hajajiunga na bidhaa husika"; - - public static string InsureeNoMissing = "6-Jaza namba ya mwanachama"; - public static string InsureeNotEnrolled = "7-Insuree not enrolled while prior enrolment mandatory."; - public static string DuplicateCNAssigned = "8-Umepatiwa namba ya ankara iliyojirudia, jaribu tena"; - public static string CantAssignCn2 = "9-Na. ya ankara imeshishindikana kutolewa, jaribu tena"; - public static string UnknownPaymentType = "10-Aina ya malipo uliyochagua hayapo"; - - public static string WrongOrMissingRecDate = "1-Umekosea tarehe ya kupokea"; - public static string WrongFormatInputData = "2-Umekosea taarifa uliyojaza"; - public static string WrongControlNumber = "3-Umekosea Na. ya ankara"; - public static string WrongAmount = "4-Umekosea kiasi"; - public static string DuplicatePayAmount = "5-Umerudia malipo"; - public static string DoesntExistEO = "6-Namba ya msimbo ya afisa mwandikishaji haipo"; - public static string DoesntExistPC = "7-Namba ya bidhaa haipo"; - public static string NoPolicyForRenewal = "8-Mwanachama hajajiunga na bidhaa husika"; - public static string UnknownTypeOfPay = "9-Aina ya malipo uliyochagua haipo"; + public static string Success = "Succès"; + + //CtrlNumberResponse + public static string CantAssignCN = "1-Le numéro de contrôle ne peut pas être attribué par la passerelle de paiement externe"; + public static string DuplicateCN = "2-Numéro de contrôle en double"; + + //DeleteMemberFamilyResponse + public static string WrongFormatMissingIN = "Mauvais format ou numéro d'assurance manquant"; + public static string INNotFount = "Numéro d'assurance du membre non trouvé"; + public static string MemberNotHead = "Le membre est chef de famille"; + + //EditFamilyResponse + public static string WrongOrMissingHeadIN = "Mauvais format ou numéro d'assurance manquant"; + public static string HeadINNotFound = "Numéro d'assurance du chef de famille non trouvé"; + public static string WrongPVillageCode = "Mauvais code de village permanent"; + public static string WrongCVillageCode = "Code du village actuel incorrect"; + public static string WrongGender = "Mauvais genre"; + public static string WrongConfirmationType = "Mauvais type de confirmation"; + public static string WrongGroupType = "Mauvais type de groupe"; + public static string WrongMaritalStatus = "Mauvais type d'état matrimonial"; + public static string WrongEducation = "Mauvais type d'éducation"; + public static string WrongProfession = "Mauvais type de profession"; + public static string FSPCodeNotFound = "Code FSP non trouvé"; + public static string WrongIdentificationType = "Mauvais type d'identification"; + + //EditMemberFamilyResponse + public static string WrongINMember = "Mauvais format du numéro d'assurance du membre"; + public static string NotFountINMember = "Numéro d'assurance du membre non trouvé"; + public static string WrongVillageCode = "Code du village actuel incorrect"; + public static string WrongRelationship = "Mauvais type de relation"; + + //EnterContributionResponse + public static string WrongOrMissingPC = "Code de produit incorrect ou manquant (non existant ou non applicable à la famille / groupe)"; + public static string WrongOrMissingPayDate = "Date de paiement erronée ou manquante"; + public static string WrongContributionCat = "Mauvaise catégorie de contribution"; + public static string WrongOrMissingPayType = "Type de paiement incorrect ou manquant"; + public static string WrongOrMissingPayer = "Mauvais payeur ou manquant"; + public static string MissingReceiptNumber = "Numéro de reçu manquant"; + public static string DuplicateReceiptNumber = "Numéro de reçu dupliqué"; + + //EnterFamilyResponse + public static string DuplicateINHead = "Numéro d'assurance du chef de famille dupliqué"; + public static string WrongOrMissingPVC = "Code de village permanent incorrect ou manquant"; + public static string WrongOrMissingGender = "Genre incorrect ou manquant"; + public static string WrongFrOrMissingBd = "Mauvais format ou date de naissance manquante."; + public static string MissingLastName = "Absence du nom de famille"; + public static string MissingOtherName = "Absence des prénoms"; + + //EnterMemberFamilyResponse + public static string DuplicatedMemberIN = "Numéro d'assurance du membre dupliqué"; + + //EnterPolicyResponse + public static string WrongOrMissingEnrolDate = "Date d'inscription incorrecte ou manquante"; + public static string WrongOrMissingEOcode = "Code du responsable d'inscription incorrect ou manquant (non existant ou non applicable à la famille / groupe)"; + + //GetCoverageResponse + + //GetFamilyResponse + + //GetMemberFamilyResponse + public static string NoMemberOfOrder = "Aucun membre du numéro de commande spécifié dans la famille / groupe"; + + //MatchPayResponse + public static string PayIdDoesntExist = "Le paymentId n'existe pas"; + + //RenewPolicyResponse + public static string WrongOrMissingRenDate = "Date de renouvellement incorrecte ou manquante"; + + //RequestedCNResponse + public static string WrongInternalIdFormat = "Mauvais format de l'identifiant interne"; + public static string InvalidInternalId = "Identifiant interne non valide"; + + //SaveAckResponse + public static string CantPostReq = "La demande de numéro de contrôle ne peut pas être envoyée dans le service de paiement externe"; + + //SaveIntentResponse + public static string WrongFormatInsureeNo = "1-Mauvais format du numéro d'assurance"; + public static string InValidINmissingPC = "2-Assurance non valide ou code de produit manquant"; + public static string InValidEOC = "3-Code du responsable d'inscription non valide"; + public static string IncompatibleEO_PC = "4-Le code du responsable d'inscription et le code de produit d'assurance ne sont pas compatibles"; + public static string NoRenewalProduct = "5-Le bénéficiaire n’a pas de police d’assurance spécifique pour le renouvellement"; + public static string InsureeNoMissing = "6-Numéro d'assurance manquant"; + public static string InsureeNotEnrolled = "7-Assuré non inscrit (inscription préalable obligatoire)"; + public static string DuplicateCNAssigned = "8-Numéro de contrôle dupliqué attribué"; + public static string CantAssignCn2 = "9-Le numéro de contrôle ne peut pas être attribué"; + public static string UnknownPaymentType = "10-Type de paiement inconnu"; + + //SavePayResponse + public static string WrongOrMissingRecDate = "1-Date de réception erronée ou manquante"; + public static string WrongFormatInputData = "2-Mauvais format des données d'entrée"; + public static string WrongControlNumber = "3-Mauvais numéro de contrôle"; + public static string WrongAmount = "4-Mauvais montant"; + public static string DuplicatePayAmount = "5-Montant du paiement dupliqué"; + public static string DoesntExistEO = "6-Le code du responsable d'inscription n'existe pas"; + public static string DoesntExistPC = "7-Le code produit n'existe pas"; + public static string NoPolicyForRenewal = "8-Le bénéficiaire n’a pas de police d’assurance spécifique pour le renouvellement"; + public static string UnknownTypeOfPay = "9-Type de paiement inconnu"; } } From 60d33ac7385732d7407bdfbfbe22eab1188b6915 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Tue, 9 Jul 2019 10:43:12 +0200 Subject: [PATCH 13/86] OS-31: Authorization has been added and changes in authentication have been added --- OpenImis.DB.SqlServer/IMISContext.cs | 15 +- OpenImis.DB.SqlServer/TblRoleRight.cs | 17 ++ OpenImis.DB.SqlServer/TblUserRole.cs | 17 ++ OpenImis.Modules/ImisModules.cs | 6 +- .../LoginModule/Logic/ILoginLogic.cs | 1 + .../LoginModule/Logic/LoginLogic.cs | 5 + .../Repositories/ILoginRepository.cs | 1 + .../Repositories/LoginRepository.cs | 18 ++ .../PaymentModule/Helpers/SMS/ImisBaseSms.cs | 12 +- .../PaymentModule/Helpers/SMS/ImisSms.cs | 2 +- .../PaymentModule/Logic/IPaymentLogic.cs | 3 + .../PaymentModule/Logic/PaymentLogic.cs | 33 ++-- .../PaymentModule/Models/Rights.cs | 23 --- .../PaymentModule/PaymentModule.cs | 6 +- .../Repositories/PaymentRepository.cs | 7 +- .../Controllers/ClaimsController.cs | 5 +- .../Controllers/ContributionController.cs | 11 +- .../Controllers/CoverageController.cs | 2 + .../Controllers/FamilyController.cs | 34 ++-- .../Controllers/LoginController.cs | 1 + .../Controllers/PaymentController.cs | 17 +- .../Controllers/PolicyController.cs | 65 ++++--- .../Security/HasRightsAttribute.cs | 50 ++++++ .../Security/IMISJwtSecurityTokenHandler.cs | 10 +- OpenImis.RestApi/Security/Rights.cs | 161 ++++++++++++++++++ 25 files changed, 393 insertions(+), 129 deletions(-) create mode 100644 OpenImis.DB.SqlServer/TblRoleRight.cs create mode 100644 OpenImis.DB.SqlServer/TblUserRole.cs delete mode 100644 OpenImis.Modules/PaymentModule/Models/Rights.cs create mode 100644 OpenImis.RestApi/Security/HasRightsAttribute.cs create mode 100644 OpenImis.RestApi/Security/Rights.cs diff --git a/OpenImis.DB.SqlServer/IMISContext.cs b/OpenImis.DB.SqlServer/IMISContext.cs index 6a6d5251..3c5fbc50 100644 --- a/OpenImis.DB.SqlServer/IMISContext.cs +++ b/OpenImis.DB.SqlServer/IMISContext.cs @@ -71,11 +71,12 @@ public IMISContext(DbContextOptions options) public virtual DbSet TblSubmittedPhotos { get; set; } public virtual DbSet TblUsers { get; set; } public virtual DbSet TblUsersDistricts { get; set; } - + public virtual DbSet TblRoleRight { get; set; } + public virtual DbSet TblUserRole { get; set; } // Unable to generate entity type for table 'dbo.tblIMISDetaulsPhone'. Please see the warning messages. // Unable to generate entity type for table 'dbo.tblEmailSettings'. Please see the warning messages. - + protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => @@ -2646,6 +2647,16 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("FK_tblUsersDistricts_tblUsers"); }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.RoleRightID); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.UserRoleID); + }); } } } diff --git a/OpenImis.DB.SqlServer/TblRoleRight.cs b/OpenImis.DB.SqlServer/TblRoleRight.cs new file mode 100644 index 00000000..889ddc70 --- /dev/null +++ b/OpenImis.DB.SqlServer/TblRoleRight.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.DB.SqlServer +{ + public class TblRoleRight + { + public TblRoleRight() + { + } + + public int RoleRightID { get; set; } + public int RoleID { get; set; } + public int RightID { get; set; } + } +} diff --git a/OpenImis.DB.SqlServer/TblUserRole.cs b/OpenImis.DB.SqlServer/TblUserRole.cs new file mode 100644 index 00000000..20b8a749 --- /dev/null +++ b/OpenImis.DB.SqlServer/TblUserRole.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.DB.SqlServer +{ + public class TblUserRole + { + public TblUserRole() + { + } + + public int UserRoleID { get; set; } + public int UserID { get; set; } + public int RoleID { get; set; } + } +} diff --git a/OpenImis.Modules/ImisModules.cs b/OpenImis.Modules/ImisModules.cs index f583af08..97b79967 100644 --- a/OpenImis.Modules/ImisModules.cs +++ b/OpenImis.Modules/ImisModules.cs @@ -49,13 +49,11 @@ public class ImisModules: IImisModules private IPaymentModule paymentModule; private readonly IConfiguration _configuration; - public readonly IHostingEnvironment _hostingEnvironment; private readonly ILogger logger; - public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory, IHostingEnvironment hostingEnvironment) + public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory) { _configuration = configuration; - _hostingEnvironment = hostingEnvironment; logger = loggerFactory.CreateLogger("LoggerCategory"); } @@ -99,7 +97,7 @@ public IPaymentModule GetPaymentModule() { if (paymentModule == null) { - paymentModule = new PaymentModule.PaymentModule(_configuration, _hostingEnvironment); + paymentModule = new PaymentModule.PaymentModule(_configuration); } return paymentModule; } diff --git a/OpenImis.Modules/LoginModule/Logic/ILoginLogic.cs b/OpenImis.Modules/LoginModule/Logic/ILoginLogic.cs index d48bca6d..e7830ff9 100644 --- a/OpenImis.Modules/LoginModule/Logic/ILoginLogic.cs +++ b/OpenImis.Modules/LoginModule/Logic/ILoginLogic.cs @@ -7,6 +7,7 @@ namespace OpenImis.Modules.LoginModule.Logic { public interface ILoginLogic { + UserData GetById(int userId); UserData FindUser(string UserName, string Password); } } diff --git a/OpenImis.Modules/LoginModule/Logic/LoginLogic.cs b/OpenImis.Modules/LoginModule/Logic/LoginLogic.cs index b66f4fb7..40f7e37d 100644 --- a/OpenImis.Modules/LoginModule/Logic/LoginLogic.cs +++ b/OpenImis.Modules/LoginModule/Logic/LoginLogic.cs @@ -23,6 +23,11 @@ public LoginLogic(IConfiguration configuration) loginRepository = new LoginRepository(Configuration); } + public UserData GetById(int userId) + { + return loginRepository.GetById(userId); + } + public UserData FindUser(string UserName, string Password) { var users = loginRepository.FindUserByName(UserName); diff --git a/OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs b/OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs index 855613a6..e0b95085 100644 --- a/OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs +++ b/OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs @@ -8,6 +8,7 @@ namespace OpenImis.Modules.LoginModule.Repositories { public interface ILoginRepository { + UserData GetById(int userId); List FindUserByName(string UserName); List GetUserRights(string userId); } diff --git a/OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs b/OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs index 9fa10242..c9e36c49 100644 --- a/OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs +++ b/OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs @@ -20,6 +20,24 @@ public LoginRepository(IConfiguration configuration) Configuration = configuration; } + public UserData GetById(int userId) + { + UserData user; + using (var imisContext = new ImisDB()) + { + user = imisContext.TblUsers.Where(u => u.UserId == userId).Select(x => new UserData() + { + UserID = x.UserId.ToString(), + LoginName = x.LoginName, + PrivateKey = x.PrivateKey, + StoredPassword = x.StoredPassword + }) + .FirstOrDefault(); + } + + return user; + } + public List FindUserByName(string UserName) { List response = new List(); diff --git a/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisBaseSms.cs b/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisBaseSms.cs index 3ec3f777..9f115e88 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisBaseSms.cs +++ b/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisBaseSms.cs @@ -15,16 +15,16 @@ namespace OpenImis.Modules.PaymentModule.Helpers.SMS public class ImisBaseSms { private string SmsTampletes = string.Empty; - private IHostingEnvironment env; + private string webRootPath; - public ImisBaseSms(IConfiguration config, IHostingEnvironment environment, Language language = Language.Primary) + public ImisBaseSms(IConfiguration config, string webRootPath, string contentRootPath, Language language = Language.Primary) { - env = environment; + this.webRootPath = webRootPath; if (language == Language.Primary) - SmsTampletes = environment.ContentRootPath + @"\Escape\Sms\Strings\"; + SmsTampletes = contentRootPath + @"\Escape\Sms\Strings\"; else - SmsTampletes = environment.ContentRootPath + @"\Escape\Sms\StringsSecondaryLanguage\"; + SmsTampletes = contentRootPath + @"\Escape\Sms\StringsSecondaryLanguage\"; } public virtual async Task SendSMS(List containers, string filename) @@ -58,7 +58,7 @@ public virtual async Task SendSMS(List containers, string public virtual void SaveMessage(string message, string name) { //string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); - string mydocpath = System.IO.Path.Combine(env.WebRootPath, "SentMessages"); + string mydocpath = System.IO.Path.Combine(webRootPath, "SentMessages"); string namepart = new Random().Next(100000, 999999).ToString(); using (StreamWriter outputFile = new StreamWriter(Path.Combine(mydocpath, name + namepart + ".json"))) diff --git a/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisSms.cs b/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisSms.cs index 683798c3..0e69cabb 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisSms.cs +++ b/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisSms.cs @@ -9,7 +9,7 @@ namespace OpenImis.Modules.PaymentModule.Helpers.SMS { public class ImisSms : ImisBaseSms { - public ImisSms(IConfiguration config, IHostingEnvironment env, Language language = Language.Primary) : base(config, env, language) + public ImisSms(IConfiguration config, string webRootPath, string contentRootPath, Language language = Language.Primary) : base(config, webRootPath, contentRootPath, language) { } diff --git a/OpenImis.Modules/PaymentModule/Logic/IPaymentLogic.cs b/OpenImis.Modules/PaymentModule/Logic/IPaymentLogic.cs index 0e86c587..74319588 100644 --- a/OpenImis.Modules/PaymentModule/Logic/IPaymentLogic.cs +++ b/OpenImis.Modules/PaymentModule/Logic/IPaymentLogic.cs @@ -9,6 +9,9 @@ namespace OpenImis.Modules.PaymentModule.Logic { public interface IPaymentLogic { + string WebRootPath { get; set; } + string ContentRootPath { get; set; } + Task SaveIntent(IntentOfPay intent, int? errorNumber = 0, string errorMessage = null); Task MatchPayment(MatchModel model); DataMessage SaveAcknowledgement(Acknowledgement model); diff --git a/OpenImis.Modules/PaymentModule/Logic/PaymentLogic.cs b/OpenImis.Modules/PaymentModule/Logic/PaymentLogic.cs index 26f5e82d..74ea8089 100644 --- a/OpenImis.Modules/PaymentModule/Logic/PaymentLogic.cs +++ b/OpenImis.Modules/PaymentModule/Logic/PaymentLogic.cs @@ -18,20 +18,21 @@ namespace OpenImis.Modules.PaymentModule.Logic public class PaymentLogic : IPaymentLogic { private IConfiguration Configuration; - private readonly IHostingEnvironment _hostingEnvironment; protected IPaymentRepository paymentRepository; - public PaymentLogic(IConfiguration configuration, IHostingEnvironment hostingEnvironment) + public string WebRootPath { get; set; } + public string ContentRootPath { get; set; } + + public PaymentLogic(IConfiguration configuration) { Configuration = configuration; - _hostingEnvironment = hostingEnvironment; - paymentRepository = new PaymentRepository(Configuration, _hostingEnvironment); + paymentRepository = new PaymentRepository(Configuration); } public async Task SaveIntent(IntentOfPay intent, int? errorNumber = 0, string errorMessage = null) { - IPaymentRepository payment = new PaymentRepository(Configuration, _hostingEnvironment); + IPaymentRepository payment = new PaymentRepository(Configuration); var intentResponse = payment.SaveIntent(intent, errorNumber, errorMessage); DataMessage return_message = new DataMessage(); @@ -98,7 +99,7 @@ public async Task SaveIntent(IntentOfPay intent, int? errorNumber = public async Task MatchPayment(MatchModel model) { - PaymentRepository payment = new PaymentRepository(Configuration, _hostingEnvironment); + PaymentRepository payment = new PaymentRepository(Configuration); var response = payment.MatchPayment(model); List PaymentIds = new List(); @@ -113,7 +114,7 @@ public async Task MatchPayment(MatchModel model) public DataMessage SaveAcknowledgement(Acknowledgement model) { - PaymentRepository payment = new PaymentRepository(Configuration, _hostingEnvironment) { PaymentId = model.internal_identifier }; + PaymentRepository payment = new PaymentRepository(Configuration) { PaymentId = model.internal_identifier }; var response = payment.SaveControlNumberAkn(model.error_occured, model.error_message); return response; @@ -122,7 +123,7 @@ public DataMessage SaveAcknowledgement(Acknowledgement model) public async Task SavePayment(PaymentData model) { - PaymentRepository payment = new PaymentRepository(Configuration, _hostingEnvironment); + PaymentRepository payment = new PaymentRepository(Configuration); //var controlNumberExists = payment.CheckControlNumber(model.internal_identifier, model.control_number); if (model.control_number != null) @@ -190,7 +191,7 @@ public async Task SavePayment(PaymentData model) public DataMessage SaveControlNumber(ControlNumberResp model) { - PaymentRepository payment = new PaymentRepository(Configuration, _hostingEnvironment); + PaymentRepository payment = new PaymentRepository(Configuration); var controlNumberExists = payment.CheckControlNumber(model.internal_identifier, model.control_number); var response = payment.SaveControlNumber(model, controlNumberExists); @@ -214,7 +215,7 @@ public DataMessage SaveControlNumber(ControlNumberResp model) public async void ControlNumberAssignedSms(IPaymentRepository payment) { //Language lang = payment.Language.ToLower() == "en" || payment.Language.ToLower() == "english" || payment.Language.ToLower() == "primary" ? Language.Primary : Language.Secondary; - ImisSms sms = new ImisSms(Configuration, _hostingEnvironment, payment.Language); + ImisSms sms = new ImisSms(Configuration, WebRootPath, ContentRootPath, payment.Language); var txtmsgTemplate = string.Empty; string othersCount = string.Empty; @@ -257,7 +258,7 @@ public async void ControlNumberAssignedSms(IPaymentRepository payment) public async Task GetControlNumbers(PaymentRequest requests) { - PaymentRepository payment = new PaymentRepository(Configuration, _hostingEnvironment); + PaymentRepository payment = new PaymentRepository(Configuration); var PaymentIds = requests.requests.Select(x => x.internal_identifier).ToArray(); var PaymentIds_string = string.Join(",", PaymentIds); @@ -270,7 +271,7 @@ public async Task GetControlNumbers(PaymentRequest requests) public async void ControlNumberNotassignedSms(IPaymentRepository payment, string error) { //Language lang = payment.Language.ToLower() == "en" || payment.Language.ToLower() == "english" || payment.Language.ToLower() == "primary" ? Language.Primary : Language.Secondary; - ImisSms sms = new ImisSms(Configuration, _hostingEnvironment, payment.Language); + ImisSms sms = new ImisSms(Configuration, WebRootPath, ContentRootPath, payment.Language); var txtmsgTemplate = string.Empty; string othersCount = string.Empty; @@ -304,7 +305,7 @@ public async void ControlNumberNotassignedSms(IPaymentRepository payment, string public async void SendPaymentSms(PaymentRepository payment) { // Language lang = payment.Language.ToLower() == "en" || payment.Language.ToLower() == "english" || payment.Language.ToLower() == "primary" ? Language.Primary : Language.Secondary; - ImisSms sms = new ImisSms(Configuration, _hostingEnvironment, payment.Language); + ImisSms sms = new ImisSms(Configuration, WebRootPath, ContentRootPath, payment.Language); List message = new List(); var familyproduct = payment.InsureeProducts.FirstOrDefault(); @@ -360,7 +361,7 @@ public async void SendPaymentSms(PaymentRepository payment) public async void SendMatchSms(PaymentRepository payment) { // Language lang = payment.Language.ToLower() == "en" || payment.Language.ToLower() == "english" || payment.Language.ToLower() == "primary" ? Language.Primary : Language.Secondary; - ImisSms sms = new ImisSms(Configuration, _hostingEnvironment, payment.Language); + ImisSms sms = new ImisSms(Configuration, WebRootPath, ContentRootPath, payment.Language); List message = new List(); var txtmsgTemplate = string.Empty; @@ -408,11 +409,11 @@ public async void SendMatchSms(List Ids) var txtmsgTemplate = string.Empty; string othersCount = string.Empty; - PaymentRepository _pay = new PaymentRepository(Configuration, _hostingEnvironment); + PaymentRepository _pay = new PaymentRepository(Configuration); _pay.GetPaymentInfo(m.PaymentId.ToString()); //Language lang = _pay.Language.ToLower() == "en" || _pay.Language.ToLower() == "english" || _pay.Language.ToLower() == "primary" ? Language.Primary : Language.Secondary; - ImisSms sms = new ImisSms(Configuration, _hostingEnvironment, _pay.Language); + ImisSms sms = new ImisSms(Configuration, WebRootPath, ContentRootPath, _pay.Language); if (_pay.PaymentId != null) { diff --git a/OpenImis.Modules/PaymentModule/Models/Rights.cs b/OpenImis.Modules/PaymentModule/Models/Rights.cs deleted file mode 100644 index e7c596b3..00000000 --- a/OpenImis.Modules/PaymentModule/Models/Rights.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenImis.Modules.PaymentModule.Models -{ - public enum Rights - { - PaymentSearch = 101401, - PaymentAdd = 101402, - PaymentEdit = 101403, - PaymentDelete = 101404, - - InsureeSearch = 101101, - InsureeAdd = 101102, - InsureeEdit = 101103, - InsureeDelete = 101104, - InsureeEnquire = 101105, - - FindClaim = 111001, - ClaimAdd = 111002, - } -} diff --git a/OpenImis.Modules/PaymentModule/PaymentModule.cs b/OpenImis.Modules/PaymentModule/PaymentModule.cs index 763a47c0..062a1a83 100644 --- a/OpenImis.Modules/PaymentModule/PaymentModule.cs +++ b/OpenImis.Modules/PaymentModule/PaymentModule.cs @@ -10,20 +10,18 @@ namespace OpenImis.Modules.PaymentModule public class PaymentModule : IPaymentModule { private IConfiguration Configuration; - private readonly IHostingEnvironment _hostingEnvironment; private IPaymentLogic _paymentLogic; - public PaymentModule(IConfiguration configuration, IHostingEnvironment hostingEnvironment) + public PaymentModule(IConfiguration configuration) { Configuration = configuration; - _hostingEnvironment = hostingEnvironment; } public IPaymentLogic GetPaymentLogic() { if (_paymentLogic == null) { - _paymentLogic = new PaymentLogic(Configuration, _hostingEnvironment); + _paymentLogic = new PaymentLogic(Configuration); } return _paymentLogic; } diff --git a/OpenImis.Modules/PaymentModule/Repositories/PaymentRepository.cs b/OpenImis.Modules/PaymentModule/Repositories/PaymentRepository.cs index 08a41ff9..be1c11e1 100644 --- a/OpenImis.Modules/PaymentModule/Repositories/PaymentRepository.cs +++ b/OpenImis.Modules/PaymentModule/Repositories/PaymentRepository.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using OpenImis.DB.SqlServer.DataHelper; using OpenImis.Modules.PaymentModule.Helpers; @@ -19,7 +18,6 @@ namespace OpenImis.Modules.PaymentModule.Repositories public class PaymentRepository : IPaymentRepository { private IConfiguration Configuration; - private readonly IHostingEnvironment _hostingEnvironment; protected DataHelper dh; public string PaymentId { get; set; } @@ -35,10 +33,9 @@ public class PaymentRepository : IPaymentRepository public List InsureeProducts { get; set; } - public PaymentRepository(IConfiguration configuration, IHostingEnvironment hostingEnvironment) + public PaymentRepository(IConfiguration configuration) { Configuration = configuration; - _hostingEnvironment = hostingEnvironment; dh = new DataHelper(configuration); } diff --git a/OpenImis.RestApi/Controllers/ClaimsController.cs b/OpenImis.RestApi/Controllers/ClaimsController.cs index 68b27f93..ab4cade1 100644 --- a/OpenImis.RestApi/Controllers/ClaimsController.cs +++ b/OpenImis.RestApi/Controllers/ClaimsController.cs @@ -9,11 +9,10 @@ using Microsoft.AspNetCore.Mvc; using OpenImis.Modules; using OpenImis.Modules.ClaimModule.Models; +using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers { - //[ApiVersion("1")] - //[Authorize(Roles = "IMISAdmin, EnrollmentOfficer")] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] @@ -48,7 +47,7 @@ public IActionResult GetDiagnosesServicesItems([FromBody]DsiInputModel model) } } - //[Authorize(Roles = "ClaimAdd")] + [HasRights(Rights.ClaimAdd)] [HttpPost] [Route("GetPaymentLists")] [ProducesResponseType(typeof(void), 200)] diff --git a/OpenImis.RestApi/Controllers/ContributionController.cs b/OpenImis.RestApi/Controllers/ContributionController.cs index 0a919858..15beb116 100644 --- a/OpenImis.RestApi/Controllers/ContributionController.cs +++ b/OpenImis.RestApi/Controllers/ContributionController.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Claims; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -10,6 +12,7 @@ namespace OpenImis.RestApi.Controllers { + [Authorize] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] @@ -31,11 +34,11 @@ public virtual IActionResult Enter_Contribution([FromBody]Contribution model) return BadRequest(new { error_occured = true, error_message = error }); } - //var identity = HttpContext.User.Identity as ClaimsIdentity; - //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); - // Temporary - var userId = 1; _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); var response = _imisModules.GetInsureeModule().GetContributionLogic().Enter(model); diff --git a/OpenImis.RestApi/Controllers/CoverageController.cs b/OpenImis.RestApi/Controllers/CoverageController.cs index 7ccb7b33..a3e0b944 100644 --- a/OpenImis.RestApi/Controllers/CoverageController.cs +++ b/OpenImis.RestApi/Controllers/CoverageController.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using OpenImis.Modules; @@ -12,6 +13,7 @@ namespace OpenImis.RestApi.Controllers { + [Authorize] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] diff --git a/OpenImis.RestApi/Controllers/FamilyController.cs b/OpenImis.RestApi/Controllers/FamilyController.cs index 98ff6214..c51c91b3 100644 --- a/OpenImis.RestApi/Controllers/FamilyController.cs +++ b/OpenImis.RestApi/Controllers/FamilyController.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -16,6 +17,7 @@ namespace OpenImis.RestApi.Controllers { + [Authorize] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] @@ -128,11 +130,11 @@ public IActionResult Edit_Family([FromBody]EditFamily model) return BadRequest(new { error_occured = true, error_message = error }); } - //var identity = HttpContext.User.Identity as ClaimsIdentity; - //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); - // Temporary - var userId = 1; _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); var response = _imisModules.GetInsureeModule().GetFamilyLogic().Edit(model); @@ -150,11 +152,11 @@ public IActionResult Enter_Member_Family([FromBody]FamilyMember model) return BadRequest(new { error_occured = true, error_message = error }); } - //var identity = HttpContext.User.Identity as ClaimsIdentity; - //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); - // Temporary - var userId = 1; _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); var response = _imisModules.GetInsureeModule().GetFamilyLogic().AddMember(model); @@ -172,11 +174,11 @@ public IActionResult Edit_Member_Family([FromBody]EditFamilyMember model) return BadRequest(new { error_occured = true, error_message = error }); } - //var identity = HttpContext.User.Identity as ClaimsIdentity; - //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); - // Temporary - var userId = 1; _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); var response = _imisModules.GetInsureeModule().GetFamilyLogic().EditMember(model); @@ -193,11 +195,11 @@ public IActionResult Delete_Member_Family([FromBody]string insureeNumber) // return BadRequest(new { error_occured = true, error_message = "1:Wrong format or missing insurance number of insuree" }); //} - //var identity = HttpContext.User.Identity as ClaimsIdentity; - //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); - // Temporary - var userId = 1; _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); var response = _imisModules.GetInsureeModule().GetFamilyLogic().DeleteMember(insureeNumber); diff --git a/OpenImis.RestApi/Controllers/LoginController.cs b/OpenImis.RestApi/Controllers/LoginController.cs index 6d9e8de5..f9d5beb8 100644 --- a/OpenImis.RestApi/Controllers/LoginController.cs +++ b/OpenImis.RestApi/Controllers/LoginController.cs @@ -16,6 +16,7 @@ namespace OpenImis.RestApi.Controllers { + [Authorize] [ApiController] [EnableCors("AllowSpecificOrigin")] public class LoginController : Controller diff --git a/OpenImis.RestApi/Controllers/PaymentController.cs b/OpenImis.RestApi/Controllers/PaymentController.cs index 23505e54..327bb375 100644 --- a/OpenImis.RestApi/Controllers/PaymentController.cs +++ b/OpenImis.RestApi/Controllers/PaymentController.cs @@ -11,6 +11,8 @@ using OpenImis.Modules.PaymentModule.Helpers.Extensions; using OpenImis.Modules.PaymentModule.Models; using OpenImis.Modules.PaymentModule.Models.Response; +using OpenImis.RestApi.Security; +using Rights = OpenImis.RestApi.Security.Rights; namespace OpenImis.RestApi.Controllers { @@ -28,9 +30,12 @@ public PaymentController(IConfiguration configuration, IHostingEnvironment hosti _configuration = configuration; _hostingEnvironment = hostingEnvironment; _imisModules = imisModules; + + _imisModules.GetPaymentModule().GetPaymentLogic().WebRootPath = _hostingEnvironment.WebRootPath; + _imisModules.GetPaymentModule().GetPaymentLogic().ContentRootPath = _hostingEnvironment.ContentRootPath; } - //[Authorize(Roles = "PaymentAdd")] + [HasRights(Rights.PaymentAdd)] [HttpPost] [Route("MatchPayment")] public virtual IActionResult MatchPayment([FromBody]MatchModel model) @@ -50,7 +55,7 @@ public virtual IActionResult MatchPayment([FromBody]MatchModel model) } //Recieve Payment from Operator/ - //[Authorize(Roles = "PaymentAdd")] + [HasRights(Rights.PaymentAdd)] [HttpPost] [Route("GetControlNumber")] //[ProducesResponseType(typeof(GetControlNumberResp), 200)] @@ -89,7 +94,7 @@ public virtual async Task GetControlNumber([FromBody]IntentOfPay } } - //[Authorize(Roles = "PaymentAdd")] + [HasRights(Rights.PaymentAdd)] [HttpPost] [Route("PostReqControlNumberAck")] [ProducesResponseType(typeof(void), 200)] @@ -122,7 +127,7 @@ public virtual IActionResult PostReqControlNumberAck([FromBody]Acknowledgement m } } - //[Authorize(Roles = "PaymentAdd")] + [HasRights(Rights.PaymentAdd)] [HttpPost] [Route("GetReqControlNumber")] [ProducesResponseType(typeof(void), 200)] @@ -156,7 +161,7 @@ public virtual IActionResult GetReqControlNumber([FromBody]ControlNumberResp mod } - //[Authorize(Roles = "PaymentAdd")] + [HasRights(Rights.PaymentAdd)] [HttpPost] [Route("GetPaymentData")] [ProducesResponseType(typeof(void), 200)] @@ -191,7 +196,7 @@ public virtual async Task GetPaymentData([FromBody]PaymentData mo } - //[Authorize(Roles = "PaymentSearch")] + [HasRights(Rights.PaymentSearch)] [HttpPost] [Route("GetAssignedControlNumbers")] [ProducesResponseType(typeof(AsignedControlNumbersResponse), 200)] diff --git a/OpenImis.RestApi/Controllers/PolicyController.cs b/OpenImis.RestApi/Controllers/PolicyController.cs index f021024d..c2a264fb 100644 --- a/OpenImis.RestApi/Controllers/PolicyController.cs +++ b/OpenImis.RestApi/Controllers/PolicyController.cs @@ -1,5 +1,7 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using System.Linq; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using OpenImis.Modules; @@ -7,6 +9,7 @@ namespace OpenImis.RestApi.Controllers { + [Authorize] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] @@ -28,11 +31,11 @@ public virtual IActionResult Enter_Policy([FromBody]Policy model) return BadRequest(new { error_occured = true, error_message = error }); } - //var identity = HttpContext.User.Identity as ClaimsIdentity; - //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); - // Temporary - var userId = 1; _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); var response = _imisModules.GetInsureeModule().GetPolicyLogic().Enter(model); @@ -50,21 +53,19 @@ public virtual IActionResult Renew_Policy([FromBody]Policy model) return BadRequest(new { error_occured = true, error_message = error }); } - //var identity = HttpContext.User.Identity as ClaimsIdentity; - //var iden = identity.FindFirst("UserId"); + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); - //try - //{ - // policies.UserId = Convert.ToInt32(iden.Value); - //} - //catch (Exception e) - //{ - // policies.UserId = -1; - //} - - // Temporary - var userId = 1; - _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + try + { + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + } + catch (Exception) + { + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(-1); + } var response = _imisModules.GetInsureeModule().GetPolicyLogic().Renew(model); @@ -81,21 +82,19 @@ public virtual IActionResult Get_Commissions([FromBody]GetCommissionInputs model return BadRequest(new { error_occured = true, error_message = error }); } - //var identity = HttpContext.User.Identity as ClaimsIdentity; - //var iden = identity.FindFirst("UserId"); + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); - //try - //{ - // policies.UserId = Convert.ToInt32(iden.Value); - //} - //catch (Exception e) - //{ - // policies.UserId = -1; - //} - - // Temporary - var userId = 1; - _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + try + { + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + } + catch (Exception) + { + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(-1); + } var response = _imisModules.GetInsureeModule().GetPolicyLogic().GetCommissions(model); diff --git a/OpenImis.RestApi/Security/HasRightsAttribute.cs b/OpenImis.RestApi/Security/HasRightsAttribute.cs new file mode 100644 index 00000000..a5df13c4 --- /dev/null +++ b/OpenImis.RestApi/Security/HasRightsAttribute.cs @@ -0,0 +1,50 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; +using OpenImis.DB.SqlServer; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; + +namespace OpenImis.RestApi.Security +{ + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] + public class HasRightsAttribute : AuthorizeAttribute, IAuthorizationFilter + { + HashSet userRights; + + public HasRightsAttribute(params Rights[] rights) + { + userRights = rights.ToHashSet(); + } + + public void OnAuthorization(AuthorizationFilterContext context) + { + int userId = Convert.ToInt32(context.HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); + + HashSet rights; + + using (var imisContext = new ImisDB()) + { + rights = (from UR in imisContext.TblUserRole + join RR in imisContext.TblRoleRight on UR.RoleID equals RR.RoleID + where UR.UserID == userId + select RR.RightID + ).ToHashSet(); + } + + bool isAuthorized = rights.Any(x => userRights.Contains((Rights)Enum.ToObject(typeof(Rights), x))); + + if (!isAuthorized) + { + context.Result = new ForbidResult(); + } + } + } +} diff --git a/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs b/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs index 309b6954..e4189b8d 100644 --- a/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs +++ b/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs @@ -8,6 +8,8 @@ using System.Security.Claims; using System.Text; using OpenImis.Modules.UserModule.Entities; +using OpenImis.Modules.LoginModule.Models; +using System.Diagnostics; namespace OpenImis.RestApi.Security { @@ -65,13 +67,9 @@ public ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParame var handler = new JwtSecurityTokenHandler(); var tokenS = handler.ReadToken(securityToken) as JwtSecurityToken; - var username = tokenS.Claims.First(claim => claim.Type == ClaimTypes.Name).Value; + int userId = Convert.ToInt32(tokenS.Claims.Where(w => w.Type == "UserId").Select(x => x.Value).FirstOrDefault()); - //var serviceCollection = new ServiceCollection(); - - //IUserSQL userRepository = _imisRepository.getUserRepository(); - - User user = _imisModules.GetUserModule().GetUserController().GetByUsername(username); + UserData user = _imisModules.GetLoginModule().GetLoginLogic().GetById(userId); if (user != null) { diff --git a/OpenImis.RestApi/Security/Rights.cs b/OpenImis.RestApi/Security/Rights.cs new file mode 100644 index 00000000..e68a6c3a --- /dev/null +++ b/OpenImis.RestApi/Security/Rights.cs @@ -0,0 +1,161 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace OpenImis.RestApi.Security +{ + public enum Rights + { + Family = 101000, // 0x00018A88 + FamilySearch = 101001, // 0x00018A89 + FamilyAdd = 101002, // 0x00018A8A + FamilyEdit = 101003, // 0x00018A8B + FamilyDelete = 101004, // 0x00018A8C + Insuree = 101100, // 0x00018AEC + InsureeSearch = 101101, // 0x00018AED + InsureeAdd = 101102, // 0x00018AEE + InsureeEdit = 101103, // 0x00018AEF + InsureeDelete = 101104, // 0x00018AF0 + InsureeEnquire = 101105, // 0x00018AF1 + PolicySearch = 101201, // 0x00018B51 + PolicyAdd = 101202, // 0x00018B52 + PolicyEdit = 101203, // 0x00018B53 + PolicyDelete = 101204, // 0x00018B54 + PolicyRenew = 101205, // 0x00018B55 + ContributionSearch = 101301, // 0x00018BB5 + ContributionAdd = 101302, // 0x00018BB6 + ContributionEdit = 101303, // 0x00018BB7 + ContributionDelete = 101304, // 0x00018BB8 + PaymentSearch = 101401, // 0x00018C19 + PaymentAdd = 101402, // 0x00018C1A + PaymentEdit = 101403, // 0x00018C1B + PaymentDelete = 101404, // 0x00018C1C + Claims = 111000, // 0x0001B198 + ClaimSearch = 111001, // 0x0001B199 + ClaimAdd = 111002, // 0x0001B19A + ClaimDelete = 111004, // 0x0001B19C + ClaimLoad = 111005, // 0x0001B19D + ClaimPrint = 111006, // 0x0001B19E + ClaimSubmit = 111007, // 0x0001B19F + ClaimReview = 111008, // 0x0001B1A0 + ClaimFeedback = 111009, // 0x0001B1A1 + ClaimUpdate = 111010, // 0x0001B1A2 + ClaimProcess = 111011, // 0x0001B1A3 + Batch = 111100, // 0x0001B1FC + BatchProcess = 111101, // 0x0001B1FD + BatchFilter = 111102, // 0x0001B1FE + BatchPreview = 111103, // 0x0001B1FF + Product = 121000, // 0x0001D8A8 + ProductSearch = 121001, // 0x0001D8A9 + ProductAdd = 121002, // 0x0001D8AA + ProductEdit = 121003, // 0x0001D8AB + ProductDelete = 121004, // 0x0001D8AC + ProductDuplicate = 121005, // 0x0001D8AD + HealthFacility = 121100, // 0x0001D90C + HealthFacilitySearch = 121101, // 0x0001D90D + HealthFacilityAdd = 121102, // 0x0001D90E + HealthFacilityEdit = 121103, // 0x0001D90F + HealthFacilityDelete = 121104, // 0x0001D910 + PriceListMedicalServices = 121200, // 0x0001D970 + FindPriceListMedicalServices = 121201, // 0x0001D971 + AddPriceListMedicalServices = 121202, // 0x0001D972 + EditPriceListMedicalServices = 121203, // 0x0001D973 + DeletePriceListMedicalServices = 121204, // 0x0001D974 + DuplicatePriceListMedicalServices = 121205, // 0x0001D975 + PriceListMedicalItems = 121300, // 0x0001D9D4 + FindPriceListMedicalItems = 121301, // 0x0001D9D5 + AddPriceListMedicalItems = 121302, // 0x0001D9D6 + EditPriceListMedicalItems = 121303, // 0x0001D9D7 + DeletePriceListMedicalItems = 121304, // 0x0001D9D8 + DuplicatePriceListMedicalItems = 121305, // 0x0001D9D9 + MedicalService = 121400, // 0x0001DA38 + FindMedicalService = 121401, // 0x0001DA39 + AddMedicalService = 121402, // 0x0001DA3A + EditMedicalService = 121403, // 0x0001DA3B + DeleteMedicalService = 121404, // 0x0001DA3C + Officer = 121500, // 0x0001DA9C + FindOfficer = 121501, // 0x0001DA9D + AddOfficer = 121502, // 0x0001DA9E + EditOfficer = 121503, // 0x0001DA9F + DeleteOfficer = 121504, // 0x0001DAA0 + ClaimAdministrator = 121600, // 0x0001DB00 + FindClaimAdministrator = 121601, // 0x0001DB01 + AddClaimAdministrator = 121602, // 0x0001DB02 + EditClaimAdministrator = 121603, // 0x0001DB03 + DeleteClaimAdministrator = 121604, // 0x0001DB04 + Users = 121700, // 0x0001DB64 + UsersSearch = 121701, // 0x0001DB65 + UsersAdd = 121702, // 0x0001DB66 + UsersEdit = 121703, // 0x0001DB67 + UsersDelete = 121704, // 0x0001DB68 + Payer = 121800, // 0x0001DBC8 + FindPayer = 121801, // 0x0001DBC9 + ViewPayer = 121801, // 0x0001DBC9 + AddPayer = 121802, // 0x0001DBCA + EditPayer = 121803, // 0x0001DBCB + DeletePayer = 121804, // 0x0001DBCC + Locations = 121900, // 0x0001DC2C + FindLocations = 121901, // 0x0001DC2D + AddLocations = 121902, // 0x0001DC2E + EditLocations = 121903, // 0x0001DC2F + DeleteLocations = 121904, // 0x0001DC30 + MoveLocations = 121905, // 0x0001DC31 + userProfiles = 122000, // 0x0001DC90 + FindUserProfile = 122001, // 0x0001DC91 + AddUserProfile = 122002, // 0x0001DC92 + EditUserProfile = 122003, // 0x0001DC93 + DeleteUserProfile = 122004, // 0x0001DC94 + DuplicateUserProfile = 122005, // 0x0001DC95 + MedicalItem = 122100, // 0x0001DCF4 + FindMedicalItem = 122101, // 0x0001DCF5 + AddMedicalItem = 122102, // 0x0001DCF6 + EditMedicalItem = 122103, // 0x0001DCF7 + DeleteMedicalItem = 122104, // 0x0001DCF8 + Tools = 130000, // 0x0001FBD0 + Registers = 131000, // 0x0001FFB8 + DiagnosesUpload = 131001, // 0x0001FFB9 + DiagnosesDownload = 131002, // 0x0001FFBA + HealthFacilitiesUpload = 131003, // 0x0001FFBB + HealthFacilitiesDownload = 131004, // 0x0001FFBC + LocationUpload = 131005, // 0x0001FFBD + LocationDonwload = 131006, // 0x0001FFBE + Extracts = 131100, // 0x0002001C + ExtractMasterDataDownload = 131101, // 0x0002001D + ExtractPhoneExtractsCreate = 131102, // 0x0002001E + ExtractOfflineExtractCreate = 131103, // 0x0002001F + ExtractClaimUpload = 131104, // 0x00020020 + ExtractEnrolmentsUpload = 131105, // 0x00020021 + ExtractFeedbackUpload = 131106, // 0x00020022 + Reports = 131200, // 0x00020080 + ReportsPrimaryOperationalIndicatorPolicies = 131201, // 0x00020081 + ReportsPrimaryOperationalIndicatorsClaims = 131202, // 0x00020082 + ReportsDerivedOperationalIndicators = 131203, // 0x00020083 + ReportsContributionCollection = 131204, // 0x00020084 + ReportsProductSales = 131205, // 0x00020085 + ReportsContributionDistribution = 131206, // 0x00020086 + ReportsUserActivity = 131207, // 0x00020087 + ReportsEnrolmentPerformanceIndicators = 131208, // 0x00020088 + ReportsStatusOfRegister = 131209, // 0x00020089 + ReportsInsureeWithoutPhotos = 131210, // 0x0002008A + ReportsPaymentCategoryOverview = 131211, // 0x0002008B + ReportsMatchingFunds = 131212, // 0x0002008C + ReportsClaimOverviewReport = 131213, // 0x0002008D + ReportsPercentageReferrals = 131214, // 0x0002008E + ReportsFamiliesInsureesOverview = 131215, // 0x0002008F + ReportsPendingInsurees = 131216, // 0x00020090 + ReportsRenewals = 131217, // 0x00020091 + ReportsCapitationPayment = 131218, // 0x00020092 + ReportRejectedPhoto = 131219, // 0x00020093 + ReportsContributionPayment = 131220, // 0x00020094 + ReportsControlNumberAssignment = 131221, // 0x00020095 + ReportsOverviewOfCommissions = 131222, // 0x00020096 + ReportsClaimHistoryReport = 131223, // 0x00020097 + Utilities = 131300, // 0x000200E4 + DatabaseBackup = 131301, // 0x000200E5 + DatabaseRestore = 131302, // 0x000200E6 + ExecuteScripts = 131303, // 0x000200E7 + EmailSettings = 131304, // 0x000200E8 + FundingSave = 131401, // 0x00020149 + } +} From 0afbae7bc1980d595e76216b6ca441176dea7b4a Mon Sep 17 00:00:00 2001 From: bkaminski Date: Tue, 9 Jul 2019 14:33:22 +0200 Subject: [PATCH 14/86] OS-31: I added Rights for endpoints --- .../Controllers/ClaimsController.cs | 3 + .../Controllers/ContributionController.cs | 2 + .../Controllers/CoverageController.cs | 2 + .../Controllers/FamilyController.cs | 16 +++-- .../Controllers/PolicyController.cs | 4 ++ OpenImis.RestApi/Startup.cs | 72 ++++++++++--------- 6 files changed, 61 insertions(+), 38 deletions(-) diff --git a/OpenImis.RestApi/Controllers/ClaimsController.cs b/OpenImis.RestApi/Controllers/ClaimsController.cs index ab4cade1..cc4b4464 100644 --- a/OpenImis.RestApi/Controllers/ClaimsController.cs +++ b/OpenImis.RestApi/Controllers/ClaimsController.cs @@ -24,6 +24,7 @@ public ClaimsController(IImisModules imisModules) _imisModules = imisModules; } + [HasRights(Rights.DiagnosesDownload)] [HttpPost] [Route("GetDiagnosesServicesItems")] [ProducesResponseType(typeof(void), 200)] @@ -71,6 +72,7 @@ public IActionResult GetPaymentLists([FromBody]PaymentListsInputModel model) } } + [HasRights(Rights.FindClaimAdministrator)] [HttpGet] [Route("Claims/GetClaimAdmins")] public IActionResult ValidateClaimAdmin() @@ -86,6 +88,7 @@ public IActionResult ValidateClaimAdmin() } } + [HasRights(Rights.ClaimSearch)] [HttpGet] [Route("Claims/Controls")] public IActionResult GetControls() diff --git a/OpenImis.RestApi/Controllers/ContributionController.cs b/OpenImis.RestApi/Controllers/ContributionController.cs index 15beb116..5f7a4d98 100644 --- a/OpenImis.RestApi/Controllers/ContributionController.cs +++ b/OpenImis.RestApi/Controllers/ContributionController.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc; using OpenImis.Modules; using OpenImis.Modules.InsureeModule.Models; +using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers { @@ -24,6 +25,7 @@ public ContributionController(IImisModules imisModules) _imisModules = imisModules; } + [HasRights(Rights.ContributionAdd)] [HttpPost] [Route("Contributions/Enter_Contribution")] public virtual IActionResult Enter_Contribution([FromBody]Contribution model) diff --git a/OpenImis.RestApi/Controllers/CoverageController.cs b/OpenImis.RestApi/Controllers/CoverageController.cs index a3e0b944..8e66dbfe 100644 --- a/OpenImis.RestApi/Controllers/CoverageController.cs +++ b/OpenImis.RestApi/Controllers/CoverageController.cs @@ -10,6 +10,7 @@ using OpenImis.Modules; using OpenImis.Modules.CoverageModule.Helpers; using OpenImis.Modules.CoverageModule.Models; +using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers { @@ -25,6 +26,7 @@ public CoverageController(IImisModules imisModules) _imisModules = imisModules; } + [HasRights(Rights.InsureeSearch)] [HttpGet] [Route("Coverage/Get_Coverage")] public virtual IActionResult Get(string InsureeNumber) diff --git a/OpenImis.RestApi/Controllers/FamilyController.cs b/OpenImis.RestApi/Controllers/FamilyController.cs index c51c91b3..f873a03e 100644 --- a/OpenImis.RestApi/Controllers/FamilyController.cs +++ b/OpenImis.RestApi/Controllers/FamilyController.cs @@ -14,6 +14,7 @@ using OpenImis.Modules; using OpenImis.Modules.InsureeModule.Helpers; using OpenImis.Modules.InsureeModule.Models; +using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers { @@ -29,6 +30,7 @@ public FamilyController(IImisModules imisModules) _imisModules = imisModules; } + [HasRights(Rights.FamilySearch)] [HttpGet] [Route("Families/Get_Family")] public IActionResult Get(string insureeNumber) @@ -62,6 +64,7 @@ public IActionResult Get(string insureeNumber) return Json(response); } + [HasRights(Rights.FamilySearch)] [HttpGet] [Route("Families/Get_Member_Family")] public IActionResult Get_Member_Family(string insureeNumber, int order) @@ -98,6 +101,7 @@ public IActionResult Get_Member_Family(string insureeNumber, int order) return Json(response, serializerSettings); } + [HasRights(Rights.FamilyAdd)] [HttpPost] [Route("Families/Enter_Family")] public IActionResult Enter_Family([FromBody]FamilyModelv3 model) @@ -108,11 +112,11 @@ public IActionResult Enter_Family([FromBody]FamilyModelv3 model) return BadRequest(new { error_occured = true, error_message = error }); } - //var identity = HttpContext.User.Identity as ClaimsIdentity; - //_imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(Convert.ToInt32(identity.FindFirst("UserId").Value)); + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); - // Temporary - var userId = 1; _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); var response = _imisModules.GetInsureeModule().GetFamilyLogic().AddNew(model); @@ -120,6 +124,7 @@ public IActionResult Enter_Family([FromBody]FamilyModelv3 model) return Json(response); } + [HasRights(Rights.FamilyEdit)] [HttpPost] [Route("Families/Edit_Family")] public IActionResult Edit_Family([FromBody]EditFamily model) @@ -142,6 +147,7 @@ public IActionResult Edit_Family([FromBody]EditFamily model) return Json(response); } + [HasRights(Rights.FamilyAdd)] [HttpPost] [Route("Families/Enter_Member_Family")] public IActionResult Enter_Member_Family([FromBody]FamilyMember model) @@ -164,6 +170,7 @@ public IActionResult Enter_Member_Family([FromBody]FamilyMember model) return Json(response); } + [HasRights(Rights.FamilyEdit)] [HttpPost] [Route("Families/Edit_Member_Family")] public IActionResult Edit_Member_Family([FromBody]EditFamilyMember model) @@ -186,6 +193,7 @@ public IActionResult Edit_Member_Family([FromBody]EditFamilyMember model) return Json(response); } + [HasRights(Rights.FamilyDelete)] [HttpPost] [Route("Families/Delete_Member_Family")] public IActionResult Delete_Member_Family([FromBody]string insureeNumber) diff --git a/OpenImis.RestApi/Controllers/PolicyController.cs b/OpenImis.RestApi/Controllers/PolicyController.cs index c2a264fb..6a3d56eb 100644 --- a/OpenImis.RestApi/Controllers/PolicyController.cs +++ b/OpenImis.RestApi/Controllers/PolicyController.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc; using OpenImis.Modules; using OpenImis.Modules.InsureeModule.Models; +using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers { @@ -21,6 +22,7 @@ public PolicyController(IImisModules imisModules) _imisModules = imisModules; } + [HasRights(Rights.PolicyAdd)] [HttpPost] [Route("Policies/Enter_Policy")] public virtual IActionResult Enter_Policy([FromBody]Policy model) @@ -43,6 +45,7 @@ public virtual IActionResult Enter_Policy([FromBody]Policy model) return Json(response); } + [HasRights(Rights.PolicyRenew)] [HttpPost] [Route("Policies/Renew_Policy")] public virtual IActionResult Renew_Policy([FromBody]Policy model) @@ -72,6 +75,7 @@ public virtual IActionResult Renew_Policy([FromBody]Policy model) return Json(response); } + [HasRights(Rights.PolicySearch)] [HttpPost] [Route("Policies/Get_Commissions")] public virtual IActionResult Get_Commissions([FromBody]GetCommissionInputs model) diff --git a/OpenImis.RestApi/Startup.cs b/OpenImis.RestApi/Startup.cs index d12feb8e..accb01a8 100644 --- a/OpenImis.RestApi/Startup.cs +++ b/OpenImis.RestApi/Startup.cs @@ -32,13 +32,13 @@ public Startup(IConfiguration configuration) public void ConfigureServices(IServiceCollection services) { - // Add the DbContext - //services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("IMISDatabase"))); + // Add the DbContext + //services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("IMISDatabase"))); - services.AddSingleton(); + services.AddSingleton(); - // Add the authentication scheme with the custom validator - services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + // Add the authentication scheme with the custom validator + services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters @@ -55,35 +55,39 @@ public void ConfigureServices(IServiceCollection services) options.SecurityTokenValidators.Add(new IMISJwtSecurityTokenHandler(services.BuildServiceProvider().GetService())); }); - services.AddAuthorization(); - //(options => - //{ - // options.AddPolicy("MedicalOfficer", policy => policy.Requirements.Add(new HasAuthorityRequirement("MedicalOfficer", Configuration["JwtIssuer"]))); - // options.AddPolicy("EnrollmentOfficer", policy => policy.Requirements.Add(new HasAuthorityRequirement("EnrollmentOfficer", Configuration["JwtIssuer"]))); - //}); + services.AddAuthorization(); + //(options => + //{ + // options.AddPolicy("MedicalOfficer", policy => policy.Requirements.Add(new HasAuthorityRequirement("MedicalOfficer", Configuration["JwtIssuer"]))); + // options.AddPolicy("EnrollmentOfficer", policy => policy.Requirements.Add(new HasAuthorityRequirement("EnrollmentOfficer", Configuration["JwtIssuer"]))); + //}); - // register the scope authorization handler - services.AddSingleton(); - services.AddSingleton(); + // register the scope authorization handler + services.AddSingleton(); + services.AddSingleton(); - services.AddMvc() - .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + services.AddMvc(options => + { + options.AllowCombiningAuthorizeFilters = false; + }) + .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + + services.AddApiVersioning(o => + { + o.ReportApiVersions = true; + o.AssumeDefaultVersionWhenUnspecified = true; + o.DefaultApiVersion = new ApiVersion(1, 0); + o.ApiVersionReader = ApiVersionReader.Combine(new QueryStringApiVersionReader(), new HeaderApiVersionReader("api-version")); + }); - services.AddApiVersioning(o => { - o.ReportApiVersions = true; - o.AssumeDefaultVersionWhenUnspecified = true; - o.DefaultApiVersion = new ApiVersion(1, 0); - o.ApiVersionReader = ApiVersionReader.Combine(new QueryStringApiVersionReader(), new HeaderApiVersionReader("api-version")); - }); - services.AddSwaggerGen(SwaggerHelper.ConfigureSwaggerGen); - services.AddCors(options => - { - options.AddPolicy("AllowSpecificOrigin", - builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowCredentials().AllowAnyHeader()); - }); + services.AddCors(options => + { + options.AddPolicy("AllowSpecificOrigin", + builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowCredentials().AllowAnyHeader()); + }); services.Configure(options => { @@ -96,9 +100,9 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); - loggerFactory.AddConsole(Configuration.GetSection("Logging")); - loggerFactory.AddDebug(); - } + loggerFactory.AddConsole(Configuration.GetSection("Logging")); + loggerFactory.AddDebug(); + } if (!env.EnvironmentName.Equals("Test")) { app.UseStaticFiles(); @@ -106,12 +110,12 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF app.UseSwaggerUI(SwaggerHelper.ConfigureSwaggerUI); } - app.UseAuthentication(); + app.UseAuthentication(); app.UseMvc(); - app.UseCors("AllowSpecificOrigin"); + app.UseCors("AllowSpecificOrigin"); + - // ===== Create tables ====== //imisContext.Database.EnsureCreated(); } From 3e954886207fd6a97f16d8675de8585d1a6c0a80 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Tue, 9 Jul 2019 16:06:11 +0200 Subject: [PATCH 15/86] OS-31: Changed the requirements of Rights --- OpenImis.RestApi/Security/HasRightsAttribute.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenImis.RestApi/Security/HasRightsAttribute.cs b/OpenImis.RestApi/Security/HasRightsAttribute.cs index a5df13c4..b527aff4 100644 --- a/OpenImis.RestApi/Security/HasRightsAttribute.cs +++ b/OpenImis.RestApi/Security/HasRightsAttribute.cs @@ -39,7 +39,7 @@ select RR.RightID ).ToHashSet(); } - bool isAuthorized = rights.Any(x => userRights.Contains((Rights)Enum.ToObject(typeof(Rights), x))); + bool isAuthorized = rights.All(x => userRights.Contains((Rights)Enum.ToObject(typeof(Rights), x))); if (!isAuthorized) { From 760cdcfc8e3ada7af530ce3221fb2983a01b5d17 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Tue, 9 Jul 2019 16:06:11 +0200 Subject: [PATCH 16/86] OS-31: Changed the requirements of Rights --- OpenImis.RestApi/Security/HasRightsAttribute.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenImis.RestApi/Security/HasRightsAttribute.cs b/OpenImis.RestApi/Security/HasRightsAttribute.cs index a5df13c4..58064677 100644 --- a/OpenImis.RestApi/Security/HasRightsAttribute.cs +++ b/OpenImis.RestApi/Security/HasRightsAttribute.cs @@ -39,7 +39,7 @@ select RR.RightID ).ToHashSet(); } - bool isAuthorized = rights.Any(x => userRights.Contains((Rights)Enum.ToObject(typeof(Rights), x))); + bool isAuthorized = userRights.Select(s => (int)s).All(x => rights.Contains(x)); if (!isAuthorized) { From fb751434a5ef835c18e9770eba97703a4f4ddc19 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 11 Jul 2019 10:45:25 +0200 Subject: [PATCH 17/86] OS-33: Added validation data --- OpenImis.DB.SqlServer/TblRoleRight.cs | 2 + OpenImis.DB.SqlServer/TblUserRole.cs | 2 + .../ClaimModule/Models/DsiInputModel.cs | 6 +-- .../Models/PaymentListsInputModel.cs | 5 +- .../Validators/InsureeNumberAttribute.cs | 27 +++++++++++ .../Validators/OfficerCodeAttribute.cs | 23 ++++++++++ .../Helpers/Validators/RequiredIfAttribute.cs | 46 +++++++++++++++++++ .../Validators/RequiredIfEoAttribute.cs | 35 ++++++++++++++ .../Helpers/Validators/ValidDateAttribute.cs | 46 +++++++++++++++++++ .../Helpers/Validators/Validation.cs | 36 +++++++++++++++ .../InsureeModule/Models/Contribution.cs | 9 ++-- .../InsureeModule/Models/EditFamilyMember.cs | 8 ++-- .../InsureeModule/Models/EditFamilyModel.cs | 7 +-- .../InsureeModule/Models/Family.cs | 15 +++++- .../InsureeModule/Models/FamilyMember.cs | 10 ++-- .../InsureeModule/Models/FamilyModelv3.cs | 19 ++------ .../InsureeModule/Models/Policy.cs | 9 ++-- .../LoginModule/Logic/LoginLogic.cs | 2 - OpenImis.Modules/LoginModule/Models/Rights.cs | 23 ---------- .../Repositories/ILoginRepository.cs | 1 - .../Repositories/LoginRepository.cs | 41 +---------------- .../PaymentModule/Models/IntentOfPay.cs | 9 ++-- .../PaymentModule/Models/PaymentData.cs | 17 +++---- .../PaymentModule/Models/PaymentDetail.cs | 5 +- .../Controllers/CoverageController.cs | 10 ++-- .../Controllers/FamilyController.cs | 9 ++-- .../Controllers/LoginController.cs | 5 -- .../Security/HasRightsAttribute.cs | 4 +- 28 files changed, 291 insertions(+), 140 deletions(-) create mode 100644 OpenImis.Modules/Helpers/Validators/InsureeNumberAttribute.cs create mode 100644 OpenImis.Modules/Helpers/Validators/OfficerCodeAttribute.cs create mode 100644 OpenImis.Modules/Helpers/Validators/RequiredIfAttribute.cs create mode 100644 OpenImis.Modules/Helpers/Validators/RequiredIfEoAttribute.cs create mode 100644 OpenImis.Modules/Helpers/Validators/ValidDateAttribute.cs create mode 100644 OpenImis.Modules/Helpers/Validators/Validation.cs delete mode 100644 OpenImis.Modules/LoginModule/Models/Rights.cs diff --git a/OpenImis.DB.SqlServer/TblRoleRight.cs b/OpenImis.DB.SqlServer/TblRoleRight.cs index 889ddc70..1bf1595a 100644 --- a/OpenImis.DB.SqlServer/TblRoleRight.cs +++ b/OpenImis.DB.SqlServer/TblRoleRight.cs @@ -13,5 +13,7 @@ public TblRoleRight() public int RoleRightID { get; set; } public int RoleID { get; set; } public int RightID { get; set; } + public DateTime ValidityFrom { get; set; } + public DateTime? ValidityTo { get; set; } } } diff --git a/OpenImis.DB.SqlServer/TblUserRole.cs b/OpenImis.DB.SqlServer/TblUserRole.cs index 20b8a749..66004d94 100644 --- a/OpenImis.DB.SqlServer/TblUserRole.cs +++ b/OpenImis.DB.SqlServer/TblUserRole.cs @@ -13,5 +13,7 @@ public TblUserRole() public int UserRoleID { get; set; } public int UserID { get; set; } public int RoleID { get; set; } + public DateTime ValidityFrom { get; set; } + public DateTime? ValidityTo { get; set; } } } diff --git a/OpenImis.Modules/ClaimModule/Models/DsiInputModel.cs b/OpenImis.Modules/ClaimModule/Models/DsiInputModel.cs index 9d46be73..4799e3c3 100644 --- a/OpenImis.Modules/ClaimModule/Models/DsiInputModel.cs +++ b/OpenImis.Modules/ClaimModule/Models/DsiInputModel.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.Modules.Helpers.Validators; +using System; using System.Collections.Generic; using System.Text; @@ -6,8 +7,7 @@ namespace OpenImis.Modules.ClaimModule.Models { public class DsiInputModel { - // TODO ValidDate Attribute - //[ValidDate(ErrorMessage = "Please Enter A valid date format")] + [ValidDate(ErrorMessage = "Please Enter A valid date format")] public string last_update_date { get; set; } } } diff --git a/OpenImis.Modules/ClaimModule/Models/PaymentListsInputModel.cs b/OpenImis.Modules/ClaimModule/Models/PaymentListsInputModel.cs index 757e2950..a5f640d5 100644 --- a/OpenImis.Modules/ClaimModule/Models/PaymentListsInputModel.cs +++ b/OpenImis.Modules/ClaimModule/Models/PaymentListsInputModel.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.Modules.Helpers.Validators; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; @@ -9,7 +10,7 @@ public class PaymentListsInputModel { [Required] public string claim_administrator_code { get; set; } - //[ValidDate] + [ValidDate] public string last_update_date { get; set; } } } diff --git a/OpenImis.Modules/Helpers/Validators/InsureeNumberAttribute.cs b/OpenImis.Modules/Helpers/Validators/InsureeNumberAttribute.cs new file mode 100644 index 00000000..762a8853 --- /dev/null +++ b/OpenImis.Modules/Helpers/Validators/InsureeNumberAttribute.cs @@ -0,0 +1,27 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class InsureeNumberAttribute : ValidationAttribute + { + public InsureeNumberAttribute() + { + } + + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + if (value != null) + { + Validation val = new Validation(); + ValidationResult result = val.InsureeNumber(value.ToString()); + + return result; + } + + return ValidationResult.Success; + } + } +} diff --git a/OpenImis.Modules/Helpers/Validators/OfficerCodeAttribute.cs b/OpenImis.Modules/Helpers/Validators/OfficerCodeAttribute.cs new file mode 100644 index 00000000..7ccae185 --- /dev/null +++ b/OpenImis.Modules/Helpers/Validators/OfficerCodeAttribute.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class OfficerCodeAttribute : ValidationAttribute + { + public OfficerCodeAttribute() + { + } + + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + Validation val = new Validation(); + ValidationResult result = val.OfficerCode(value); + + return result; + } + } +} diff --git a/OpenImis.Modules/Helpers/Validators/RequiredIfAttribute.cs b/OpenImis.Modules/Helpers/Validators/RequiredIfAttribute.cs new file mode 100644 index 00000000..aab35e71 --- /dev/null +++ b/OpenImis.Modules/Helpers/Validators/RequiredIfAttribute.cs @@ -0,0 +1,46 @@ +using OpenImis.Modules.PaymentModule.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class RequiredIfAttribute : ValidationAttribute + { + private string _fieldName; + private int _fieldNumber; + + public RequiredIfAttribute(string fieldName, int fieldNumber = 0) // fieldNumber = 1:control_number 2:insurance_number, 3:insurance_product_code, 4:renewal, 5:enrolment_officer_code + { + _fieldName = fieldName; + _fieldNumber = fieldNumber; + } + + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + PaymentData payment = (PaymentData)validationContext.ObjectInstance; + + if (payment.control_number == null && value == null) + { + if (_fieldNumber == 2 && payment.insurance_number != null) + { + return ValidationResult.Success; + } + else + { + return new ValidationResult(_fieldName + " is required if Control Number is not provided"); + } + } + if (payment.control_number != null && value != null) + { + return new ValidationResult(_fieldName + " is not required if Control Number is provided"); + } + else + { + return ValidationResult.Success; + } + } + } +} diff --git a/OpenImis.Modules/Helpers/Validators/RequiredIfEoAttribute.cs b/OpenImis.Modules/Helpers/Validators/RequiredIfEoAttribute.cs new file mode 100644 index 00000000..030b6705 --- /dev/null +++ b/OpenImis.Modules/Helpers/Validators/RequiredIfEoAttribute.cs @@ -0,0 +1,35 @@ +using OpenImis.Modules.PaymentModule.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class RequiredIfEoAttribute : ValidationAttribute + { + private string _fieldName; + private int _fieldNumber; + + public RequiredIfEoAttribute(string fieldName) // fieldNumber = 1:control_number 2:insurance_number, 3:insurance_product_code, 4:renewal, 5:enrolment_officer_code + { + _fieldName = fieldName; + } + + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + IntentOfPay intent = (IntentOfPay)validationContext.ObjectInstance; + + if (intent.enrolment_officer_code == null && value != null && Convert.ToInt32(value) != 0) + { + return new ValidationResult(_fieldName + " is not required if Enrolment officer is not provided"); + } + else + { + return ValidationResult.Success; + } + + } + } +} diff --git a/OpenImis.Modules/Helpers/Validators/ValidDateAttribute.cs b/OpenImis.Modules/Helpers/Validators/ValidDateAttribute.cs new file mode 100644 index 00000000..435de3bd --- /dev/null +++ b/OpenImis.Modules/Helpers/Validators/ValidDateAttribute.cs @@ -0,0 +1,46 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Globalization; + +namespace OpenImis.Modules.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class ValidDateAttribute : ValidationAttribute + { + public ValidDateAttribute() + { + } + + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + if (value == null) + return ValidationResult.Success; + + try + { + DateTime date = Convert.ToDateTime(value.ToString()); + DateTime Odate; + + if (date.Year > 1753) + { + if (DateTime.TryParseExact(value.ToString(), "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out Odate)) + { + return ValidationResult.Success; + } + else + { + return new ValidationResult(null); + } + } + else + { + return new ValidationResult(null); + } + } + catch (Exception) + { + return new ValidationResult(null); + } + } + } +} diff --git a/OpenImis.Modules/Helpers/Validators/Validation.cs b/OpenImis.Modules/Helpers/Validators/Validation.cs new file mode 100644 index 00000000..c22b9b02 --- /dev/null +++ b/OpenImis.Modules/Helpers/Validators/Validation.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.Modules.Helpers.Validators +{ + public class Validation + { + public virtual ValidationResult InsureeNumber(string insureeNumber) + { + if (insureeNumber != null) + { + if (insureeNumber.Length < 12 && insureeNumber.Length > 0) + return ValidationResult.Success; + else + return new ValidationResult("1:Wrong format of insurance number "); + } + + return ValidationResult.Success; + } + + public virtual ValidationResult OfficerCode(object value) + { + if (value != null) + { + if (value.ToString().Length < 8) + return ValidationResult.Success; + else + return new ValidationResult("3:Not valid enrolment officer code"); + } + + return ValidationResult.Success; + } + } +} diff --git a/OpenImis.Modules/InsureeModule/Models/Contribution.cs b/OpenImis.Modules/InsureeModule/Models/Contribution.cs index 6dae93b9..7db26377 100644 --- a/OpenImis.Modules/InsureeModule/Models/Contribution.cs +++ b/OpenImis.Modules/InsureeModule/Models/Contribution.cs @@ -1,19 +1,18 @@ -using System; -using System.Collections.Generic; +using OpenImis.Modules.Helpers.Validators; +using System; using System.ComponentModel.DataAnnotations; -using System.Text; namespace OpenImis.Modules.InsureeModule.Models { public class Contribution { [Required] - //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number ")] + [InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number ")] public string InsuranceNumber { get; set; } [Required(ErrorMessage = "7-Wrong or missing payer")] public string Payer { get; set; } [Required(ErrorMessage = "4:Wrong or missing payment date")] - //[ValidDate(ErrorMessage = "4:Wrong or missing payment date")] + [ValidDate(ErrorMessage = "4:Wrong or missing payment date")] public string PaymentDate { get; set; } [Required(ErrorMessage = "3:Wrong or missing product ")] public string ProductCode { get; set; } diff --git a/OpenImis.Modules/InsureeModule/Models/EditFamilyMember.cs b/OpenImis.Modules/InsureeModule/Models/EditFamilyMember.cs index 0cf63d9c..1cd99f25 100644 --- a/OpenImis.Modules/InsureeModule/Models/EditFamilyMember.cs +++ b/OpenImis.Modules/InsureeModule/Models/EditFamilyMember.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.Modules.Helpers.Validators; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; @@ -8,15 +9,14 @@ namespace OpenImis.Modules.InsureeModule.Models public class EditFamilyMember { [Required] - //[InsureeNumber(ErrorMessage = "3:Wrong format or missing insurance number of member")] + [InsureeNumber(ErrorMessage = "3:Wrong format or missing insurance number of member")] public string InsureeNumber { get; set; } public string OtherName { get; set; } public string LastName { get; set; } - //[ValidDate(ErrorMessage = "5:Wrong format or missing birth date")] + [ValidDate(ErrorMessage = "5:Wrong format or missing birth date")] public string BirthDate { get; set; } [StringLength(1, ErrorMessage = "6:Wrong gender")] public string Gender { get; set; } - public string Relationship { get; set; } [StringLength(1, ErrorMessage = "7:Wrong marital status")] public string MaritalStatus { get; set; } diff --git a/OpenImis.Modules/InsureeModule/Models/EditFamilyModel.cs b/OpenImis.Modules/InsureeModule/Models/EditFamilyModel.cs index f7532460..8eaa4203 100644 --- a/OpenImis.Modules/InsureeModule/Models/EditFamilyModel.cs +++ b/OpenImis.Modules/InsureeModule/Models/EditFamilyModel.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.Modules.Helpers.Validators; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; @@ -9,11 +10,11 @@ public class EditFamily { public string VillageCode { get; set; } [Required(ErrorMessage = "1:Wrong format or missing insurance number of head")] - //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] + [InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] public string HeadOfFamilyId { get; set; } public string OtherName { get; set; } public string LastName { get; set; } - //[ValidDate(ErrorMessage = "6:Wrong format or missing birth date")] + [ValidDate(ErrorMessage = "6:Wrong format or missing birth date")] public string BirthDate { get; set; } public string Gender { get; set; } public bool PovertyStatus { get; set; } diff --git a/OpenImis.Modules/InsureeModule/Models/Family.cs b/OpenImis.Modules/InsureeModule/Models/Family.cs index 5a5f4d3f..a48174d9 100644 --- a/OpenImis.Modules/InsureeModule/Models/Family.cs +++ b/OpenImis.Modules/InsureeModule/Models/Family.cs @@ -1,5 +1,7 @@ -using System; +using OpenImis.Modules.Helpers.Validators; +using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Text; namespace OpenImis.Modules.InsureeModule.Models @@ -8,13 +10,24 @@ public abstract class Family { public string InsuranceNumber { get; set; } public string OtherNames { get; set; } + + [Required(ErrorMessage = "7:Missing last name", AllowEmptyStrings = false)] public string LastName { get; set; } + + [Required(ErrorMessage = "6:Wrong format or missing birth date")] + [ValidDate] public DateTime BirthDate { get; set; } + + [Required(ErrorMessage = "5:Wrong or missing gender"), StringLength(1, ErrorMessage = "5:Wrong or missing gender")] public string Gender { get; set; } + public bool? PoveryStatus { get; set; } public string ConfirmationType { get; set; } public string PermanentAddress { get; set; } + + [StringLength(1, ErrorMessage = "11:Wrong marital status")] public string MaritalStatus { get; set; } + public bool BeneficiaryCard { get; set; } public string CurrentVillageCode { get; set; } public string CurrentAddress { get; set; } diff --git a/OpenImis.Modules/InsureeModule/Models/FamilyMember.cs b/OpenImis.Modules/InsureeModule/Models/FamilyMember.cs index 34fa331f..e40eb71b 100644 --- a/OpenImis.Modules/InsureeModule/Models/FamilyMember.cs +++ b/OpenImis.Modules/InsureeModule/Models/FamilyMember.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.Modules.Helpers.Validators; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; @@ -8,21 +9,20 @@ namespace OpenImis.Modules.InsureeModule.Models public class FamilyMember { [Required] - //[InsureeNumber(ErrorMessage = "3:Wrong format or missing insurance number of member")] + [InsureeNumber(ErrorMessage = "3:Wrong format or missing insurance number of member")] public string InsureeNumber { get; set; } [Required] - //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] + [InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] public string HeadInsureeNumber { get; set; } [Required(ErrorMessage = "7:Missing other name", AllowEmptyStrings = false)] public string OtherName { get; set; } [Required(ErrorMessage = "6:Missing last name", AllowEmptyStrings = false)] public string LastName { get; set; } [Required(ErrorMessage = "5:Wrong format or missing birth date")] - //[ValidDate] + [ValidDate] public string BirthDate { get; set; } [StringLength(1, ErrorMessage = "4:Wrong or missing gender")] public string Gender { get; set; } - public string Relationship { get; set; } [StringLength(1, ErrorMessage = "10:Wrong marital status")] public string MaritalStatus { get; set; } diff --git a/OpenImis.Modules/InsureeModule/Models/FamilyModelv3.cs b/OpenImis.Modules/InsureeModule/Models/FamilyModelv3.cs index 02d214a3..b8934f9c 100644 --- a/OpenImis.Modules/InsureeModule/Models/FamilyModelv3.cs +++ b/OpenImis.Modules/InsureeModule/Models/FamilyModelv3.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.Modules.Helpers.Validators; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; @@ -17,23 +18,12 @@ public class FamilyModelv3 : Family /// An insuree number belonging to the head of a family /// [Required(ErrorMessage = "1:Wrong format or missing insurance number of head")] - //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] + [InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] public string HeadOfFamilyId { get; set; } [Required(ErrorMessage = "8:Missing other name", AllowEmptyStrings = false)] public string OtherName { get; set; } - //[Required(ErrorMessage = "7:Missing last name", AllowEmptyStrings = false)] - //public string LastName { get; set; } - - //[Required(ErrorMessage = "6:Wrong format or missing birth date")] - //[ValidDate] - //public string BirthDate { get; set; } - - //[Required(ErrorMessage = "5:Wrong or missing gender"), StringLength(1, ErrorMessage = "5:Wrong or missing gender")] - //[BindRequired] - //public string Gender { get; set; } - public bool PovertyStatus { get; set; } public string GroupType { get; set; } @@ -42,9 +32,6 @@ public class FamilyModelv3 : Family public string PermanentAddressDetails { get; set; } - //[StringLength(1, ErrorMessage = "11:Wrong marital status")] - //public string MaritalStatus { get; set; } - public string CurrentAddressDetails { get; set; } public string FspCode { get; set; } diff --git a/OpenImis.Modules/InsureeModule/Models/Policy.cs b/OpenImis.Modules/InsureeModule/Models/Policy.cs index 778c1fe7..83d1392f 100644 --- a/OpenImis.Modules/InsureeModule/Models/Policy.cs +++ b/OpenImis.Modules/InsureeModule/Models/Policy.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.Modules.Helpers.Validators; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; @@ -8,11 +9,13 @@ namespace OpenImis.Modules.InsureeModule.Models public class Policy { [Required] - //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number")] + [InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number")] public string InsuranceNumber { get; set; } + [Required(ErrorMessage = "4:Wrong or missing enrolment date")] - //[ValidDate(ErrorMessage = "4:Wrong or missing enrolment date")] + [ValidDate(ErrorMessage = "4:Wrong or missing enrolment date")] public string Date { get; set; } + [Required] public string ProductCode { get; set; } [Required] diff --git a/OpenImis.Modules/LoginModule/Logic/LoginLogic.cs b/OpenImis.Modules/LoginModule/Logic/LoginLogic.cs index 40f7e37d..114e73e7 100644 --- a/OpenImis.Modules/LoginModule/Logic/LoginLogic.cs +++ b/OpenImis.Modules/LoginModule/Logic/LoginLogic.cs @@ -40,8 +40,6 @@ public UserData FindUser(string UserName, string Password) if (validUser) { - List userRights = loginRepository.GetUserRights(user.UserID); - user.Rights = userRights; return user; } else diff --git a/OpenImis.Modules/LoginModule/Models/Rights.cs b/OpenImis.Modules/LoginModule/Models/Rights.cs deleted file mode 100644 index 8c57dd80..00000000 --- a/OpenImis.Modules/LoginModule/Models/Rights.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenImis.Modules.LoginModule.Models -{ - public enum Rights - { - PaymentSearch = 101401, - PaymentAdd = 101402, - PaymentEdit = 101403, - PaymentDelete = 101404, - - InsureeSearch = 101101, - InsureeAdd = 101102, - InsureeEdit = 101103, - InsureeDelete = 101104, - InsureeEnquire = 101105, - - FindClaim = 111001, - ClaimAdd = 111002 - } -} diff --git a/OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs b/OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs index e0b95085..b388a2a4 100644 --- a/OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs +++ b/OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs @@ -10,6 +10,5 @@ public interface ILoginRepository { UserData GetById(int userId); List FindUserByName(string UserName); - List GetUserRights(string userId); } } diff --git a/OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs b/OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs index c9e36c49..1f992fbb 100644 --- a/OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs +++ b/OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Data; using System.Data.SqlClient; +using System.Diagnostics; using System.Linq; using System.Text; @@ -65,45 +66,5 @@ public List FindUserByName(string UserName) throw e; } } - - public List GetUserRights(string userId) - { - DataHelper helper = new DataHelper(Configuration); - - var rights = new List(); - - var sSQL = @"SELECT DISTINCT tblRoleRight.RightID - FROM tblRole INNER JOIN - tblRoleRight ON tblRole.RoleID = tblRoleRight.RoleID AnD tblRoleRight.ValidityTo IS NULL - INNER JOIN - tblUserRole ON tblRole.RoleID = tblUserRole.RoleID AND tblUserRole.ValidityTo IS NULL - INNER JOIN - tblUsers ON tblUserRole.UserID = tblUsers.UserID AND tblUsers.ValidityTo IS NULL - WHERE tblUsers.UserID = @UserId AND tblRole.ValidityTo IS NULL"; - - SqlParameter[] paramets = { - new SqlParameter("@UserId", userId) - }; - - var dt = helper.GetDataTable(sSQL, paramets, CommandType.Text); - - if (dt.Rows.Count > 0) - { - for (int i = 0; i < dt.Rows.Count; i++) - { - var row = dt.Rows[i]; - var rightId = Convert.ToInt32(row["RightID"]); - var rightName = Enum.GetName(typeof(Models.Rights), rightId); - - if (rightName != null) - { - rights.Add(rightName); - } - - } - } - - return rights; - } } } diff --git a/OpenImis.Modules/PaymentModule/Models/IntentOfPay.cs b/OpenImis.Modules/PaymentModule/Models/IntentOfPay.cs index c847d029..ce5e641b 100644 --- a/OpenImis.Modules/PaymentModule/Models/IntentOfPay.cs +++ b/OpenImis.Modules/PaymentModule/Models/IntentOfPay.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.Modules.Helpers.Validators; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; @@ -9,13 +10,13 @@ public class IntentOfPay { [Required(ErrorMessage = "9: Phone number not provided")] public virtual string phone_number { get; set; } - //[ValidDate(ErrorMessage = "10: Request Date not valid")] + [ValidDate(ErrorMessage = "10: Request Date not valid")] [DataType(DataType.DateTime)] public string request_date { get; set; } - //[OfficerCode] + [OfficerCode] public string enrolment_officer_code { get; set; } public virtual List policies { get; set; } - //[RequiredIfEo("amunt to be paid")] + [RequiredIfEo("amunt to be paid")] public decimal amount_to_be_paid { get; set; } public string language { get; set; } [Range(0, 2, ErrorMessage = "10-Uknown type of payment")] diff --git a/OpenImis.Modules/PaymentModule/Models/PaymentData.cs b/OpenImis.Modules/PaymentModule/Models/PaymentData.cs index e3480bf9..19b80451 100644 --- a/OpenImis.Modules/PaymentModule/Models/PaymentData.cs +++ b/OpenImis.Modules/PaymentModule/Models/PaymentData.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.Modules.Helpers.Validators; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; @@ -8,23 +9,23 @@ namespace OpenImis.Modules.PaymentModule.Models public class PaymentData { public string control_number { get; set; } - //[InsureeNumber] - //[RequiredIf("Insuree number")] //this attributes validates if control number is not provided + [InsureeNumber] + [RequiredIf("Insuree number")] //this attributes validates if control number is not provided public string insurance_number { get; set; } - //[RequiredIf("Insurance Product Code")] + [RequiredIf("Insurance Product Code")] public string insurance_product_code { get; set; } - //[RequiredIf("Renewal")] + [RequiredIf("Renewal")] public EnrolmentType? renewal { get; set; } - //[RequiredIf("Enrolment Officer Code", 2)] + [RequiredIf("Enrolment Officer Code", 2)] public string enrolment_officer_code { get; set; } public string transaction_identification { get; set; } public string receipt_identification { get; set; } public double received_amount { get; set; } [Required(ErrorMessage = "1-Wrong or missing receiving date")] - //[ValidDate(ErrorMessage = "1-Wrong or missing receiving date")] + [ValidDate(ErrorMessage = "1-Wrong or missing receiving date")] [DataType(DataType.DateTime)] public string received_date { get; set; } - //[ValidDate(ErrorMessage = "5-Invalid Payment Date")] + [ValidDate(ErrorMessage = "5-Invalid Payment Date")] [DataType(DataType.DateTime)] public string payment_date { get; set; } public string payment_origin { get; set; } diff --git a/OpenImis.Modules/PaymentModule/Models/PaymentDetail.cs b/OpenImis.Modules/PaymentModule/Models/PaymentDetail.cs index 8f3c7627..a063be64 100644 --- a/OpenImis.Modules/PaymentModule/Models/PaymentDetail.cs +++ b/OpenImis.Modules/PaymentModule/Models/PaymentDetail.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.Modules.Helpers.Validators; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; @@ -7,7 +8,7 @@ namespace OpenImis.Modules.PaymentModule.Models { public class PaymentDetail { - //[InsureeNumber] + [InsureeNumber] public string insurance_number { get; set; } [Required(ErrorMessage = "2:Not valid insurance or missing product code")] public string insurance_product_code { get; set; } diff --git a/OpenImis.RestApi/Controllers/CoverageController.cs b/OpenImis.RestApi/Controllers/CoverageController.cs index 8e66dbfe..d2660f61 100644 --- a/OpenImis.RestApi/Controllers/CoverageController.cs +++ b/OpenImis.RestApi/Controllers/CoverageController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Data.SqlClient; using System.Diagnostics; using System.Linq; @@ -10,6 +11,7 @@ using OpenImis.Modules; using OpenImis.Modules.CoverageModule.Helpers; using OpenImis.Modules.CoverageModule.Models; +using OpenImis.Modules.Helpers.Validators; using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers @@ -31,17 +33,11 @@ public CoverageController(IImisModules imisModules) [Route("Coverage/Get_Coverage")] public virtual IActionResult Get(string InsureeNumber) { - // Temporary HTTP 400 - if (!ModelState.IsValid) + if (new Validation().InsureeNumber(InsureeNumber) != ValidationResult.Success) { return BadRequest(new { error_occured = true, error_message = "1:Wrong format or missing insurance number of insuree" }); } - //if (new ValidationBase().InsureeNumber(InsureeNumber) != ValidationResult.Success) - //{ - // return BadRequest(new { error_occured = true, error_message = "1:Wrong format or missing insurance number of insuree" }); - //} - DataMessage response; try { diff --git a/OpenImis.RestApi/Controllers/FamilyController.cs b/OpenImis.RestApi/Controllers/FamilyController.cs index f873a03e..10d14581 100644 --- a/OpenImis.RestApi/Controllers/FamilyController.cs +++ b/OpenImis.RestApi/Controllers/FamilyController.cs @@ -12,6 +12,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using OpenImis.Modules; +using OpenImis.Modules.Helpers.Validators; using OpenImis.Modules.InsureeModule.Helpers; using OpenImis.Modules.InsureeModule.Models; using OpenImis.RestApi.Security; @@ -198,10 +199,10 @@ public IActionResult Edit_Member_Family([FromBody]EditFamilyMember model) [Route("Families/Delete_Member_Family")] public IActionResult Delete_Member_Family([FromBody]string insureeNumber) { - //if (new ValidationBase().InsureeNumber(insureeNumber) != ValidationResult.Success) - //{ - // return BadRequest(new { error_occured = true, error_message = "1:Wrong format or missing insurance number of insuree" }); - //} + if (new Validation().InsureeNumber(insureeNumber) != ValidationResult.Success) + { + return BadRequest(new { error_occured = true, error_message = "1:Wrong format or missing insurance number of insuree" }); + } int userId = Convert.ToInt32(HttpContext.User.Claims .Where(w => w.Type == "UserId") diff --git a/OpenImis.RestApi/Controllers/LoginController.cs b/OpenImis.RestApi/Controllers/LoginController.cs index f9d5beb8..1bad64b5 100644 --- a/OpenImis.RestApi/Controllers/LoginController.cs +++ b/OpenImis.RestApi/Controllers/LoginController.cs @@ -46,11 +46,6 @@ public IActionResult Index([FromBody]LoginModel model) new Claim("UserId", user.UserID) }; - foreach (var right in user.Rights) - { - claims.Add(new Claim(ClaimTypes.Role, right)); - } - var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(user.PrivateKey)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); diff --git a/OpenImis.RestApi/Security/HasRightsAttribute.cs b/OpenImis.RestApi/Security/HasRightsAttribute.cs index 58064677..e37f2bf7 100644 --- a/OpenImis.RestApi/Security/HasRightsAttribute.cs +++ b/OpenImis.RestApi/Security/HasRightsAttribute.cs @@ -33,8 +33,8 @@ public void OnAuthorization(AuthorizationFilterContext context) using (var imisContext = new ImisDB()) { rights = (from UR in imisContext.TblUserRole - join RR in imisContext.TblRoleRight on UR.RoleID equals RR.RoleID - where UR.UserID == userId + join RR in imisContext.TblRoleRight.Where(x => x.ValidityTo == null) on UR.RoleID equals RR.RoleID + where (UR.UserID == userId && UR.ValidityTo == null) select RR.RightID ).ToHashSet(); } From 756eb383af29fdee54e2dda3e29a82a4a126d767 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Fri, 12 Jul 2019 11:31:08 +0200 Subject: [PATCH 18/86] OS-34: Added API versioning --- ...imsController.cs => ClaimsControllerV1.cs} | 5 +- ...troller.cs => ContributionControllerV1.cs} | 5 +- ...eController.cs => CoverageControllerV1.cs} | 5 +- .../Controllers/FamilyController.cs | 218 ------------ .../Controllers/FamilyControllerV1.cs | 317 ++++++++++-------- .../Controllers/LocationController.cs | 54 --- .../Controllers/LoginController.cs | 1 + .../Controllers/LoginControllerV1.cs | 110 ------ .../Controllers/MasterDataController.cs | 62 ---- ...ntController.cs => PaymentControllerV1.cs} | 5 +- ...icyController.cs => PolicyControllerV1.cs} | 5 +- .../Controllers/ValuesControllerV1.cs | 56 ---- .../Docs/AddRequiredHeaderParameter.cs | 27 ++ OpenImis.RestApi/Docs/SwaggerHelper.cs | 4 +- 14 files changed, 229 insertions(+), 645 deletions(-) rename OpenImis.RestApi/Controllers/{ClaimsController.cs => ClaimsControllerV1.cs} (96%) rename OpenImis.RestApi/Controllers/{ContributionController.cs => ContributionControllerV1.cs} (91%) rename OpenImis.RestApi/Controllers/{CoverageController.cs => CoverageControllerV1.cs} (94%) delete mode 100644 OpenImis.RestApi/Controllers/FamilyController.cs delete mode 100644 OpenImis.RestApi/Controllers/LocationController.cs delete mode 100644 OpenImis.RestApi/Controllers/LoginControllerV1.cs delete mode 100644 OpenImis.RestApi/Controllers/MasterDataController.cs rename OpenImis.RestApi/Controllers/{PaymentController.cs => PaymentControllerV1.cs} (97%) rename OpenImis.RestApi/Controllers/{PolicyController.cs => PolicyControllerV1.cs} (96%) delete mode 100644 OpenImis.RestApi/Controllers/ValuesControllerV1.cs create mode 100644 OpenImis.RestApi/Docs/AddRequiredHeaderParameter.cs diff --git a/OpenImis.RestApi/Controllers/ClaimsController.cs b/OpenImis.RestApi/Controllers/ClaimsControllerV1.cs similarity index 96% rename from OpenImis.RestApi/Controllers/ClaimsController.cs rename to OpenImis.RestApi/Controllers/ClaimsControllerV1.cs index cc4b4464..542c962e 100644 --- a/OpenImis.RestApi/Controllers/ClaimsController.cs +++ b/OpenImis.RestApi/Controllers/ClaimsControllerV1.cs @@ -13,13 +13,14 @@ namespace OpenImis.RestApi.Controllers { + [ApiVersion("1")] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] - public class ClaimsController : Controller + public class ClaimsControllerV1 : Controller { private readonly IImisModules _imisModules; - public ClaimsController(IImisModules imisModules) + public ClaimsControllerV1(IImisModules imisModules) { _imisModules = imisModules; } diff --git a/OpenImis.RestApi/Controllers/ContributionController.cs b/OpenImis.RestApi/Controllers/ContributionControllerV1.cs similarity index 91% rename from OpenImis.RestApi/Controllers/ContributionController.cs rename to OpenImis.RestApi/Controllers/ContributionControllerV1.cs index 5f7a4d98..28c44353 100644 --- a/OpenImis.RestApi/Controllers/ContributionController.cs +++ b/OpenImis.RestApi/Controllers/ContributionControllerV1.cs @@ -13,14 +13,15 @@ namespace OpenImis.RestApi.Controllers { + [ApiVersion("1")] [Authorize] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] - public class ContributionController : Controller + public class ContributionControllerV1 : Controller { private readonly IImisModules _imisModules; - public ContributionController(IImisModules imisModules) + public ContributionControllerV1(IImisModules imisModules) { _imisModules = imisModules; } diff --git a/OpenImis.RestApi/Controllers/CoverageController.cs b/OpenImis.RestApi/Controllers/CoverageControllerV1.cs similarity index 94% rename from OpenImis.RestApi/Controllers/CoverageController.cs rename to OpenImis.RestApi/Controllers/CoverageControllerV1.cs index 8e66dbfe..e8770775 100644 --- a/OpenImis.RestApi/Controllers/CoverageController.cs +++ b/OpenImis.RestApi/Controllers/CoverageControllerV1.cs @@ -14,14 +14,15 @@ namespace OpenImis.RestApi.Controllers { + [ApiVersion("1")] [Authorize] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] - public class CoverageController : Controller + public class CoverageControllerV1 : Controller { private readonly IImisModules _imisModules; - public CoverageController(IImisModules imisModules) + public CoverageControllerV1(IImisModules imisModules) { _imisModules = imisModules; } diff --git a/OpenImis.RestApi/Controllers/FamilyController.cs b/OpenImis.RestApi/Controllers/FamilyController.cs deleted file mode 100644 index f873a03e..00000000 --- a/OpenImis.RestApi/Controllers/FamilyController.cs +++ /dev/null @@ -1,218 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Diagnostics; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Cors; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -using OpenImis.Modules; -using OpenImis.Modules.InsureeModule.Helpers; -using OpenImis.Modules.InsureeModule.Models; -using OpenImis.RestApi.Security; - -namespace OpenImis.RestApi.Controllers -{ - [Authorize] - [Route("api/")] - [ApiController] - [EnableCors("AllowSpecificOrigin")] - public class FamilyController : Controller - { - private readonly IImisModules _imisModules; - public FamilyController(IImisModules imisModules) - { - _imisModules = imisModules; - } - - [HasRights(Rights.FamilySearch)] - [HttpGet] - [Route("Families/Get_Family")] - public IActionResult Get(string insureeNumber) - { - DataMessage response; - try - { - if (insureeNumber != null || insureeNumber.Length != 0) - { - var data = _imisModules.GetInsureeModule().GetFamilyLogic().Get(insureeNumber); - - if (data.Count > 0) - { - response = new GetFamilyResponse(0, false, data, 0).Message; - } - else - { - response = new GetFamilyResponse(2, false, 0).Message; - } - } - else - { - response = new GetFamilyResponse(1, true, 0).Message; - } - } - catch (Exception e) - { - response = new GetFamilyResponse(e).Message; - } - - return Json(response); - } - - [HasRights(Rights.FamilySearch)] - [HttpGet] - [Route("Families/Get_Member_Family")] - public IActionResult Get_Member_Family(string insureeNumber, int order) - { - DataMessage response; - try - { - if (insureeNumber != null || insureeNumber.Length != 0) - { - var data = _imisModules.GetInsureeModule().GetFamilyLogic().GetMember(insureeNumber, order); - - if (data.Count > 0) - { - response = new GetMemberFamilyResponse(0, false, data, 0).Message; - } - else - { - response = new GetMemberFamilyResponse(2, true, 0).Message; - } - } - else - { - response = new GetMemberFamilyResponse(1, true, 0).Message; - } - } - catch (Exception e) - { - response = new GetMemberFamilyResponse(e).Message; - } - - var serializerSettings = new JsonSerializerSettings(); - serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - - return Json(response, serializerSettings); - } - - [HasRights(Rights.FamilyAdd)] - [HttpPost] - [Route("Families/Enter_Family")] - public IActionResult Enter_Family([FromBody]FamilyModelv3 model) - { - if (!ModelState.IsValid) - { - var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; - return BadRequest(new { error_occured = true, error_message = error }); - } - - int userId = Convert.ToInt32(HttpContext.User.Claims - .Where(w => w.Type == "UserId") - .Select(x => x.Value) - .FirstOrDefault()); - - _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); - - var response = _imisModules.GetInsureeModule().GetFamilyLogic().AddNew(model); - - return Json(response); - } - - [HasRights(Rights.FamilyEdit)] - [HttpPost] - [Route("Families/Edit_Family")] - public IActionResult Edit_Family([FromBody]EditFamily model) - { - if (!ModelState.IsValid) - { - var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; - return BadRequest(new { error_occured = true, error_message = error }); - } - - int userId = Convert.ToInt32(HttpContext.User.Claims - .Where(w => w.Type == "UserId") - .Select(x => x.Value) - .FirstOrDefault()); - - _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); - - var response = _imisModules.GetInsureeModule().GetFamilyLogic().Edit(model); - - return Json(response); - } - - [HasRights(Rights.FamilyAdd)] - [HttpPost] - [Route("Families/Enter_Member_Family")] - public IActionResult Enter_Member_Family([FromBody]FamilyMember model) - { - if (!ModelState.IsValid) - { - var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; - return BadRequest(new { error_occured = true, error_message = error }); - } - - int userId = Convert.ToInt32(HttpContext.User.Claims - .Where(w => w.Type == "UserId") - .Select(x => x.Value) - .FirstOrDefault()); - - _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); - - var response = _imisModules.GetInsureeModule().GetFamilyLogic().AddMember(model); - - return Json(response); - } - - [HasRights(Rights.FamilyEdit)] - [HttpPost] - [Route("Families/Edit_Member_Family")] - public IActionResult Edit_Member_Family([FromBody]EditFamilyMember model) - { - if (!ModelState.IsValid) - { - var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; - return BadRequest(new { error_occured = true, error_message = error }); - } - - int userId = Convert.ToInt32(HttpContext.User.Claims - .Where(w => w.Type == "UserId") - .Select(x => x.Value) - .FirstOrDefault()); - - _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); - - var response = _imisModules.GetInsureeModule().GetFamilyLogic().EditMember(model); - - return Json(response); - } - - [HasRights(Rights.FamilyDelete)] - [HttpPost] - [Route("Families/Delete_Member_Family")] - public IActionResult Delete_Member_Family([FromBody]string insureeNumber) - { - //if (new ValidationBase().InsureeNumber(insureeNumber) != ValidationResult.Success) - //{ - // return BadRequest(new { error_occured = true, error_message = "1:Wrong format or missing insurance number of insuree" }); - //} - - int userId = Convert.ToInt32(HttpContext.User.Claims - .Where(w => w.Type == "UserId") - .Select(x => x.Value) - .FirstOrDefault()); - - _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); - - var response = _imisModules.GetInsureeModule().GetFamilyLogic().DeleteMember(insureeNumber); - - return Json(response); - } - } -} \ No newline at end of file diff --git a/OpenImis.RestApi/Controllers/FamilyControllerV1.cs b/OpenImis.RestApi/Controllers/FamilyControllerV1.cs index d81529df..e0c8d4f2 100644 --- a/OpenImis.RestApi/Controllers/FamilyControllerV1.cs +++ b/OpenImis.RestApi/Controllers/FamilyControllerV1.cs @@ -1,170 +1,219 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Diagnostics; using System.Linq; +using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; using OpenImis.Modules; -using OpenImis.Modules.InsureeManagementModule.Models; -using OpenImis.Modules.InsureeManagementModule.Protocol; +using OpenImis.Modules.InsureeModule.Helpers; +using OpenImis.Modules.InsureeModule.Models; +using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers { [ApiVersion("1")] - [Route("api/family")] - [ApiController] - [EnableCors("AllowSpecificOrigin")] - public class FamilyControllerV1 : Controller + [Authorize] + [Route("api/")] + [ApiController] + [EnableCors("AllowSpecificOrigin")] + public class FamilyControllerV1 : Controller { - private readonly IImisModules _imisModules; - - - public FamilyControllerV1(IImisModules imisModules) - { - _imisModules = imisModules; - } - - /// - /// Get the list of the Families - /// - /// Number of the page - /// Number of families per request/page - /// The list of families - /// - /// ### REMARKS ### - /// The following codes are returned - /// - 200 - The list of the families - /// - 400 - The request is invalid - /// - 401 - The token is invalid - /// - /// Returns the list of families - /// If the request is incomplete - /// If the token is missing, is wrong or expired - [Authorize("EnrollmentOfficer")] - [HttpGet] - [ProducesResponseType(typeof(GetFamiliesResponse), 200)] - [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] - [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] - public async Task GetFamilies([FromQuery]int page = 1, [FromQuery]int resultsPerPage = 20) + private readonly IImisModules _imisModules; + public FamilyControllerV1(IImisModules imisModules) { - GetFamiliesResponse families; - families = await _imisModules.GetInsureeManagementModule().GetFamilyLogic().GetFamilies(page, resultsPerPage); + _imisModules = imisModules; + } - return Ok(families); + [HasRights(Rights.FamilySearch)] + [HttpGet] + [Route("Families/Get_Family")] + public IActionResult Get(string insureeNumber) + { + DataMessage response; + try + { + if (insureeNumber != null || insureeNumber.Length != 0) + { + var data = _imisModules.GetInsureeModule().GetFamilyLogic().Get(insureeNumber); + + if (data.Count > 0) + { + response = new GetFamilyResponse(0, false, data, 0).Message; + } + else + { + response = new GetFamilyResponse(2, false, 0).Message; + } + } + else + { + response = new GetFamilyResponse(1, true, 0).Message; + } + } + catch (Exception e) + { + response = new GetFamilyResponse(e).Message; + } + + return Json(response); } - // GET api/ws/family/00001 - [Authorize("IMISAdmin")] - [HttpGet("insuree/{insureeId}", Name = "GetFamilyByInsureeId")] - public async Task GetFamilyByInsureeId(string insureeId) + [HasRights(Rights.FamilySearch)] + [HttpGet] + [Route("Families/Get_Member_Family")] + public IActionResult Get_Member_Family(string insureeNumber, int order) { - FamilyModel familyModel; - - try - { - familyModel = await _imisModules.GetInsureeManagementModule().GetFamilyLogic().GetFamilyByInsureeId(insureeId); - } - catch (ValidationException e) - { - return BadRequest(new { error = new { message = e.Message, value = e.Value } }); - } - - if (familyModel==null) - { - return NotFound(); - } - - return Ok(familyModel); + DataMessage response; + try + { + if (insureeNumber != null || insureeNumber.Length != 0) + { + var data = _imisModules.GetInsureeModule().GetFamilyLogic().GetMember(insureeNumber, order); + + if (data.Count > 0) + { + response = new GetMemberFamilyResponse(0, false, data, 0).Message; + } + else + { + response = new GetMemberFamilyResponse(2, true, 0).Message; + } + } + else + { + response = new GetMemberFamilyResponse(1, true, 0).Message; + } + } + catch (Exception e) + { + response = new GetMemberFamilyResponse(e).Message; + } + + var serializerSettings = new JsonSerializerSettings(); + serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + + return Json(response, serializerSettings); } + [HasRights(Rights.FamilyAdd)] + [HttpPost] + [Route("Families/Enter_Family")] + public IActionResult Enter_Family([FromBody]FamilyModelv3 model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); + + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + + var response = _imisModules.GetInsureeModule().GetFamilyLogic().AddNew(model); - [HttpGet("{familyId}", Name = "GetFamilyByFamilyId")] - public async Task GetFamilyByFamilyId(int familyId) - { - FamilyModel familyModel; + return Json(response); + } + + [HasRights(Rights.FamilyEdit)] + [HttpPost] + [Route("Families/Edit_Family")] + public IActionResult Edit_Family([FromBody]EditFamily model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } - try - { - familyModel = await _imisModules.GetInsureeManagementModule().GetFamilyLogic().GetFamilyByFamilyId(familyId); - } - catch (ValidationException e) - { - return BadRequest(new { error = new { message = e.Message, value = e.Value } }); - } + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); - if (familyModel == null) - { - return NotFound(); - } + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); - return Ok(familyModel); - } + var response = _imisModules.GetInsureeModule().GetFamilyLogic().Edit(model); + return Json(response); + } - // POST api/values - [HttpPost] - public async Task AddNewFamily([FromBody]FamilyModel family) + [HasRights(Rights.FamilyAdd)] + [HttpPost] + [Route("Families/Enter_Member_Family")] + public IActionResult Enter_Member_Family([FromBody]FamilyMember model) { - FamilyModel newFamily; - try - { - newFamily = await _imisModules.GetInsureeManagementModule().GetFamilyLogic().AddFamilyAsync(family); - } - catch (ValidationException e) - { - return BadRequest(new { error = new { message = e.Message, value = e.Value } }); - } - catch (Exception e) - { - return BadRequest(new { error = new { message = e.Message, source = e.Source, trace = e.StackTrace } }); - } - - return Created(new Uri(Url.Link("GetFamilyByFamilyId", new { familyId = newFamily.FamilyId})), newFamily); + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); + + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + + var response = _imisModules.GetInsureeModule().GetFamilyLogic().AddMember(model); + + return Json(response); } - // PUT api/values/5 - [HttpPut("{familyId}")] - public async Task UpdateFamily(int familyId, [FromBody]FamilyModel family) + [HasRights(Rights.FamilyEdit)] + [HttpPost] + [Route("Families/Edit_Member_Family")] + public IActionResult Edit_Member_Family([FromBody]EditFamilyMember model) { - FamilyModel updatedFamily; - try - { - updatedFamily = await _imisModules.GetInsureeManagementModule().GetFamilyLogic().UpdateFamilyAsync(familyId, family); - } - catch (ValidationException e) - { - return BadRequest(new { error = new { message = e.Message, value = e.Value } }); - } - catch (Exception e) - { - return BadRequest(new { error = new { message = e.Message, source = e.Source, trace = e.StackTrace } }); - } - - return Ok(updatedFamily); - } - - // DELETE api/values/5 - [HttpDelete("{familyId}")] - public async Task Delete(int familyId) + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); + + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + + var response = _imisModules.GetInsureeModule().GetFamilyLogic().EditMember(model); + + return Json(response); + } + + [HasRights(Rights.FamilyDelete)] + [HttpPost] + [Route("Families/Delete_Member_Family")] + public IActionResult Delete_Member_Family([FromBody]string insureeNumber) { + //if (new ValidationBase().InsureeNumber(insureeNumber) != ValidationResult.Success) + //{ + // return BadRequest(new { error_occured = true, error_message = "1:Wrong format or missing insurance number of insuree" }); + //} + + int userId = Convert.ToInt32(HttpContext.User.Claims + .Where(w => w.Type == "UserId") + .Select(x => x.Value) + .FirstOrDefault()); + + _imisModules.GetInsureeModule().GetFamilyLogic().SetUserId(userId); + + var response = _imisModules.GetInsureeModule().GetFamilyLogic().DeleteMember(insureeNumber); - try - { - await _imisModules.GetInsureeManagementModule().GetFamilyLogic().DeleteFamilyAsync(familyId); - } - catch (ValidationException e) - { - return BadRequest(new { error = new { message = e.Message, value = e.Value } }); - } - catch (Exception e) - { - return BadRequest(new { error = new { message = e.Message, source = e.Source, trace = e.StackTrace } }); - } - - return Accepted(); + return Json(response); } } -} +} \ No newline at end of file diff --git a/OpenImis.RestApi/Controllers/LocationController.cs b/OpenImis.RestApi/Controllers/LocationController.cs deleted file mode 100644 index 47f8933d..00000000 --- a/OpenImis.RestApi/Controllers/LocationController.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Cors; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using OpenImis.Modules; -using OpenImis.Modules.MasterDataManagementModule.Models; - -// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 - -namespace OpenImis.RestApi.Controllers -{ - [ApiVersion("1")] - [Authorize(Roles = "IMISAdmin, EnrollmentOfficer")] - [Route("api/location")] - [ApiController] - [EnableCors("AllowSpecificOrigin")] - public class LocationController : Controller - { - private readonly IImisModules _imisModules; - - - public LocationController(IImisModules imisModules) - { - _imisModules = imisModules; - } - - /// - /// Get the list of Locations - /// - /// The list of Locations - /// - /// ### REMARKS ### - /// The following codes are returned - /// - 200 - The list of the families - /// - 401 - The token is invalid - /// - /// Returns the list of Locations - /// If the token is missing, is wrong or expired - [HttpGet] - [ProducesResponseType(typeof(LocationModel[]), 200)] - [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] - public async Task GetAllLocations() - { - LocationModel[] locations; - locations = await _imisModules.GetMasterDataManagementModule().GetLocationLogic().GetAllLocations(); - - return Ok(locations); - } - } -} diff --git a/OpenImis.RestApi/Controllers/LoginController.cs b/OpenImis.RestApi/Controllers/LoginController.cs index f9d5beb8..ed03b1db 100644 --- a/OpenImis.RestApi/Controllers/LoginController.cs +++ b/OpenImis.RestApi/Controllers/LoginController.cs @@ -16,6 +16,7 @@ namespace OpenImis.RestApi.Controllers { + [ApiVersionNeutral] [Authorize] [ApiController] [EnableCors("AllowSpecificOrigin")] diff --git a/OpenImis.RestApi/Controllers/LoginControllerV1.cs b/OpenImis.RestApi/Controllers/LoginControllerV1.cs deleted file mode 100644 index 7aab1356..00000000 --- a/OpenImis.RestApi/Controllers/LoginControllerV1.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; - -using OpenImis.RestApi.Protocol.LoginModel; -using Microsoft.AspNetCore.Authorization; -using System.IdentityModel.Tokens.Jwt; -using System.Security.Claims; -using Microsoft.IdentityModel.Tokens; -using System.Text; -using Microsoft.Extensions.Configuration; - -using OpenImis.Modules; -using System.ComponentModel.DataAnnotations; -using OpenImis.Modules.UserModule.Entities; -using Microsoft.AspNetCore.Cors; - -namespace OpenImis.RestApi.Controllers -{ - [ApiVersion("1")] - [Route("api/login")] - [ApiController] - [EnableCors("AllowSpecificOrigin")] - - public class LoginControllerV1 : ControllerBase - { - private readonly IConfiguration _configuration; - private readonly IImisModules _imisModules; - - /// - /// - /// - /// - /// - public LoginControllerV1(IConfiguration configuration, IImisModules imisModules) - { - _configuration = configuration; - _imisModules = imisModules; - } - - /// - /// Creates the JWT token - /// - /// - /// ### REMARKS ### - /// The following codes are returned - /// - 200 - New generated token - /// - 400 - The request is invalid - /// - 401 - Login credentials are invalid - /// - /// The LoginRequestModel containing the username and password - /// The token related information - /// Returns the token - /// If the request in incomplete - /// If the login credentials are wrong - [AllowAnonymous] - [HttpPost] - [ProducesResponseType(typeof(LoginResponseModel), 200)] - [ProducesResponseType(typeof(LoginBadRequestModel), StatusCodes.Status400BadRequest)] - [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] - public async Task Login([FromBody]LoginRequestModel request) - { - - //IUserSQL userRepository = _imisRepository.getUserRepository(); - - User user = await _imisModules.GetUserModule().GetUserController().GetByUsernameAndPasswordAsync(request.Username, request.Password); - - if (user!=null) - { - DateTime expirationDate = DateTime.Now.AddDays(double.Parse(_configuration["JwtExpireDays"])); - - IEnumerable claims = new[] - { - new Claim(ClaimTypes.Name, request.Username) - }; - - /*var roles = user.GetRolesStringArray(); - - foreach (var role in roles) - { - claims = claims.Append(new Claim(ClaimTypes.Role, role)); - }*/ - - //claims = claims.Append(new Claim("scope", "read:messages")); - - - var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(user.PrivateKey)); - var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); - - var token = new JwtSecurityToken( - issuer: _configuration["JwtIssuer"], - audience: _configuration["JwtIssuer"], - claims: claims, - expires: expirationDate, - signingCredentials: creds); - - return Ok(new LoginResponseModel - { - Token = new JwtSecurityTokenHandler().WriteToken(token), - Expires = expirationDate - }); - } - - return Unauthorized(); - } - } -} \ No newline at end of file diff --git a/OpenImis.RestApi/Controllers/MasterDataController.cs b/OpenImis.RestApi/Controllers/MasterDataController.cs deleted file mode 100644 index 844c03e5..00000000 --- a/OpenImis.RestApi/Controllers/MasterDataController.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Cors; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using OpenImis.Modules; -using OpenImis.RestApi.Protocol; - -namespace OpenImis.RestApi.Controllers -{ - [ApiVersion("1")] - [Authorize(Roles = "IMISAdmin, EnrollmentOfficer")] - [Route("api/master")] - [ApiController] - [EnableCors("AllowSpecificOrigin")] - public class MasterDataController : Controller - { - private readonly IImisModules _imisModules; - - - public MasterDataController(IImisModules imisModules) - { - _imisModules = imisModules; - } - - /// - /// Get the Master Data - /// - /// The Master Data - /// - /// ### REMARKS ### - /// The following codes are returned - /// - 200 - The Master Data - /// - 401 - The token is invalid - /// - /// Returns the list of Locations - /// If the token is missing, is wrong or expired - [HttpGet] - [ProducesResponseType(typeof(GetMasterDataResponse), 200)] - [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] - public async Task GetAllLocations() - { - GetMasterDataResponse masterDataResponse = new GetMasterDataResponse() - { - Locations = await _imisModules.GetMasterDataManagementModule().GetLocationLogic().GetAllLocations(), - FamilyTypes = await _imisModules.GetMasterDataManagementModule().GetFamilyTypeLogic().GetAllFamilyTypes(), - ConfirmationTypes = await _imisModules.GetMasterDataManagementModule().GetConfirmationTypeLogic().GetAllConfirmationTypes(), - EducationLevels = await _imisModules.GetMasterDataManagementModule().GetEducationLevelLogic().GetAllEducationLevels(), - GenderTypes = await _imisModules.GetMasterDataManagementModule().GetGenderTypeLogic().GetAllGenderTypes(), - RelationTypes = await _imisModules.GetMasterDataManagementModule().GetRelationTypeLogic().GetAllRelationTypes(), - ProfessionTypes = await _imisModules.GetMasterDataManagementModule().GetProfessionTypeLogic().GetAllProfessionTypes(), - IdentificationTypes = await _imisModules.GetMasterDataManagementModule().GetIdentificationTypeLogic().GetAllIdentificationTypes(), - }; - - return Ok(masterDataResponse); - } - - } -} \ No newline at end of file diff --git a/OpenImis.RestApi/Controllers/PaymentController.cs b/OpenImis.RestApi/Controllers/PaymentControllerV1.cs similarity index 97% rename from OpenImis.RestApi/Controllers/PaymentController.cs rename to OpenImis.RestApi/Controllers/PaymentControllerV1.cs index 327bb375..3bd2ac55 100644 --- a/OpenImis.RestApi/Controllers/PaymentController.cs +++ b/OpenImis.RestApi/Controllers/PaymentControllerV1.cs @@ -16,16 +16,17 @@ namespace OpenImis.RestApi.Controllers { + [ApiVersion("1")] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] - public class PaymentController : Controller + public class PaymentControllerV1 : Controller { private readonly IConfiguration _configuration; private readonly IImisModules _imisModules; public readonly IHostingEnvironment _hostingEnvironment; - public PaymentController(IConfiguration configuration, IHostingEnvironment hostingEnvironment, IImisModules imisModules) + public PaymentControllerV1(IConfiguration configuration, IHostingEnvironment hostingEnvironment, IImisModules imisModules) { _configuration = configuration; _hostingEnvironment = hostingEnvironment; diff --git a/OpenImis.RestApi/Controllers/PolicyController.cs b/OpenImis.RestApi/Controllers/PolicyControllerV1.cs similarity index 96% rename from OpenImis.RestApi/Controllers/PolicyController.cs rename to OpenImis.RestApi/Controllers/PolicyControllerV1.cs index 6a3d56eb..efa2dc48 100644 --- a/OpenImis.RestApi/Controllers/PolicyController.cs +++ b/OpenImis.RestApi/Controllers/PolicyControllerV1.cs @@ -10,14 +10,15 @@ namespace OpenImis.RestApi.Controllers { + [ApiVersion("1")] [Authorize] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] - public class PolicyController : Controller + public class PolicyControllerV1 : Controller { private readonly IImisModules _imisModules; - public PolicyController(IImisModules imisModules) + public PolicyControllerV1(IImisModules imisModules) { _imisModules = imisModules; } diff --git a/OpenImis.RestApi/Controllers/ValuesControllerV1.cs b/OpenImis.RestApi/Controllers/ValuesControllerV1.cs deleted file mode 100644 index b04d168b..00000000 --- a/OpenImis.RestApi/Controllers/ValuesControllerV1.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Cors; -using Microsoft.AspNetCore.Mvc; - -namespace OpenImis.RestApi.Controllers -{ - [ApiVersion("1")] - [Route("api/values")] - [ApiController] - [EnableCors("AllowSpecificOrigin")] - public class ValuesControllerV1 : Controller - { - // GET api/values - [Authorize(Roles = "EnrollmentOfficer")] - [HttpGet] - public async Task Get() - { - var result = new string[] { "value1", "value2", User.Identity.Name }; - return Ok(result); - } - - // GET api/values/5 - //[Authorize("read:messages")] - [Authorize("MedicalOfficer")] - [HttpGet("{id}")] - public async Task Get(int id) - { - return Ok(id); - } - - // POST api/values - // [HttpPost] - // public async Task Post([FromBody]string value) - // { - //return Ok(); - // } - - // // PUT api/values/5 - // [HttpPut("{id}")] - // public async Task Put(int id, [FromBody]string value) - // { - //return Ok(); - // } - - // // DELETE api/values/5 - // [HttpDelete("{id}")] - // public async Task Delete(int id) - // { - //return Ok(); - // } - } -} diff --git a/OpenImis.RestApi/Docs/AddRequiredHeaderParameter.cs b/OpenImis.RestApi/Docs/AddRequiredHeaderParameter.cs new file mode 100644 index 00000000..aeaefbfb --- /dev/null +++ b/OpenImis.RestApi/Docs/AddRequiredHeaderParameter.cs @@ -0,0 +1,27 @@ +using Swashbuckle.AspNetCore.Swagger; +using Swashbuckle.AspNetCore.SwaggerGen; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace OpenImis.RestApi.Docs +{ + public class AddRequiredHeaderParameter : IOperationFilter + { + public void Apply(Operation operation, OperationFilterContext context) + { + if (operation.Parameters == null) + operation.Parameters = new List(); + + operation.Parameters.Add(new NonBodyParameter + { + Name = "api-version", + In = "header", + Type = "int", + Required = false, + Description = "API version" + }); + } + } +} diff --git a/OpenImis.RestApi/Docs/SwaggerHelper.cs b/OpenImis.RestApi/Docs/SwaggerHelper.cs index 05288058..c0b09c9a 100644 --- a/OpenImis.RestApi/Docs/SwaggerHelper.cs +++ b/OpenImis.RestApi/Docs/SwaggerHelper.cs @@ -29,7 +29,9 @@ public static void ConfigureSwaggerGen(SwaggerGenOptions swaggerGenOptions) swaggerGenOptions.OperationFilter(); swaggerGenOptions.OperationFilter(); // Adds an Authorization input box to every endpoint swaggerGenOptions.OperationFilter(); // Adds "(Auth)" to the summary so that you can see which endpoints have Authorization - } + + swaggerGenOptions.OperationFilter(); + } private static void AddSwaggerDocPerVersion(SwaggerGenOptions swaggerGenOptions, Assembly webApiAssembly) { From 18f4e22baf5047e8b376c7fcf6bd2e716d1f1a70 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Mon, 29 Jul 2019 09:08:46 +0200 Subject: [PATCH 19/86] OS-36: The architecture of the versioning and modular application has been renewed --- .../ClaimModule/Models/DsiInputModel.cs | 13 -- .../CoverageModule/ICoverageModule.cs | 12 - .../Validators/InsureeNumberAttribute.cs | 1 - .../Helpers/Validators/RequiredIfAttribute.cs | 4 +- .../Validators/RequiredIfEoAttribute.cs | 4 +- OpenImis.Modules/IImisModules.cs | 35 +-- OpenImis.Modules/ImisModules.cs | 218 +----------------- .../Logic/FamilyLogic.cs | 10 +- .../InsureeModule/IInsureeModule.cs | 14 -- OpenImis.Modules/LoginModule/ILoginModule.cs | 12 - .../ClaimModule/ClaimModule.cs | 10 +- .../ClaimModule/IClaimModule.cs | 5 +- .../ClaimModule/Logic/ClaimLogic.cs | 6 +- .../ClaimModule/Logic/IClaimLogic.cs | 4 +- .../ClaimModule/Models/ClaimAdminModel.cs | 2 +- .../ClaimModule/Models/CodeName.cs | 2 +- .../ClaimModule/Models/CodeNamePrice.cs | 2 +- .../Models/DiagnosisServiceItem.cs | 2 +- .../ClaimModule/Models/DsiInputModel.cs | 13 ++ .../ClaimModule/Models/PaymentLists.cs | 2 +- .../Models/PaymentListsInputModel.cs | 7 +- .../Repositories/ClaimRepository.cs | 4 +- .../Repositories/IClaimRepository.cs | 4 +- .../CoverageModule/CoverageModule.cs | 10 +- .../Helpers/GetCoverageResponse.cs | 6 +- .../CoverageModule/Helpers/ImisApiResponse.cs | 4 +- .../Helpers/Messages/Language.cs | 2 +- .../Helpers/Messages/PrimaryLanguage.cs | 2 +- .../Helpers/Messages/SecondaryLanguage.cs | 2 +- .../CoverageModule/ICoverageModule.cs | 13 ++ .../CoverageModule/Logic/CoverageLogic.cs | 6 +- .../CoverageModule/Logic/ICoverageLogic.cs | 4 +- .../CoverageModule/Models/CoverageModel.cs | 2 +- .../CoverageModule/Models/CoverageProduct.cs | 2 +- .../CoverageModule}/Models/DataMessage.cs | 2 +- .../Repositories/CoverageRepository.cs | 4 +- .../Repositories/ICoverageRepository.cs | 4 +- .../Helpers/ConfigImisModules.cs | 44 ++++ .../Validators/InsureeNumberAttribute.cs | 26 +++ .../Validators/OfficerCodeAttribute.cs | 23 ++ .../Helpers/Validators/RequiredIfAttribute.cs | 44 ++++ .../Validators/RequiredIfEoAttribute.cs | 33 +++ .../Helpers/Validators/ValidDateAttribute.cs | 46 ++++ .../Helpers/Validators/Validation.cs | 36 +++ OpenImis.ModulesV1/IImisModules.cs | 24 ++ OpenImis.ModulesV1/ImisModules.cs | 183 +++++++++++++++ .../Helpers/DeleteMamberFamilyResponse.cs | 4 +- .../Helpers/EditFamilyResponse.cs | 4 +- .../Helpers/EditMemberFamilyResponse.cs | 4 +- .../Helpers/EnterContibutionResponse.cs | 4 +- .../Helpers/EnterFamilyResponse.cs | 4 +- .../Helpers/EnterMemberFamilyResponse.cs | 4 +- .../Helpers/EnterPolicyResponse.cs | 4 +- .../Helpers/GetCommissionResponse.cs | 4 +- .../Helpers/GetFamilyResponse.cs | 6 +- .../Helpers/GetMemberFamilyResponse.cs | 6 +- .../InsureeModule/Helpers/ImisApiResponse.cs | 4 +- .../Helpers/Messages/Language.cs | 2 +- .../Helpers/Messages/PrimaryLanguage.cs | 2 +- .../Helpers/Messages/SecondaryLanguage.cs | 2 +- .../Helpers/RenewPolicyResponse.cs | 4 +- .../InsureeModule/IInsureeModule.cs | 17 ++ .../InsureeModule/InsureeModule.cs | 33 ++- .../InsureeModule/Logic/ContributionLogic.cs | 6 +- .../InsureeModule/Logic/FamilyLogic.cs | 6 +- .../InsureeModule/Logic/IContributionLogic.cs | 4 +- .../InsureeModule/Logic/IFamilyLogic.cs | 4 +- .../InsureeModule/Logic/IPolicyLogic.cs | 4 +- .../InsureeModule/Logic/PolicyLogic.cs | 6 +- .../InsureeModule/Models/CommissionMode.cs | 2 +- .../InsureeModule/Models/Contribution.cs | 11 +- .../InsureeModule}/Models/DataMessage.cs | 2 +- .../InsureeModule/Models/EditFamilyMember.cs | 10 +- .../InsureeModule/Models/EditFamilyModel.cs | 9 +- .../InsureeModule/Models/Family.cs | 17 +- .../InsureeModule/Models/FamilyMember.cs | 12 +- .../InsureeModule/Models/FamilyModel.cs | 2 +- .../InsureeModule/Models/FamilyModelv2.cs | 2 +- .../InsureeModule/Models/FamilyModelv3.cs | 21 +- .../Models/GetCommissionInputs.cs | 2 +- .../InsureeModule/Models/Policy.cs | 11 +- .../InsureeModule/Models/ReactionType.cs | 2 +- .../Repositories/ContributionRepository.cs | 6 +- .../Repositories/FamilyRepository.cs | 6 +- .../Repositories/IContributionRepository.cs | 4 +- .../Repositories/IFamilyRepository.cs | 4 +- .../Repositories/IPolicyRepository.cs | 4 +- .../Repositories/PolicyRepository.cs | 6 +- .../LoginModule/ILoginModule.cs | 11 + .../LoginModule/Logic/ILoginLogic.cs | 4 +- .../LoginModule/Logic/LoginLogic.cs | 14 +- .../LoginModule/LoginModule.cs | 16 +- .../LoginModule}/Models/Language.cs | 2 +- .../LoginModule/Models/LoginModel.cs | 2 +- .../LoginModule/Models/UserData.cs | 2 +- .../LoginModule/Models/UserLogin.cs | 2 +- .../Models/ValidateCredentialsResponse.cs | 2 +- .../Repositories/ILoginRepository.cs | 4 +- .../Repositories/LoginRepository.cs | 4 +- OpenImis.ModulesV1/OpenImis.ModulesV1.csproj | 27 +++ .../Helpers/CtrlNumberResponse.cs | 4 +- .../Helpers/Extensions/StringExtensions.cs | 2 +- .../PaymentModule/Helpers/FamilyDefaults.cs | 2 +- .../PaymentModule/Helpers/ImisApiResponse.cs | 4 +- .../PaymentModule/Helpers/LocalDefault.cs | 4 +- .../PaymentModule/Helpers/MatchPayResponse.cs | 6 +- .../Helpers/Messages/Language.cs | 2 +- .../Helpers/Messages/PrimaryLanguage.cs | 2 +- .../Helpers/Messages/SecondaryLanguage.cs | 2 +- .../Helpers/RequestedCNResponse.cs | 8 +- .../PaymentModule/Helpers/SMS/ImisBaseSms.cs | 6 +- .../PaymentModule/Helpers/SMS/ImisSms.cs | 4 +- .../PaymentModule/Helpers/SaveAckResponse.cs | 4 +- .../Helpers/SaveIntentResponse.cs | 4 +- .../PaymentModule/Helpers/SavePayResponse.cs | 4 +- .../PaymentModule/IPaymentModule.cs | 5 +- .../PaymentModule/Logic/IPaymentLogic.cs | 6 +- .../PaymentModule/Logic/PaymentLogic.cs | 18 +- .../PaymentModule/Models/Acknowledgement.cs | 2 +- .../PaymentModule/Models/CnStatus.cs | 2 +- .../PaymentModule/Models/ControlNumberResp.cs | 2 +- .../PaymentModule}/Models/DataMessage.cs | 2 +- .../PaymentModule/Models/EnrolmentType.cs | 2 +- .../PaymentModule/Models/InsureeProduct.cs | 2 +- .../PaymentModule/Models/IntentOfPay.cs | 11 +- .../PaymentModule/Models/Language.cs | 12 + .../PaymentModule/Models/MatchModel.cs | 2 +- .../PaymentModule/Models/MatchSms.cs | 2 +- .../PaymentModule/Models/MatchedPayment.cs | 2 +- .../PaymentModule/Models/PaymentData.cs | 19 +- .../PaymentModule/Models/PaymentDetail.cs | 7 +- .../PaymentModule/Models/PaymentRequest.cs | 2 +- .../PaymentModule/Models/Request.cs | 2 +- .../Response/AsignedControlNumbersResponse.cs | 2 +- .../Models/Response/AssignedControlNumber.cs | 2 +- .../Models/Response/ErrorResponse.cs | 2 +- .../Models/Response/ErrorResponseV2.cs | 2 +- .../Models/Response/GetControlNumberResp.cs | 2 +- .../Models/Response/PaymentDataBadResp.cs | 2 +- .../Models/Response/PostReqCNResponse.cs | 2 +- .../PaymentModule/Models/SMS/SmsContainer.cs | 2 +- .../PaymentModule/Models/TypeOfPayment.cs | 2 +- .../PaymentModule/PaymentModule.cs | 16 +- .../Repositories/IPaymentRepository.cs | 6 +- .../Repositories/PaymentRepository.cs | 8 +- OpenImis.ModulesV1/Utils/LinqExtensions.cs | 45 ++++ OpenImis.ModulesV1/Utils/Models/PagerModel.cs | 18 ++ OpenImis.ModulesV1/Utils/TypeCast.cs | 34 +++ OpenImis.ModulesV2/ClaimModule/ClaimModule.cs | 28 +++ .../ClaimModule/IClaimModule.cs | 10 + .../ClaimModule/Logic/ClaimLogic.cs | 14 ++ .../ClaimModule/Logic/IClaimLogic.cs | 11 + .../CoverageModule/CoverageModule.cs | 31 +++ .../CoverageModule/ICoverageModule.cs | 11 + .../CoverageModule/Logic/CoverageLogic.cs | 17 ++ .../CoverageModule/Logic/ICoverageLogic.cs | 11 + .../Helpers/ConfigImisModules.cs | 43 ++++ .../Validators/InsureeNumberAttribute.cs | 26 +++ .../Validators/OfficerCodeAttribute.cs | 23 ++ .../Helpers/Validators/RequiredIfAttribute.cs | 43 ++++ .../Validators/RequiredIfEoAttribute.cs | 32 +++ .../Helpers/Validators/ValidDateAttribute.cs | 46 ++++ .../Helpers/Validators/Validation.cs | 36 +++ OpenImis.ModulesV2/IImisModules.cs | 24 ++ OpenImis.ModulesV2/ImisModules.cs | 181 +++++++++++++++ .../InsureeModule/IInsureeModule.cs | 15 ++ .../InsureeModule/InsureeModule.cs | 64 +++++ .../InsureeModule/Logic/ContributionLogic.cs | 17 ++ .../InsureeModule/Logic/FamilyLogic.cs | 18 ++ .../InsureeModule/Logic/IContributionLogic.cs | 11 + .../InsureeModule/Logic/IFamilyLogic.cs | 11 + .../InsureeModule/Logic/IPolicyLogic.cs | 11 + .../InsureeModule/Logic/PolicyLogic.cs | 14 ++ .../LoginModule/ILoginModule.cs | 10 + .../LoginModule/Logic/ILoginLogic.cs | 10 + .../LoginModule/Logic/LoginLogic.cs | 85 +++++++ OpenImis.ModulesV2/LoginModule/LoginModule.cs | 34 +++ .../LoginModule/Models/Language.cs | 2 +- .../LoginModule/Models/LoginModel.cs | 12 + .../LoginModule/Models/UserData.cs | 15 ++ .../LoginModule/Models/UserLogin.cs | 16 ++ .../Models/ValidateCredentialsResponse.cs | 12 + .../Repositories/ILoginRepository.cs | 14 ++ .../Repositories/LoginRepository.cs | 65 ++++++ OpenImis.ModulesV2/OpenImis.ModulesV2.csproj | 16 ++ .../PaymentModule/IPaymentModule.cs | 11 + .../PaymentModule/Logic/IPaymentLogic.cs | 12 + .../PaymentModule/Logic/PaymentLogic.cs | 16 ++ .../PaymentModule/PaymentModule.cs | 31 +++ OpenImis.ModulesV2/Utils/LinqExtensions.cs | 45 ++++ OpenImis.ModulesV2/Utils/Models/PagerModel.cs | 18 ++ OpenImis.ModulesV2/Utils/TypeCast.cs | 34 +++ .../Controllers/ClaimsControllerV1.cs | 10 +- .../Controllers/ContributionControllerV1.cs | 7 +- .../Controllers/CoverageControllerV1.cs | 13 +- .../Controllers/FamilyControllerV1.cs | 13 +- ...oginController.cs => LoginControllerV1.cs} | 13 +- .../Controllers/LoginControllerV2.cs | 105 +++++++++ .../Controllers/PaymentControllerV1.cs | 8 +- .../Controllers/PolicyControllerV1.cs | 4 +- OpenImis.RestApi/Escape/Sms/Headers.cs | 2 +- .../Protocol/GetMasterDataResponse.cs | 21 -- .../LoginModels/LoginBadRequestModel.cs | 2 +- .../Protocol/LoginModels/LoginRequestModel.cs | 2 +- .../LoginModels/LoginResponseModel.cs | 2 +- .../Security/AuthorizationPolicyProvider.cs | 40 ---- .../Security/HasAuthorityHandler.cs | 38 --- .../Security/HasAuthorityRequirement.cs | 20 -- .../Security/IMISJwtSecurityTokenHandler.cs | 29 ++- OpenImis.RestApi/Security/UserData.cs | 37 +++ OpenImis.RestApi/Startup.cs | 36 ++- OpenImis.RestApi/openImisModules.json | 60 +++-- 212 files changed, 2428 insertions(+), 812 deletions(-) delete mode 100644 OpenImis.Modules/ClaimModule/Models/DsiInputModel.cs delete mode 100644 OpenImis.Modules/CoverageModule/ICoverageModule.cs delete mode 100644 OpenImis.Modules/InsureeModule/IInsureeModule.cs delete mode 100644 OpenImis.Modules/LoginModule/ILoginModule.cs rename {OpenImis.Modules => OpenImis.ModulesV1}/ClaimModule/ClaimModule.cs (64%) rename {OpenImis.Modules => OpenImis.ModulesV1}/ClaimModule/IClaimModule.cs (51%) rename {OpenImis.Modules => OpenImis.ModulesV1}/ClaimModule/Logic/ClaimLogic.cs (89%) rename {OpenImis.Modules => OpenImis.ModulesV1}/ClaimModule/Logic/IClaimLogic.cs (80%) rename {OpenImis.Modules => OpenImis.ModulesV1}/ClaimModule/Models/ClaimAdminModel.cs (84%) rename {OpenImis.Modules => OpenImis.ModulesV1}/ClaimModule/Models/CodeName.cs (80%) rename {OpenImis.Modules => OpenImis.ModulesV1}/ClaimModule/Models/CodeNamePrice.cs (83%) rename {OpenImis.Modules => OpenImis.ModulesV1}/ClaimModule/Models/DiagnosisServiceItem.cs (87%) create mode 100644 OpenImis.ModulesV1/ClaimModule/Models/DsiInputModel.cs rename {OpenImis.Modules => OpenImis.ModulesV1}/ClaimModule/Models/PaymentLists.cs (89%) rename {OpenImis.Modules => OpenImis.ModulesV1}/ClaimModule/Models/PaymentListsInputModel.cs (69%) rename {OpenImis.Modules => OpenImis.ModulesV1}/ClaimModule/Repositories/ClaimRepository.cs (98%) rename {OpenImis.Modules => OpenImis.ModulesV1}/ClaimModule/Repositories/IClaimRepository.cs (79%) rename {OpenImis.Modules => OpenImis.ModulesV1}/CoverageModule/CoverageModule.cs (71%) rename {OpenImis.Modules => OpenImis.ModulesV1}/CoverageModule/Helpers/GetCoverageResponse.cs (90%) rename {OpenImis.Modules => OpenImis.ModulesV1}/CoverageModule/Helpers/ImisApiResponse.cs (91%) rename {OpenImis.Modules/InsureeModule => OpenImis.ModulesV1/CoverageModule}/Helpers/Messages/Language.cs (92%) rename {OpenImis.Modules/InsureeModule => OpenImis.ModulesV1/CoverageModule}/Helpers/Messages/PrimaryLanguage.cs (99%) rename {OpenImis.Modules/InsureeModule => OpenImis.ModulesV1/CoverageModule}/Helpers/Messages/SecondaryLanguage.cs (98%) create mode 100644 OpenImis.ModulesV1/CoverageModule/ICoverageModule.cs rename {OpenImis.Modules => OpenImis.ModulesV1}/CoverageModule/Logic/CoverageLogic.cs (81%) rename {OpenImis.Modules => OpenImis.ModulesV1}/CoverageModule/Logic/ICoverageLogic.cs (62%) rename {OpenImis.Modules => OpenImis.ModulesV1}/CoverageModule/Models/CoverageModel.cs (86%) rename {OpenImis.Modules => OpenImis.ModulesV1}/CoverageModule/Models/CoverageProduct.cs (96%) rename {OpenImis.Modules/PaymentModule => OpenImis.ModulesV1/CoverageModule}/Models/DataMessage.cs (85%) rename {OpenImis.Modules => OpenImis.ModulesV1}/CoverageModule/Repositories/CoverageRepository.cs (94%) rename {OpenImis.Modules => OpenImis.ModulesV1}/CoverageModule/Repositories/ICoverageRepository.cs (61%) create mode 100644 OpenImis.ModulesV1/Helpers/ConfigImisModules.cs create mode 100644 OpenImis.ModulesV1/Helpers/Validators/InsureeNumberAttribute.cs create mode 100644 OpenImis.ModulesV1/Helpers/Validators/OfficerCodeAttribute.cs create mode 100644 OpenImis.ModulesV1/Helpers/Validators/RequiredIfAttribute.cs create mode 100644 OpenImis.ModulesV1/Helpers/Validators/RequiredIfEoAttribute.cs create mode 100644 OpenImis.ModulesV1/Helpers/Validators/ValidDateAttribute.cs create mode 100644 OpenImis.ModulesV1/Helpers/Validators/Validation.cs create mode 100644 OpenImis.ModulesV1/IImisModules.cs create mode 100644 OpenImis.ModulesV1/ImisModules.cs rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Helpers/DeleteMamberFamilyResponse.cs (93%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Helpers/EditFamilyResponse.cs (96%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Helpers/EditMemberFamilyResponse.cs (96%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Helpers/EnterContibutionResponse.cs (96%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Helpers/EnterFamilyResponse.cs (97%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Helpers/EnterMemberFamilyResponse.cs (97%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Helpers/EnterPolicyResponse.cs (94%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Helpers/GetCommissionResponse.cs (92%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Helpers/GetFamilyResponse.cs (91%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Helpers/GetMemberFamilyResponse.cs (92%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Helpers/ImisApiResponse.cs (91%) rename {OpenImis.Modules/PaymentModule => OpenImis.ModulesV1/InsureeModule}/Helpers/Messages/Language.cs (92%) rename {OpenImis.Modules/CoverageModule => OpenImis.ModulesV1/InsureeModule}/Helpers/Messages/PrimaryLanguage.cs (99%) rename {OpenImis.Modules/CoverageModule => OpenImis.ModulesV1/InsureeModule}/Helpers/Messages/SecondaryLanguage.cs (98%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Helpers/RenewPolicyResponse.cs (94%) create mode 100644 OpenImis.ModulesV1/InsureeModule/IInsureeModule.cs rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/InsureeModule.cs (50%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Logic/ContributionLogic.cs (84%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Logic/FamilyLogic.cs (93%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Logic/IContributionLogic.cs (67%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Logic/IFamilyLogic.cs (84%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Logic/IPolicyLogic.cs (75%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Logic/PolicyLogic.cs (88%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Models/CommissionMode.cs (75%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Models/Contribution.cs (79%) rename {OpenImis.Modules/CoverageModule => OpenImis.ModulesV1/InsureeModule}/Models/DataMessage.cs (85%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Models/EditFamilyMember.cs (80%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Models/EditFamilyModel.cs (83%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Models/Family.cs (66%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Models/FamilyMember.cs (82%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Models/FamilyModel.cs (77%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Models/FamilyModelv2.cs (78%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Models/FamilyModelv3.cs (58%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Models/GetCommissionInputs.cs (91%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Models/Policy.cs (63%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Models/ReactionType.cs (75%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Repositories/ContributionRepository.cs (92%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Repositories/FamilyRepository.cs (99%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Repositories/IContributionRepository.cs (66%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Repositories/IFamilyRepository.cs (83%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Repositories/IPolicyRepository.cs (73%) rename {OpenImis.Modules => OpenImis.ModulesV1}/InsureeModule/Repositories/PolicyRepository.cs (96%) create mode 100644 OpenImis.ModulesV1/LoginModule/ILoginModule.cs rename {OpenImis.Modules => OpenImis.ModulesV1}/LoginModule/Logic/ILoginLogic.cs (69%) rename {OpenImis.Modules => OpenImis.ModulesV1}/LoginModule/Logic/LoginLogic.cs (87%) rename {OpenImis.Modules => OpenImis.ModulesV1}/LoginModule/LoginModule.cs (53%) rename {OpenImis.Modules/PaymentModule => OpenImis.ModulesV1/LoginModule}/Models/Language.cs (75%) rename {OpenImis.Modules => OpenImis.ModulesV1}/LoginModule/Models/LoginModel.cs (81%) rename {OpenImis.Modules => OpenImis.ModulesV1}/LoginModule/Models/UserData.cs (87%) rename {OpenImis.Modules => OpenImis.ModulesV1}/LoginModule/Models/UserLogin.cs (86%) rename {OpenImis.Modules => OpenImis.ModulesV1}/LoginModule/Models/ValidateCredentialsResponse.cs (82%) rename {OpenImis.Modules => OpenImis.ModulesV1}/LoginModule/Repositories/ILoginRepository.cs (69%) rename {OpenImis.Modules => OpenImis.ModulesV1}/LoginModule/Repositories/LoginRepository.cs (95%) create mode 100644 OpenImis.ModulesV1/OpenImis.ModulesV1.csproj rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/CtrlNumberResponse.cs (92%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/Extensions/StringExtensions.cs (95%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/FamilyDefaults.cs (85%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/ImisApiResponse.cs (91%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/LocalDefault.cs (97%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/MatchPayResponse.cs (89%) rename {OpenImis.Modules/CoverageModule => OpenImis.ModulesV1/PaymentModule}/Helpers/Messages/Language.cs (92%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/Messages/PrimaryLanguage.cs (99%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/Messages/SecondaryLanguage.cs (99%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/RequestedCNResponse.cs (89%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/SMS/ImisBaseSms.cs (95%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/SMS/ImisSms.cs (80%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/SaveAckResponse.cs (90%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/SaveIntentResponse.cs (96%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Helpers/SavePayResponse.cs (96%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/IPaymentModule.cs (50%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Logic/IPaymentLogic.cs (86%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Logic/PaymentLogic.cs (97%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/Acknowledgement.cs (87%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/CnStatus.cs (79%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/ControlNumberResp.cs (89%) rename {OpenImis.Modules/InsureeModule => OpenImis.ModulesV1/PaymentModule}/Models/DataMessage.cs (85%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/EnrolmentType.cs (74%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/InsureeProduct.cs (91%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/IntentOfPay.cs (74%) create mode 100644 OpenImis.ModulesV1/PaymentModule/Models/Language.cs rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/MatchModel.cs (84%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/MatchSms.cs (83%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/MatchedPayment.cs (88%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/PaymentData.cs (68%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/PaymentDetail.cs (85%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/PaymentRequest.cs (77%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/Request.cs (85%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs (81%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/Response/AssignedControlNumber.cs (79%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/Response/ErrorResponse.cs (74%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/Response/ErrorResponseV2.cs (78%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/Response/GetControlNumberResp.cs (84%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/Response/PaymentDataBadResp.cs (74%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/Response/PostReqCNResponse.cs (87%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/SMS/SmsContainer.cs (79%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Models/TypeOfPayment.cs (77%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/PaymentModule.cs (55%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Repositories/IPaymentRepository.cs (93%) rename {OpenImis.Modules => OpenImis.ModulesV1}/PaymentModule/Repositories/PaymentRepository.cs (99%) create mode 100644 OpenImis.ModulesV1/Utils/LinqExtensions.cs create mode 100644 OpenImis.ModulesV1/Utils/Models/PagerModel.cs create mode 100644 OpenImis.ModulesV1/Utils/TypeCast.cs create mode 100644 OpenImis.ModulesV2/ClaimModule/ClaimModule.cs create mode 100644 OpenImis.ModulesV2/ClaimModule/IClaimModule.cs create mode 100644 OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs create mode 100644 OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs create mode 100644 OpenImis.ModulesV2/CoverageModule/CoverageModule.cs create mode 100644 OpenImis.ModulesV2/CoverageModule/ICoverageModule.cs create mode 100644 OpenImis.ModulesV2/CoverageModule/Logic/CoverageLogic.cs create mode 100644 OpenImis.ModulesV2/CoverageModule/Logic/ICoverageLogic.cs create mode 100644 OpenImis.ModulesV2/Helpers/ConfigImisModules.cs create mode 100644 OpenImis.ModulesV2/Helpers/Validators/InsureeNumberAttribute.cs create mode 100644 OpenImis.ModulesV2/Helpers/Validators/OfficerCodeAttribute.cs create mode 100644 OpenImis.ModulesV2/Helpers/Validators/RequiredIfAttribute.cs create mode 100644 OpenImis.ModulesV2/Helpers/Validators/RequiredIfEoAttribute.cs create mode 100644 OpenImis.ModulesV2/Helpers/Validators/ValidDateAttribute.cs create mode 100644 OpenImis.ModulesV2/Helpers/Validators/Validation.cs create mode 100644 OpenImis.ModulesV2/IImisModules.cs create mode 100644 OpenImis.ModulesV2/ImisModules.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/IInsureeModule.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/InsureeModule.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Logic/ContributionLogic.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Logic/IContributionLogic.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs create mode 100644 OpenImis.ModulesV2/LoginModule/ILoginModule.cs create mode 100644 OpenImis.ModulesV2/LoginModule/Logic/ILoginLogic.cs create mode 100644 OpenImis.ModulesV2/LoginModule/Logic/LoginLogic.cs create mode 100644 OpenImis.ModulesV2/LoginModule/LoginModule.cs rename {OpenImis.Modules => OpenImis.ModulesV2}/LoginModule/Models/Language.cs (75%) create mode 100644 OpenImis.ModulesV2/LoginModule/Models/LoginModel.cs create mode 100644 OpenImis.ModulesV2/LoginModule/Models/UserData.cs create mode 100644 OpenImis.ModulesV2/LoginModule/Models/UserLogin.cs create mode 100644 OpenImis.ModulesV2/LoginModule/Models/ValidateCredentialsResponse.cs create mode 100644 OpenImis.ModulesV2/LoginModule/Repositories/ILoginRepository.cs create mode 100644 OpenImis.ModulesV2/LoginModule/Repositories/LoginRepository.cs create mode 100644 OpenImis.ModulesV2/OpenImis.ModulesV2.csproj create mode 100644 OpenImis.ModulesV2/PaymentModule/IPaymentModule.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Logic/IPaymentLogic.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Logic/PaymentLogic.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/PaymentModule.cs create mode 100644 OpenImis.ModulesV2/Utils/LinqExtensions.cs create mode 100644 OpenImis.ModulesV2/Utils/Models/PagerModel.cs create mode 100644 OpenImis.ModulesV2/Utils/TypeCast.cs rename OpenImis.RestApi/Controllers/{LoginController.cs => LoginControllerV1.cs} (91%) create mode 100644 OpenImis.RestApi/Controllers/LoginControllerV2.cs delete mode 100644 OpenImis.RestApi/Protocol/GetMasterDataResponse.cs delete mode 100644 OpenImis.RestApi/Security/AuthorizationPolicyProvider.cs delete mode 100644 OpenImis.RestApi/Security/HasAuthorityHandler.cs delete mode 100644 OpenImis.RestApi/Security/HasAuthorityRequirement.cs create mode 100644 OpenImis.RestApi/Security/UserData.cs diff --git a/OpenImis.Modules/ClaimModule/Models/DsiInputModel.cs b/OpenImis.Modules/ClaimModule/Models/DsiInputModel.cs deleted file mode 100644 index 4799e3c3..00000000 --- a/OpenImis.Modules/ClaimModule/Models/DsiInputModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using OpenImis.Modules.Helpers.Validators; -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenImis.Modules.ClaimModule.Models -{ - public class DsiInputModel - { - [ValidDate(ErrorMessage = "Please Enter A valid date format")] - public string last_update_date { get; set; } - } -} diff --git a/OpenImis.Modules/CoverageModule/ICoverageModule.cs b/OpenImis.Modules/CoverageModule/ICoverageModule.cs deleted file mode 100644 index dac9346f..00000000 --- a/OpenImis.Modules/CoverageModule/ICoverageModule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using OpenImis.Modules.CoverageModule.Logic; -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenImis.Modules.CoverageModule -{ - public interface ICoverageModule - { - ICoverageLogic GetCoverageLogic(); - } -} diff --git a/OpenImis.Modules/Helpers/Validators/InsureeNumberAttribute.cs b/OpenImis.Modules/Helpers/Validators/InsureeNumberAttribute.cs index 762a8853..33a4f3fa 100644 --- a/OpenImis.Modules/Helpers/Validators/InsureeNumberAttribute.cs +++ b/OpenImis.Modules/Helpers/Validators/InsureeNumberAttribute.cs @@ -1,6 +1,5 @@ using System; using System.ComponentModel.DataAnnotations; -using System.Text; namespace OpenImis.Modules.Helpers.Validators { diff --git a/OpenImis.Modules/Helpers/Validators/RequiredIfAttribute.cs b/OpenImis.Modules/Helpers/Validators/RequiredIfAttribute.cs index aab35e71..9fee5b1b 100644 --- a/OpenImis.Modules/Helpers/Validators/RequiredIfAttribute.cs +++ b/OpenImis.Modules/Helpers/Validators/RequiredIfAttribute.cs @@ -1,8 +1,6 @@ -using OpenImis.Modules.PaymentModule.Models; +using OpenImis.Modules.V1.PaymentModule.Models; using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Text; namespace OpenImis.Modules.Helpers.Validators { diff --git a/OpenImis.Modules/Helpers/Validators/RequiredIfEoAttribute.cs b/OpenImis.Modules/Helpers/Validators/RequiredIfEoAttribute.cs index 030b6705..4fc562fa 100644 --- a/OpenImis.Modules/Helpers/Validators/RequiredIfEoAttribute.cs +++ b/OpenImis.Modules/Helpers/Validators/RequiredIfEoAttribute.cs @@ -1,8 +1,6 @@ -using OpenImis.Modules.PaymentModule.Models; +using OpenImis.Modules.V1.PaymentModule.Models; using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Text; namespace OpenImis.Modules.Helpers.Validators { diff --git a/OpenImis.Modules/IImisModules.cs b/OpenImis.Modules/IImisModules.cs index 93f96892..ad496816 100644 --- a/OpenImis.Modules/IImisModules.cs +++ b/OpenImis.Modules/IImisModules.cs @@ -1,16 +1,4 @@ -using OpenImis.Modules.UserModule; -using OpenImis.Modules.InsureeManagementModule; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using OpenImis.Modules.MasterDataManagementModule; -using OpenImis.Modules.ClaimModule; -using OpenImis.Modules.InsureeModule; -using OpenImis.Modules.LoginModule; -using OpenImis.Modules.CoverageModule; -using OpenImis.Modules.PaymentModule; - + namespace OpenImis.Modules { /// @@ -18,27 +6,6 @@ namespace OpenImis.Modules /// public interface IImisModules { - IClaimModule GetClaimModule(); - - IInsureeModule GetInsureeModule(); - - ILoginModule GetLoginModule(); - - ICoverageModule GetCoverageModule(); - - IPaymentModule GetPaymentModule(); - - /// - /// Creates and returns the user management module. - /// - /// - /// The User module. - /// - IUserModule GetUserModule(); - - IInsureeManagementModule GetInsureeManagementModule(); - - IMasterDataManagementModule GetMasterDataManagementModule(); } } diff --git a/OpenImis.Modules/ImisModules.cs b/OpenImis.Modules/ImisModules.cs index 97b79967..0b17fe9f 100644 --- a/OpenImis.Modules/ImisModules.cs +++ b/OpenImis.Modules/ImisModules.cs @@ -1,224 +1,10 @@ using Microsoft.Extensions.Logging; -using OpenImis.Modules.UserModule; -using OpenImis.Modules.UserModule.Controllers; -using OpenImis.Modules.InsureeManagementModule; -using OpenImis.Modules.InsureeManagementModule.Logic; using System; -using System.Reflection; -using Microsoft.Extensions.Configuration; -using OpenImis.Modules.MasterDataManagementModule; -using OpenImis.Modules.MasterDataManagementModule.Logic; -using OpenImis.Modules.ClaimModule; -using OpenImis.Modules.InsureeModule; -using OpenImis.Modules.LoginModule; -using OpenImis.Modules.CoverageModule; -using OpenImis.Modules.PaymentModule; -using Microsoft.AspNetCore.Hosting; namespace OpenImis.Modules { - /// - /// Provides the entry point to the services. - /// - /// - /// The modules and the associated controllers are constructed based on the configuratîon. - /// Example of the configuration file: - /// { - /// "ImisModules": { - /// "UserModule": { - /// "UserController": "OpenImis.Modules.UserModule.Controllers.UserController" - /// }, - /// "WSModule": { - /// "FamilyController": "OpenImis.Modules.WSModule.Controllers.FamilyController", - /// "InsureeController": "OpenImis.Modules.WSModule.Controllers.InsureeController" - /// } - /// } - /// } - /// - public class ImisModules: IImisModules + public class ImisModules : IImisModules { - private IUserModule userModule; - private IInsureeManagementModule insureeManagementModule; - private IMasterDataManagementModule masterDataManagementModule; - - private IClaimModule claimModule; - private IInsureeModule insureeModule; - private ILoginModule loginModule; - private ICoverageModule coverageModule; - private IPaymentModule paymentModule; - - private readonly IConfiguration _configuration; - private readonly ILogger logger; - - public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory) - { - _configuration = configuration; - logger = loggerFactory.CreateLogger("LoggerCategory"); - } - - public IClaimModule GetClaimModule() - { - if (claimModule == null) - { - claimModule = new ClaimModule.ClaimModule(); - } - return claimModule; - } - - public IInsureeModule GetInsureeModule() - { - if (insureeModule == null) - { - insureeModule = new InsureeModule.InsureeModule(_configuration); - } - return insureeModule; - } - - public ILoginModule GetLoginModule() - { - if (loginModule == null) - { - loginModule = new LoginModule.LoginModule(_configuration); - } - return loginModule; - } - - public ICoverageModule GetCoverageModule() - { - if (coverageModule == null) - { - coverageModule = new CoverageModule.CoverageModule(_configuration); - } - return coverageModule; - } - - public IPaymentModule GetPaymentModule() - { - if (paymentModule == null) - { - paymentModule = new PaymentModule.PaymentModule(_configuration); - } - return paymentModule; - } - - /// - /// Creates and returns the user management module. - /// - /// - /// The User module. - /// - public IUserModule GetUserModule() - { - if (userModule == null) - { - userModule = new UserModule.UserModule(); - Type userControllerType = CreateTypeFromConfiguration("UserModule", "UserController", "OpenImis.Modules.UserModule.Controllers.UserController"); - - userModule.SetUserController((IUserController)Activator.CreateInstance(userControllerType)); - } - return userModule; - } - - /// - /// Creates and returns the Web Services integration module. - /// - /// - /// The Web Services integration module. - /// - public IInsureeManagementModule GetInsureeManagementModule() - { - if (insureeManagementModule == null) - { - insureeManagementModule = new InsureeManagementModule.InsureeManagementModule(this); - - Type insureeLogicType = CreateTypeFromConfiguration("InsureeManagementModule", "InsureeLogic", "OpenImis.Modules.InsureeManagementModule.Logic.InsureeLogic"); - insureeManagementModule.SetInsureeLogic((IInsureeLogic)Activator.CreateInstance(insureeLogicType, this)); - - Type familyLogicType = CreateTypeFromConfiguration("InsureeManagementModule", "FamilyLogic", "OpenImis.Modules.InsureeManagementModule.Logic.FamilyLogic"); - insureeManagementModule.SetFamilyLogic((IFamilyLogic)Activator.CreateInstance(familyLogicType, this)); - - } - return insureeManagementModule; - } - - /// - /// Creates and returns the Web Services integration module. - /// - /// - /// The Web Services integration module. - /// - public IMasterDataManagementModule GetMasterDataManagementModule() - { - if (masterDataManagementModule == null) - { - masterDataManagementModule = new MasterDataManagementModule.MasterDataManagementModule(this); - - Type locationLogicType = CreateTypeFromConfiguration("MasterDataManagementModule", "LocationLogic", "OpenImis.Modules.MasterDataManagementModule.Logic.LocationLogic"); - masterDataManagementModule.SetLocationLogic((ILocationLogic)Activator.CreateInstance(locationLogicType, this)); - - Type familyTypeLogicType = CreateTypeFromConfiguration("MasterDataManagementModule", "FamilyTypeLogic", "OpenImis.Modules.MasterDataManagementModule.Logic.FamilyTypeLogic"); - masterDataManagementModule.SetFamilyTypeLogic((IFamilyTypeLogic)Activator.CreateInstance(familyTypeLogicType, this)); - - Type confirmationTypeLogicType = CreateTypeFromConfiguration("MasterDataManagementModule", "ConfirmationTypeLogic", "OpenImis.Modules.MasterDataManagementModule.Logic.ConfirmationTypeLogic"); - masterDataManagementModule.SetConfirmationTypeLogic((IConfirmationTypeLogic)Activator.CreateInstance(confirmationTypeLogicType, this)); - - Type educationLevelLogicType = CreateTypeFromConfiguration("MasterDataManagementModule", "EducationLevelLogic", "OpenImis.Modules.MasterDataManagementModule.Logic.EducationLevelLogic"); - masterDataManagementModule.SetEducationLevelLogic((IEducationLevelLogic)Activator.CreateInstance(educationLevelLogicType, this)); - - Type genderTypeLogicType = CreateTypeFromConfiguration("MasterDataManagementModule", "GenderTypeLogic", "OpenImis.Modules.MasterDataManagementModule.Logic.GenderTypeLogic"); - masterDataManagementModule.SetGenderTypeLogic((IGenderTypeLogic)Activator.CreateInstance(genderTypeLogicType, this)); - - Type professionTypeLogicType = CreateTypeFromConfiguration("MasterDataManagementModule", "ProfessionTypeLogic", "OpenImis.Modules.MasterDataManagementModule.Logic.ProfessionTypeLogic"); - masterDataManagementModule.SetProfessionTypeLogic((IProfessionTypeLogic)Activator.CreateInstance(professionTypeLogicType, this)); - - Type identificationTypeLogicType = CreateTypeFromConfiguration("MasterDataManagementModule", "IdentificationTypeLogic", "OpenImis.Modules.MasterDataManagementModule.Logic.IdentificationTypeLogic"); - masterDataManagementModule.SetIdentificationTypeLogic((IIdentificationTypeLogic)Activator.CreateInstance(identificationTypeLogicType, this)); - - } - return masterDataManagementModule; - } - - /// - /// Creates and returns the type based on the string from the configuration - /// - /// The module name - /// The section name - /// The default section value - /// Type represented by the section - private Type CreateTypeFromConfiguration(string moduleName, string sectionName, string defaultValue) - { - - Type type; - - string part = ""; - - Assembly assembly = Assembly.GetCallingAssembly(); - - if (_configuration.GetSection("ImisModules:" + moduleName).Exists()) - { - var configSection = _configuration.GetSection("ImisModules:" + moduleName); - - if (configSection[sectionName] != null) - { - part = configSection[sectionName]; - } - } - - type = assembly.GetType(part); - - if (type == null) - { - logger.LogError(moduleName + " " + sectionName + " error: the type " + part + " was not found. Using default " + defaultValue + " configuration."); - - type = assembly.GetType(defaultValue); - } - else - { - logger.LogInformation(moduleName + " load OK: " + part); - } - - return type; - } - } + } } diff --git a/OpenImis.Modules/InsureeManagementModule/Logic/FamilyLogic.cs b/OpenImis.Modules/InsureeManagementModule/Logic/FamilyLogic.cs index b3df94d8..fcfaa9ee 100644 --- a/OpenImis.Modules/InsureeManagementModule/Logic/FamilyLogic.cs +++ b/OpenImis.Modules/InsureeManagementModule/Logic/FamilyLogic.cs @@ -121,11 +121,11 @@ public async Task AddFamilyAsync(FamilyModel family) // check each insuree number is correct and unique /// TODO: add only one validator for the Insuree class as it will be used here and in the InsureeLogic - IInsureeLogic insureeLogic = this.imisModules.GetInsureeManagementModule().GetInsureeLogic(); - UniqueInsureeNumberValidator uniqueInsureeNumberValidator = new UniqueInsureeNumberValidator(insureeLogic, insureeNumberValidator); - foreach (InsureeModel insuree in family.Insurees) { - await uniqueInsureeNumberValidator.ValidateAsync(insuree.CHFID); - } + //IInsureeLogic insureeLogic = this.imisModules.GetInsureeManagementModule().GetInsureeLogic(); + //UniqueInsureeNumberValidator uniqueInsureeNumberValidator = new UniqueInsureeNumberValidator(insureeLogic, insureeNumberValidator); + //foreach (InsureeModel insuree in family.Insurees) { + // await uniqueInsureeNumberValidator.ValidateAsync(insuree.CHFID); + //} #endregion diff --git a/OpenImis.Modules/InsureeModule/IInsureeModule.cs b/OpenImis.Modules/InsureeModule/IInsureeModule.cs deleted file mode 100644 index 651fcae4..00000000 --- a/OpenImis.Modules/InsureeModule/IInsureeModule.cs +++ /dev/null @@ -1,14 +0,0 @@ -using OpenImis.Modules.InsureeModule.Logic; -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenImis.Modules.InsureeModule -{ - public interface IInsureeModule - { - IFamilyLogic GetFamilyLogic(); - IContributionLogic GetContributionLogic(); - IPolicyLogic GetPolicyLogic(); - } -} diff --git a/OpenImis.Modules/LoginModule/ILoginModule.cs b/OpenImis.Modules/LoginModule/ILoginModule.cs deleted file mode 100644 index cbccb53b..00000000 --- a/OpenImis.Modules/LoginModule/ILoginModule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using OpenImis.Modules.LoginModule.Logic; -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenImis.Modules.LoginModule -{ - public interface ILoginModule - { - ILoginLogic GetLoginLogic(); - } -} diff --git a/OpenImis.Modules/ClaimModule/ClaimModule.cs b/OpenImis.ModulesV1/ClaimModule/ClaimModule.cs similarity index 64% rename from OpenImis.Modules/ClaimModule/ClaimModule.cs rename to OpenImis.ModulesV1/ClaimModule/ClaimModule.cs index 23696135..deb2a339 100644 --- a/OpenImis.Modules/ClaimModule/ClaimModule.cs +++ b/OpenImis.ModulesV1/ClaimModule/ClaimModule.cs @@ -1,9 +1,9 @@ -using OpenImis.Modules.ClaimModule.Logic; +using OpenImis.ModulesV1.ClaimModule.Logic; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.ClaimModule +namespace OpenImis.ModulesV1.ClaimModule { public class ClaimModule : IClaimModule { @@ -21,5 +21,11 @@ public IClaimLogic GetClaimLogic() } return _claimLogic; } + + public IClaimModule SetClaimLogic(IClaimLogic claimLogic) + { + _claimLogic = claimLogic; + return this; + } } } diff --git a/OpenImis.Modules/ClaimModule/IClaimModule.cs b/OpenImis.ModulesV1/ClaimModule/IClaimModule.cs similarity index 51% rename from OpenImis.Modules/ClaimModule/IClaimModule.cs rename to OpenImis.ModulesV1/ClaimModule/IClaimModule.cs index 5da9bbf1..ef20c655 100644 --- a/OpenImis.Modules/ClaimModule/IClaimModule.cs +++ b/OpenImis.ModulesV1/ClaimModule/IClaimModule.cs @@ -1,12 +1,13 @@ -using OpenImis.Modules.ClaimModule.Logic; +using OpenImis.ModulesV1.ClaimModule.Logic; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.ClaimModule +namespace OpenImis.ModulesV1.ClaimModule { public interface IClaimModule { IClaimLogic GetClaimLogic(); + IClaimModule SetClaimLogic(IClaimLogic claimLogic); } } diff --git a/OpenImis.Modules/ClaimModule/Logic/ClaimLogic.cs b/OpenImis.ModulesV1/ClaimModule/Logic/ClaimLogic.cs similarity index 89% rename from OpenImis.Modules/ClaimModule/Logic/ClaimLogic.cs rename to OpenImis.ModulesV1/ClaimModule/Logic/ClaimLogic.cs index 7c3358bb..31d04682 100644 --- a/OpenImis.Modules/ClaimModule/Logic/ClaimLogic.cs +++ b/OpenImis.ModulesV1/ClaimModule/Logic/ClaimLogic.cs @@ -1,11 +1,11 @@ using OpenImis.DB.SqlServer; -using OpenImis.Modules.ClaimModule.Models; -using OpenImis.Modules.ClaimModule.Repositories; +using OpenImis.ModulesV1.ClaimModule.Models; +using OpenImis.ModulesV1.ClaimModule.Repositories; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.ClaimModule.Logic +namespace OpenImis.ModulesV1.ClaimModule.Logic { public class ClaimLogic : IClaimLogic { diff --git a/OpenImis.Modules/ClaimModule/Logic/IClaimLogic.cs b/OpenImis.ModulesV1/ClaimModule/Logic/IClaimLogic.cs similarity index 80% rename from OpenImis.Modules/ClaimModule/Logic/IClaimLogic.cs rename to OpenImis.ModulesV1/ClaimModule/Logic/IClaimLogic.cs index a099bb9b..f8bf9432 100644 --- a/OpenImis.Modules/ClaimModule/Logic/IClaimLogic.cs +++ b/OpenImis.ModulesV1/ClaimModule/Logic/IClaimLogic.cs @@ -1,10 +1,10 @@ using OpenImis.DB.SqlServer; -using OpenImis.Modules.ClaimModule.Models; +using OpenImis.ModulesV1.ClaimModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.ClaimModule.Logic +namespace OpenImis.ModulesV1.ClaimModule.Logic { public interface IClaimLogic { diff --git a/OpenImis.Modules/ClaimModule/Models/ClaimAdminModel.cs b/OpenImis.ModulesV1/ClaimModule/Models/ClaimAdminModel.cs similarity index 84% rename from OpenImis.Modules/ClaimModule/Models/ClaimAdminModel.cs rename to OpenImis.ModulesV1/ClaimModule/Models/ClaimAdminModel.cs index ca5b19e6..cc6f7f47 100644 --- a/OpenImis.Modules/ClaimModule/Models/ClaimAdminModel.cs +++ b/OpenImis.ModulesV1/ClaimModule/Models/ClaimAdminModel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.ClaimModule.Models +namespace OpenImis.ModulesV1.ClaimModule.Models { public class ClaimAdminModel { diff --git a/OpenImis.Modules/ClaimModule/Models/CodeName.cs b/OpenImis.ModulesV1/ClaimModule/Models/CodeName.cs similarity index 80% rename from OpenImis.Modules/ClaimModule/Models/CodeName.cs rename to OpenImis.ModulesV1/ClaimModule/Models/CodeName.cs index d1f0aa42..f412d21b 100644 --- a/OpenImis.Modules/ClaimModule/Models/CodeName.cs +++ b/OpenImis.ModulesV1/ClaimModule/Models/CodeName.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.ClaimModule.Models +namespace OpenImis.ModulesV1.ClaimModule.Models { public class CodeName { diff --git a/OpenImis.Modules/ClaimModule/Models/CodeNamePrice.cs b/OpenImis.ModulesV1/ClaimModule/Models/CodeNamePrice.cs similarity index 83% rename from OpenImis.Modules/ClaimModule/Models/CodeNamePrice.cs rename to OpenImis.ModulesV1/ClaimModule/Models/CodeNamePrice.cs index 2d2a2e3c..df508c44 100644 --- a/OpenImis.Modules/ClaimModule/Models/CodeNamePrice.cs +++ b/OpenImis.ModulesV1/ClaimModule/Models/CodeNamePrice.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.ClaimModule.Models +namespace OpenImis.ModulesV1.ClaimModule.Models { public class CodeNamePrice { diff --git a/OpenImis.Modules/ClaimModule/Models/DiagnosisServiceItem.cs b/OpenImis.ModulesV1/ClaimModule/Models/DiagnosisServiceItem.cs similarity index 87% rename from OpenImis.Modules/ClaimModule/Models/DiagnosisServiceItem.cs rename to OpenImis.ModulesV1/ClaimModule/Models/DiagnosisServiceItem.cs index 5e53efe7..09bc3b64 100644 --- a/OpenImis.Modules/ClaimModule/Models/DiagnosisServiceItem.cs +++ b/OpenImis.ModulesV1/ClaimModule/Models/DiagnosisServiceItem.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.ClaimModule.Models +namespace OpenImis.ModulesV1.ClaimModule.Models { public class DiagnosisServiceItem { diff --git a/OpenImis.ModulesV1/ClaimModule/Models/DsiInputModel.cs b/OpenImis.ModulesV1/ClaimModule/Models/DsiInputModel.cs new file mode 100644 index 00000000..b0c88de6 --- /dev/null +++ b/OpenImis.ModulesV1/ClaimModule/Models/DsiInputModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV1.ClaimModule.Models +{ + public class DsiInputModel + { + // TODO ValidDate Attribute + //[ValidDate(ErrorMessage = "Please Enter A valid date format")] + public string last_update_date { get; set; } + } +} diff --git a/OpenImis.Modules/ClaimModule/Models/PaymentLists.cs b/OpenImis.ModulesV1/ClaimModule/Models/PaymentLists.cs similarity index 89% rename from OpenImis.Modules/ClaimModule/Models/PaymentLists.cs rename to OpenImis.ModulesV1/ClaimModule/Models/PaymentLists.cs index 2aba22a8..1a1a07ab 100644 --- a/OpenImis.Modules/ClaimModule/Models/PaymentLists.cs +++ b/OpenImis.ModulesV1/ClaimModule/Models/PaymentLists.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.ClaimModule.Models +namespace OpenImis.ModulesV1.ClaimModule.Models { public class PaymentLists { diff --git a/OpenImis.Modules/ClaimModule/Models/PaymentListsInputModel.cs b/OpenImis.ModulesV1/ClaimModule/Models/PaymentListsInputModel.cs similarity index 69% rename from OpenImis.Modules/ClaimModule/Models/PaymentListsInputModel.cs rename to OpenImis.ModulesV1/ClaimModule/Models/PaymentListsInputModel.cs index a5f640d5..8951b333 100644 --- a/OpenImis.Modules/ClaimModule/Models/PaymentListsInputModel.cs +++ b/OpenImis.ModulesV1/ClaimModule/Models/PaymentListsInputModel.cs @@ -1,16 +1,15 @@ -using OpenImis.Modules.Helpers.Validators; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.ClaimModule.Models +namespace OpenImis.ModulesV1.ClaimModule.Models { public class PaymentListsInputModel { [Required] public string claim_administrator_code { get; set; } - [ValidDate] + //[ValidDate] public string last_update_date { get; set; } } } diff --git a/OpenImis.Modules/ClaimModule/Repositories/ClaimRepository.cs b/OpenImis.ModulesV1/ClaimModule/Repositories/ClaimRepository.cs similarity index 98% rename from OpenImis.Modules/ClaimModule/Repositories/ClaimRepository.cs rename to OpenImis.ModulesV1/ClaimModule/Repositories/ClaimRepository.cs index 49557fad..16215474 100644 --- a/OpenImis.Modules/ClaimModule/Repositories/ClaimRepository.cs +++ b/OpenImis.ModulesV1/ClaimModule/Repositories/ClaimRepository.cs @@ -7,9 +7,9 @@ using Microsoft.EntityFrameworkCore.Internal; using Newtonsoft.Json; using OpenImis.DB.SqlServer; -using OpenImis.Modules.ClaimModule.Models; +using OpenImis.ModulesV1.ClaimModule.Models; -namespace OpenImis.Modules.ClaimModule.Repositories +namespace OpenImis.ModulesV1.ClaimModule.Repositories { public class ClaimRepository : IClaimRepository { diff --git a/OpenImis.Modules/ClaimModule/Repositories/IClaimRepository.cs b/OpenImis.ModulesV1/ClaimModule/Repositories/IClaimRepository.cs similarity index 79% rename from OpenImis.Modules/ClaimModule/Repositories/IClaimRepository.cs rename to OpenImis.ModulesV1/ClaimModule/Repositories/IClaimRepository.cs index b3a16c1c..31f9cadf 100644 --- a/OpenImis.Modules/ClaimModule/Repositories/IClaimRepository.cs +++ b/OpenImis.ModulesV1/ClaimModule/Repositories/IClaimRepository.cs @@ -1,10 +1,10 @@ using OpenImis.DB.SqlServer; -using OpenImis.Modules.ClaimModule.Models; +using OpenImis.ModulesV1.ClaimModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.ClaimModule.Repositories +namespace OpenImis.ModulesV1.ClaimModule.Repositories { public interface IClaimRepository { diff --git a/OpenImis.Modules/CoverageModule/CoverageModule.cs b/OpenImis.ModulesV1/CoverageModule/CoverageModule.cs similarity index 71% rename from OpenImis.Modules/CoverageModule/CoverageModule.cs rename to OpenImis.ModulesV1/CoverageModule/CoverageModule.cs index 6b84e2c4..d992e9fe 100644 --- a/OpenImis.Modules/CoverageModule/CoverageModule.cs +++ b/OpenImis.ModulesV1/CoverageModule/CoverageModule.cs @@ -1,10 +1,10 @@ using Microsoft.Extensions.Configuration; -using OpenImis.Modules.CoverageModule.Logic; +using OpenImis.ModulesV1.CoverageModule.Logic; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.CoverageModule +namespace OpenImis.ModulesV1.CoverageModule { public class CoverageModule : ICoverageModule { @@ -24,5 +24,11 @@ public ICoverageLogic GetCoverageLogic() } return _coverageLogic; } + + public ICoverageModule SetCoverageLogic(ICoverageLogic coverageLogic) + { + _coverageLogic = coverageLogic; + return this; + } } } diff --git a/OpenImis.Modules/CoverageModule/Helpers/GetCoverageResponse.cs b/OpenImis.ModulesV1/CoverageModule/Helpers/GetCoverageResponse.cs similarity index 90% rename from OpenImis.Modules/CoverageModule/Helpers/GetCoverageResponse.cs rename to OpenImis.ModulesV1/CoverageModule/Helpers/GetCoverageResponse.cs index 10ee57fe..d428b276 100644 --- a/OpenImis.Modules/CoverageModule/Helpers/GetCoverageResponse.cs +++ b/OpenImis.ModulesV1/CoverageModule/Helpers/GetCoverageResponse.cs @@ -1,12 +1,12 @@ using Newtonsoft.Json; -using OpenImis.Modules.CoverageModule.Helpers.Messages; -using OpenImis.Modules.CoverageModule.Models; +using OpenImis.ModulesV1.CoverageModule.Helpers.Messages; +using OpenImis.ModulesV1.CoverageModule.Models; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.CoverageModule.Helpers +namespace OpenImis.ModulesV1.CoverageModule.Helpers { public class GetCoverageResponse : ImisApiResponse { diff --git a/OpenImis.Modules/CoverageModule/Helpers/ImisApiResponse.cs b/OpenImis.ModulesV1/CoverageModule/Helpers/ImisApiResponse.cs similarity index 91% rename from OpenImis.Modules/CoverageModule/Helpers/ImisApiResponse.cs rename to OpenImis.ModulesV1/CoverageModule/Helpers/ImisApiResponse.cs index b02fdaf2..255d228b 100644 --- a/OpenImis.Modules/CoverageModule/Helpers/ImisApiResponse.cs +++ b/OpenImis.ModulesV1/CoverageModule/Helpers/ImisApiResponse.cs @@ -1,11 +1,11 @@ using Newtonsoft.Json; -using OpenImis.Modules.CoverageModule.Models; +using OpenImis.ModulesV1.CoverageModule.Models; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.CoverageModule.Helpers +namespace OpenImis.ModulesV1.CoverageModule.Helpers { public class ImisApiResponse { diff --git a/OpenImis.Modules/InsureeModule/Helpers/Messages/Language.cs b/OpenImis.ModulesV1/CoverageModule/Helpers/Messages/Language.cs similarity index 92% rename from OpenImis.Modules/InsureeModule/Helpers/Messages/Language.cs rename to OpenImis.ModulesV1/CoverageModule/Helpers/Messages/Language.cs index 788cf00e..153c50e2 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/Messages/Language.cs +++ b/OpenImis.ModulesV1/CoverageModule/Helpers/Messages/Language.cs @@ -3,7 +3,7 @@ using System.Reflection; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers.Messages +namespace OpenImis.ModulesV1.CoverageModule.Helpers.Messages { public class Language { diff --git a/OpenImis.Modules/InsureeModule/Helpers/Messages/PrimaryLanguage.cs b/OpenImis.ModulesV1/CoverageModule/Helpers/Messages/PrimaryLanguage.cs similarity index 99% rename from OpenImis.Modules/InsureeModule/Helpers/Messages/PrimaryLanguage.cs rename to OpenImis.ModulesV1/CoverageModule/Helpers/Messages/PrimaryLanguage.cs index 77669c0b..445f3cac 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/Messages/PrimaryLanguage.cs +++ b/OpenImis.ModulesV1/CoverageModule/Helpers/Messages/PrimaryLanguage.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers.Messages +namespace OpenImis.ModulesV1.CoverageModule.Helpers.Messages { public static class PrimaryLanguage { diff --git a/OpenImis.Modules/InsureeModule/Helpers/Messages/SecondaryLanguage.cs b/OpenImis.ModulesV1/CoverageModule/Helpers/Messages/SecondaryLanguage.cs similarity index 98% rename from OpenImis.Modules/InsureeModule/Helpers/Messages/SecondaryLanguage.cs rename to OpenImis.ModulesV1/CoverageModule/Helpers/Messages/SecondaryLanguage.cs index 5600c788..5dddb809 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/Messages/SecondaryLanguage.cs +++ b/OpenImis.ModulesV1/CoverageModule/Helpers/Messages/SecondaryLanguage.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers.Messages +namespace OpenImis.ModulesV1.CoverageModule.Helpers.Messages { public static class SecondaryLanguage { diff --git a/OpenImis.ModulesV1/CoverageModule/ICoverageModule.cs b/OpenImis.ModulesV1/CoverageModule/ICoverageModule.cs new file mode 100644 index 00000000..899e57f9 --- /dev/null +++ b/OpenImis.ModulesV1/CoverageModule/ICoverageModule.cs @@ -0,0 +1,13 @@ +using OpenImis.ModulesV1.CoverageModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV1.CoverageModule +{ + public interface ICoverageModule + { + ICoverageLogic GetCoverageLogic(); + ICoverageModule SetCoverageLogic(ICoverageLogic coverageLogic); + } +} diff --git a/OpenImis.Modules/CoverageModule/Logic/CoverageLogic.cs b/OpenImis.ModulesV1/CoverageModule/Logic/CoverageLogic.cs similarity index 81% rename from OpenImis.Modules/CoverageModule/Logic/CoverageLogic.cs rename to OpenImis.ModulesV1/CoverageModule/Logic/CoverageLogic.cs index 26986457..7eca7ca3 100644 --- a/OpenImis.Modules/CoverageModule/Logic/CoverageLogic.cs +++ b/OpenImis.ModulesV1/CoverageModule/Logic/CoverageLogic.cs @@ -1,11 +1,11 @@ using Microsoft.Extensions.Configuration; -using OpenImis.Modules.CoverageModule.Models; -using OpenImis.Modules.CoverageModule.Repositories; +using OpenImis.ModulesV1.CoverageModule.Models; +using OpenImis.ModulesV1.CoverageModule.Repositories; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.CoverageModule.Logic +namespace OpenImis.ModulesV1.CoverageModule.Logic { public class CoverageLogic : ICoverageLogic { diff --git a/OpenImis.Modules/CoverageModule/Logic/ICoverageLogic.cs b/OpenImis.ModulesV1/CoverageModule/Logic/ICoverageLogic.cs similarity index 62% rename from OpenImis.Modules/CoverageModule/Logic/ICoverageLogic.cs rename to OpenImis.ModulesV1/CoverageModule/Logic/ICoverageLogic.cs index 5b87bb81..cebbad6b 100644 --- a/OpenImis.Modules/CoverageModule/Logic/ICoverageLogic.cs +++ b/OpenImis.ModulesV1/CoverageModule/Logic/ICoverageLogic.cs @@ -1,9 +1,9 @@ -using OpenImis.Modules.CoverageModule.Models; +using OpenImis.ModulesV1.CoverageModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.CoverageModule.Logic +namespace OpenImis.ModulesV1.CoverageModule.Logic { public interface ICoverageLogic { diff --git a/OpenImis.Modules/CoverageModule/Models/CoverageModel.cs b/OpenImis.ModulesV1/CoverageModule/Models/CoverageModel.cs similarity index 86% rename from OpenImis.Modules/CoverageModule/Models/CoverageModel.cs rename to OpenImis.ModulesV1/CoverageModule/Models/CoverageModel.cs index e48ba670..104edcba 100644 --- a/OpenImis.Modules/CoverageModule/Models/CoverageModel.cs +++ b/OpenImis.ModulesV1/CoverageModule/Models/CoverageModel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.CoverageModule.Models +namespace OpenImis.ModulesV1.CoverageModule.Models { public class CoverageModel { diff --git a/OpenImis.Modules/CoverageModule/Models/CoverageProduct.cs b/OpenImis.ModulesV1/CoverageModule/Models/CoverageProduct.cs similarity index 96% rename from OpenImis.Modules/CoverageModule/Models/CoverageProduct.cs rename to OpenImis.ModulesV1/CoverageModule/Models/CoverageProduct.cs index fe20b77c..b3d8450b 100644 --- a/OpenImis.Modules/CoverageModule/Models/CoverageProduct.cs +++ b/OpenImis.ModulesV1/CoverageModule/Models/CoverageProduct.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.CoverageModule.Models +namespace OpenImis.ModulesV1.CoverageModule.Models { public class CoverageProduct { diff --git a/OpenImis.Modules/PaymentModule/Models/DataMessage.cs b/OpenImis.ModulesV1/CoverageModule/Models/DataMessage.cs similarity index 85% rename from OpenImis.Modules/PaymentModule/Models/DataMessage.cs rename to OpenImis.ModulesV1/CoverageModule/Models/DataMessage.cs index b30de232..aa42e476 100644 --- a/OpenImis.Modules/PaymentModule/Models/DataMessage.cs +++ b/OpenImis.ModulesV1/CoverageModule/Models/DataMessage.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.CoverageModule.Models { public class DataMessage { diff --git a/OpenImis.Modules/CoverageModule/Repositories/CoverageRepository.cs b/OpenImis.ModulesV1/CoverageModule/Repositories/CoverageRepository.cs similarity index 94% rename from OpenImis.Modules/CoverageModule/Repositories/CoverageRepository.cs rename to OpenImis.ModulesV1/CoverageModule/Repositories/CoverageRepository.cs index e974f57e..b32e3908 100644 --- a/OpenImis.Modules/CoverageModule/Repositories/CoverageRepository.cs +++ b/OpenImis.ModulesV1/CoverageModule/Repositories/CoverageRepository.cs @@ -3,7 +3,7 @@ using Newtonsoft.Json; using OpenImis.DB.SqlServer; using OpenImis.DB.SqlServer.DataHelper; -using OpenImis.Modules.CoverageModule.Models; +using OpenImis.ModulesV1.CoverageModule.Models; using System; using System.Collections.Generic; using System.Data; @@ -11,7 +11,7 @@ using System.Linq; using System.Text; -namespace OpenImis.Modules.CoverageModule.Repositories +namespace OpenImis.ModulesV1.CoverageModule.Repositories { public class CoverageRepository : ICoverageRepository { diff --git a/OpenImis.Modules/CoverageModule/Repositories/ICoverageRepository.cs b/OpenImis.ModulesV1/CoverageModule/Repositories/ICoverageRepository.cs similarity index 61% rename from OpenImis.Modules/CoverageModule/Repositories/ICoverageRepository.cs rename to OpenImis.ModulesV1/CoverageModule/Repositories/ICoverageRepository.cs index 5b03164a..2035de2b 100644 --- a/OpenImis.Modules/CoverageModule/Repositories/ICoverageRepository.cs +++ b/OpenImis.ModulesV1/CoverageModule/Repositories/ICoverageRepository.cs @@ -1,9 +1,9 @@ -using OpenImis.Modules.CoverageModule.Models; +using OpenImis.ModulesV1.CoverageModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.CoverageModule.Repositories +namespace OpenImis.ModulesV1.CoverageModule.Repositories { public interface ICoverageRepository { diff --git a/OpenImis.ModulesV1/Helpers/ConfigImisModules.cs b/OpenImis.ModulesV1/Helpers/ConfigImisModules.cs new file mode 100644 index 00000000..090ffb89 --- /dev/null +++ b/OpenImis.ModulesV1/Helpers/ConfigImisModules.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; + +namespace OpenImis.ModulesV1.Helpers +{ + public class ConfigImisModules + { + public string Version { get; set; } + public LoginModule LoginModule { get; set; } + public ClaimModule ClaimModule { get; set; } + public CoverageModule CoverageModule { get; set; } + public InsureeModule InsureeModule { get; set; } + public PaymentModule PaymentModule { get; set; } + } + + public class LoginModule + { + public string LoginLogic { get; set; } + } + + public class ClaimModule + { + public string ClaimLogic { get; set; } + } + + public class CoverageModule + { + public string CoverageLogic { get; set; } + } + + public class InsureeModule + { + public string FamilyLogic { get; set; } + public string PolicyLogic { get; set; } + public string ContributionLogic { get; set; } + } + + public class PaymentModule + { + public string PaymentLogic { get; set; } + } +} diff --git a/OpenImis.ModulesV1/Helpers/Validators/InsureeNumberAttribute.cs b/OpenImis.ModulesV1/Helpers/Validators/InsureeNumberAttribute.cs new file mode 100644 index 00000000..362a1336 --- /dev/null +++ b/OpenImis.ModulesV1/Helpers/Validators/InsureeNumberAttribute.cs @@ -0,0 +1,26 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace OpenImis.ModulesV1.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class InsureeNumberAttribute : ValidationAttribute + { + public InsureeNumberAttribute() + { + } + + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + if (value != null) + { + Validation val = new Validation(); + ValidationResult result = val.InsureeNumber(value.ToString()); + + return result; + } + + return ValidationResult.Success; + } + } +} diff --git a/OpenImis.ModulesV1/Helpers/Validators/OfficerCodeAttribute.cs b/OpenImis.ModulesV1/Helpers/Validators/OfficerCodeAttribute.cs new file mode 100644 index 00000000..3ee10d58 --- /dev/null +++ b/OpenImis.ModulesV1/Helpers/Validators/OfficerCodeAttribute.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.ModulesV1.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class OfficerCodeAttribute : ValidationAttribute + { + public OfficerCodeAttribute() + { + } + + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + Validation val = new Validation(); + ValidationResult result = val.OfficerCode(value); + + return result; + } + } +} diff --git a/OpenImis.ModulesV1/Helpers/Validators/RequiredIfAttribute.cs b/OpenImis.ModulesV1/Helpers/Validators/RequiredIfAttribute.cs new file mode 100644 index 00000000..33ba5583 --- /dev/null +++ b/OpenImis.ModulesV1/Helpers/Validators/RequiredIfAttribute.cs @@ -0,0 +1,44 @@ +using OpenImis.ModulesV1.PaymentModule.Models; +using System; +using System.ComponentModel.DataAnnotations; + +namespace OpenImis.ModulesV1.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class RequiredIfAttribute : ValidationAttribute + { + private string _fieldName; + private int _fieldNumber; + + public RequiredIfAttribute(string fieldName, int fieldNumber = 0) // fieldNumber = 1:control_number 2:insurance_number, 3:insurance_product_code, 4:renewal, 5:enrolment_officer_code + { + _fieldName = fieldName; + _fieldNumber = fieldNumber; + } + + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + PaymentData payment = (PaymentData)validationContext.ObjectInstance; + + if (payment.control_number == null && value == null) + { + if (_fieldNumber == 2 && payment.insurance_number != null) + { + return ValidationResult.Success; + } + else + { + return new ValidationResult(_fieldName + " is required if Control Number is not provided"); + } + } + if (payment.control_number != null && value != null) + { + return new ValidationResult(_fieldName + " is not required if Control Number is provided"); + } + else + { + return ValidationResult.Success; + } + } + } +} diff --git a/OpenImis.ModulesV1/Helpers/Validators/RequiredIfEoAttribute.cs b/OpenImis.ModulesV1/Helpers/Validators/RequiredIfEoAttribute.cs new file mode 100644 index 00000000..e17047d7 --- /dev/null +++ b/OpenImis.ModulesV1/Helpers/Validators/RequiredIfEoAttribute.cs @@ -0,0 +1,33 @@ +using OpenImis.ModulesV1.PaymentModule.Models; +using System; +using System.ComponentModel.DataAnnotations; + +namespace OpenImis.ModulesV1.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class RequiredIfEoAttribute : ValidationAttribute + { + private string _fieldName; + private int _fieldNumber; + + public RequiredIfEoAttribute(string fieldName) // fieldNumber = 1:control_number 2:insurance_number, 3:insurance_product_code, 4:renewal, 5:enrolment_officer_code + { + _fieldName = fieldName; + } + + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + IntentOfPay intent = (IntentOfPay)validationContext.ObjectInstance; + + if (intent.enrolment_officer_code == null && value != null && Convert.ToInt32(value) != 0) + { + return new ValidationResult(_fieldName + " is not required if Enrolment officer is not provided"); + } + else + { + return ValidationResult.Success; + } + + } + } +} diff --git a/OpenImis.ModulesV1/Helpers/Validators/ValidDateAttribute.cs b/OpenImis.ModulesV1/Helpers/Validators/ValidDateAttribute.cs new file mode 100644 index 00000000..d4cad692 --- /dev/null +++ b/OpenImis.ModulesV1/Helpers/Validators/ValidDateAttribute.cs @@ -0,0 +1,46 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Globalization; + +namespace OpenImis.ModulesV1.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class ValidDateAttribute : ValidationAttribute + { + public ValidDateAttribute() + { + } + + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + if (value == null) + return ValidationResult.Success; + + try + { + DateTime date = Convert.ToDateTime(value.ToString()); + DateTime Odate; + + if (date.Year > 1753) + { + if (DateTime.TryParseExact(value.ToString(), "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out Odate)) + { + return ValidationResult.Success; + } + else + { + return new ValidationResult(null); + } + } + else + { + return new ValidationResult(null); + } + } + catch (Exception) + { + return new ValidationResult(null); + } + } + } +} diff --git a/OpenImis.ModulesV1/Helpers/Validators/Validation.cs b/OpenImis.ModulesV1/Helpers/Validators/Validation.cs new file mode 100644 index 00000000..c704fa97 --- /dev/null +++ b/OpenImis.ModulesV1/Helpers/Validators/Validation.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.ModulesV1.Helpers.Validators +{ + public class Validation + { + public virtual ValidationResult InsureeNumber(string insureeNumber) + { + if (insureeNumber != null) + { + if (insureeNumber.Length < 12 && insureeNumber.Length > 0) + return ValidationResult.Success; + else + return new ValidationResult("1:Wrong format of insurance number "); + } + + return ValidationResult.Success; + } + + public virtual ValidationResult OfficerCode(object value) + { + if (value != null) + { + if (value.ToString().Length < 8) + return ValidationResult.Success; + else + return new ValidationResult("3:Not valid enrolment officer code"); + } + + return ValidationResult.Success; + } + } +} diff --git a/OpenImis.ModulesV1/IImisModules.cs b/OpenImis.ModulesV1/IImisModules.cs new file mode 100644 index 00000000..d32f750f --- /dev/null +++ b/OpenImis.ModulesV1/IImisModules.cs @@ -0,0 +1,24 @@ +using OpenImis.ModulesV1.ClaimModule; +using OpenImis.ModulesV1.CoverageModule; +using OpenImis.ModulesV1.InsureeModule; +using OpenImis.ModulesV1.LoginModule; +using OpenImis.ModulesV1.PaymentModule; + +namespace OpenImis.ModulesV1 +{ + /// + /// This interface serves to define a Service for the IMIS modules + /// + public interface IImisModules + { + ILoginModule GetLoginModule(); + + IClaimModule GetClaimModule(); + + IInsureeModule GetInsureeModule(); + + ICoverageModule GetCoverageModule(); + + IPaymentModule GetPaymentModule(); + } +} diff --git a/OpenImis.ModulesV1/ImisModules.cs b/OpenImis.ModulesV1/ImisModules.cs new file mode 100644 index 00000000..f5085da1 --- /dev/null +++ b/OpenImis.ModulesV1/ImisModules.cs @@ -0,0 +1,183 @@ +using System.Reflection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Configuration; +using System; +using OpenImis.ModulesV1.LoginModule; +using OpenImis.ModulesV1.InsureeModule; +using OpenImis.ModulesV1.ClaimModule; +using OpenImis.ModulesV1.CoverageModule; +using OpenImis.ModulesV1.PaymentModule; +using Microsoft.Extensions.DependencyInjection; +using OpenImis.ModulesV1.Helpers; +using System.Collections.Generic; +using Newtonsoft.Json; +using System.Diagnostics; +using System.Linq; + +namespace OpenImis.ModulesV1 +{ + public class ImisModules : IImisModules + { + private ILoginModule loginModule; + + private IInsureeModule insureeModule; + private IClaimModule claimModule; + private ICoverageModule coverageModule; + private IPaymentModule paymentModule; + + private readonly IConfiguration _configuration; + private readonly ILogger _logger; + private readonly IServiceProvider _serviceProvider; + + public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory, IServiceProvider serviceProvider) + { + _configuration = configuration; + _logger = loggerFactory.CreateLogger("LoggerCategory"); + _serviceProvider = serviceProvider; + } + + /// + /// Creates and returns the login module. + /// + /// + /// The Login module. + /// + public ILoginModule GetLoginModule() + { + if (loginModule == null) + { + loginModule = new LoginModule.LoginModule(_configuration); + + Type loginLogicType = CreateTypeFromConfiguration("LoginModule", "LoginLogic", "OpenImis.ModulesV1.LoginModule.Logic.LoginLogic"); + loginModule.SetLoginLogic((LoginModule.Logic.ILoginLogic)ActivatorUtilities.CreateInstance(_serviceProvider, loginLogicType)); + } + return loginModule; + } + + /// + /// Creates and returns the claim module version 1. + /// + /// + /// The Claim module V1. + /// + public IClaimModule GetClaimModule() + { + if (claimModule == null) + { + claimModule = new ClaimModule.ClaimModule(); + + Type claimLogicType = CreateTypeFromConfiguration("ClaimModule", "ClaimLogic", "OpenImis.ModulesV1.ClaimModule.Logic.ClaimLogic"); + claimModule.SetClaimLogic((ClaimModule.Logic.IClaimLogic)ActivatorUtilities.CreateInstance(_serviceProvider, claimLogicType)); + } + return claimModule; + } + + /// + /// Creates and returns the insuree module version 1. + /// + /// + /// The Insuree module V1. + /// + public IInsureeModule GetInsureeModule() + { + if (insureeModule == null) + { + insureeModule = new InsureeModule.InsureeModule(_configuration); + + Type familyLogicType = CreateTypeFromConfiguration("InsureeModule", "FamilyLogic", "OpenImis.ModulesV1.InsureeModule.Logic.FamilyLogic"); + insureeModule.SetFamilyLogic((InsureeModule.Logic.IFamilyLogic)ActivatorUtilities.CreateInstance(_serviceProvider, familyLogicType)); + + Type policyLogicType = CreateTypeFromConfiguration("InsureeModule", "PolicyLogic", "OpenImis.ModulesV1.InsureeModule.Logic.PolicyLogic"); + insureeModule.SetPolicyLogic((InsureeModule.Logic.IPolicyLogic)ActivatorUtilities.CreateInstance(_serviceProvider, policyLogicType)); + + Type contributionLogicType = CreateTypeFromConfiguration("InsureeModule", "ContributionLogic", "OpenImis.ModulesV1.InsureeModule.Logic.ContributionLogic"); + insureeModule.SetContributionLogic((InsureeModule.Logic.IContributionLogic)ActivatorUtilities.CreateInstance(_serviceProvider, contributionLogicType)); + } + return insureeModule; + } + + /// + /// Creates and returns the payment module version 1. + /// + /// + /// The Payment module V1. + /// + public ICoverageModule GetCoverageModule() + { + if (coverageModule == null) + { + coverageModule = new CoverageModule.CoverageModule(_configuration); + + Type coverageLogicType = CreateTypeFromConfiguration("CoverageModule", "CoverageLogic", "OpenImis.ModulesV1.CoverageModule.Logic.CoverageLogic"); + coverageModule.SetCoverageLogic((CoverageModule.Logic.ICoverageLogic)ActivatorUtilities.CreateInstance(_serviceProvider, coverageLogicType)); + } + return coverageModule; + } + + /// + /// Creates and returns the payment module version 1. + /// + /// + /// The Payment module V1. + /// + public IPaymentModule GetPaymentModule() + { + if (paymentModule == null) + { + paymentModule = new PaymentModule.PaymentModule(_configuration); + + Type paymentLogicType = CreateTypeFromConfiguration("PaymentModule", "PaymentLogic", "OpenImis.ModulesV1.PaymentModule.Logic.PaymentLogic"); + paymentModule.SetPaymentLogic((PaymentModule.Logic.IPaymentLogic)ActivatorUtilities.CreateInstance(_serviceProvider, paymentLogicType)); + } + return paymentModule; + } + + /// + /// Creates and returns the type based on the string from the configuration + /// + /// The module name + /// The section name + /// The default section value + /// Type represented by the section + private Type CreateTypeFromConfiguration(string moduleName, string sectionName, string defaultValue) + { + Type type; + + string part = ""; + + Assembly assembly = Assembly.GetCallingAssembly(); + + var listImisModules = _configuration.GetSection("ImisModules").Get>(); + + if (listImisModules.Where(v => v.Version == "1").Any(x => GetPropValue(x, moduleName) != null)) + { + object module = listImisModules.Where(v => v.Version == "1").Select(x => GetPropValue(x, moduleName)).FirstOrDefault(); + + if (GetPropValue(module, sectionName) != null) + { + part = GetPropValue(module, sectionName).ToString(); + } + } + + type = assembly.GetType(part); + + if (type == null) + { + _logger.LogError(moduleName + " " + sectionName + " error: the type " + part + " was not found. Using default " + defaultValue + " configuration."); + + type = assembly.GetType(defaultValue); + } + else + { + _logger.LogInformation(moduleName + " load OK: " + part); + } + + return type; + } + + public static object GetPropValue(object src, string propName) + { + return src.GetType().GetProperty(propName).GetValue(src, null); + } + } +} \ No newline at end of file diff --git a/OpenImis.Modules/InsureeModule/Helpers/DeleteMamberFamilyResponse.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/DeleteMamberFamilyResponse.cs similarity index 93% rename from OpenImis.Modules/InsureeModule/Helpers/DeleteMamberFamilyResponse.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/DeleteMamberFamilyResponse.cs index 759af700..369028db 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/DeleteMamberFamilyResponse.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/DeleteMamberFamilyResponse.cs @@ -1,10 +1,10 @@ -using OpenImis.Modules.InsureeModule.Helpers.Messages; +using OpenImis.ModulesV1.InsureeModule.Helpers.Messages; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers +namespace OpenImis.ModulesV1.InsureeModule.Helpers { public class DeleteMamberFamilyResponse : ImisApiResponse { diff --git a/OpenImis.Modules/InsureeModule/Helpers/EditFamilyResponse.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/EditFamilyResponse.cs similarity index 96% rename from OpenImis.Modules/InsureeModule/Helpers/EditFamilyResponse.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/EditFamilyResponse.cs index 3c853689..205b81b5 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/EditFamilyResponse.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/EditFamilyResponse.cs @@ -1,10 +1,10 @@ -using OpenImis.Modules.InsureeModule.Helpers.Messages; +using OpenImis.ModulesV1.InsureeModule.Helpers.Messages; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers +namespace OpenImis.ModulesV1.InsureeModule.Helpers { public class EditFamilyResponse : ImisApiResponse { diff --git a/OpenImis.Modules/InsureeModule/Helpers/EditMemberFamilyResponse.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/EditMemberFamilyResponse.cs similarity index 96% rename from OpenImis.Modules/InsureeModule/Helpers/EditMemberFamilyResponse.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/EditMemberFamilyResponse.cs index 6d650e14..cfd71679 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/EditMemberFamilyResponse.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/EditMemberFamilyResponse.cs @@ -1,10 +1,10 @@ -using OpenImis.Modules.InsureeModule.Helpers.Messages; +using OpenImis.ModulesV1.InsureeModule.Helpers.Messages; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers +namespace OpenImis.ModulesV1.InsureeModule.Helpers { public class EditMemberFamilyResponse : ImisApiResponse { diff --git a/OpenImis.Modules/InsureeModule/Helpers/EnterContibutionResponse.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/EnterContibutionResponse.cs similarity index 96% rename from OpenImis.Modules/InsureeModule/Helpers/EnterContibutionResponse.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/EnterContibutionResponse.cs index c6728e60..a46593fd 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/EnterContibutionResponse.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/EnterContibutionResponse.cs @@ -1,10 +1,10 @@ -using OpenImis.Modules.InsureeModule.Helpers.Messages; +using OpenImis.ModulesV1.InsureeModule.Helpers.Messages; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers +namespace OpenImis.ModulesV1.InsureeModule.Helpers { public class EnterContibutionResponse : ImisApiResponse { diff --git a/OpenImis.Modules/InsureeModule/Helpers/EnterFamilyResponse.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/EnterFamilyResponse.cs similarity index 97% rename from OpenImis.Modules/InsureeModule/Helpers/EnterFamilyResponse.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/EnterFamilyResponse.cs index cf1654a1..dea8be6c 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/EnterFamilyResponse.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/EnterFamilyResponse.cs @@ -1,9 +1,9 @@ -using OpenImis.Modules.InsureeModule.Helpers.Messages; +using OpenImis.ModulesV1.InsureeModule.Helpers.Messages; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers +namespace OpenImis.ModulesV1.InsureeModule.Helpers { public class EnterFamilyResponse : ImisApiResponse { diff --git a/OpenImis.Modules/InsureeModule/Helpers/EnterMemberFamilyResponse.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/EnterMemberFamilyResponse.cs similarity index 97% rename from OpenImis.Modules/InsureeModule/Helpers/EnterMemberFamilyResponse.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/EnterMemberFamilyResponse.cs index bfbb6fdc..dc9e6a3b 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/EnterMemberFamilyResponse.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/EnterMemberFamilyResponse.cs @@ -1,10 +1,10 @@ -using OpenImis.Modules.InsureeModule.Helpers.Messages; +using OpenImis.ModulesV1.InsureeModule.Helpers.Messages; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers +namespace OpenImis.ModulesV1.InsureeModule.Helpers { public class EnterMemberFamilyResponse : ImisApiResponse { diff --git a/OpenImis.Modules/InsureeModule/Helpers/EnterPolicyResponse.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/EnterPolicyResponse.cs similarity index 94% rename from OpenImis.Modules/InsureeModule/Helpers/EnterPolicyResponse.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/EnterPolicyResponse.cs index c598aa75..79c80b53 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/EnterPolicyResponse.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/EnterPolicyResponse.cs @@ -1,10 +1,10 @@ -using OpenImis.Modules.InsureeModule.Helpers.Messages; +using OpenImis.ModulesV1.InsureeModule.Helpers.Messages; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers +namespace OpenImis.ModulesV1.InsureeModule.Helpers { public class EnterPolicyResponse : ImisApiResponse { diff --git a/OpenImis.Modules/InsureeModule/Helpers/GetCommissionResponse.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/GetCommissionResponse.cs similarity index 92% rename from OpenImis.Modules/InsureeModule/Helpers/GetCommissionResponse.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/GetCommissionResponse.cs index 2e1a397d..b0624554 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/GetCommissionResponse.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/GetCommissionResponse.cs @@ -1,10 +1,10 @@ -using OpenImis.Modules.InsureeModule.Helpers.Messages; +using OpenImis.ModulesV1.InsureeModule.Helpers.Messages; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers +namespace OpenImis.ModulesV1.InsureeModule.Helpers { public class GetCommissionResponse : ImisApiResponse { diff --git a/OpenImis.Modules/InsureeModule/Helpers/GetFamilyResponse.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/GetFamilyResponse.cs similarity index 91% rename from OpenImis.Modules/InsureeModule/Helpers/GetFamilyResponse.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/GetFamilyResponse.cs index 35fdfed7..4425678b 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/GetFamilyResponse.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/GetFamilyResponse.cs @@ -1,12 +1,12 @@ using Newtonsoft.Json; -using OpenImis.Modules.InsureeModule.Helpers.Messages; -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Helpers.Messages; +using OpenImis.ModulesV1.InsureeModule.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers +namespace OpenImis.ModulesV1.InsureeModule.Helpers { public class GetFamilyResponse : ImisApiResponse { diff --git a/OpenImis.Modules/InsureeModule/Helpers/GetMemberFamilyResponse.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/GetMemberFamilyResponse.cs similarity index 92% rename from OpenImis.Modules/InsureeModule/Helpers/GetMemberFamilyResponse.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/GetMemberFamilyResponse.cs index 3e581d0a..ae2cefd4 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/GetMemberFamilyResponse.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/GetMemberFamilyResponse.cs @@ -1,12 +1,12 @@ using Newtonsoft.Json; -using OpenImis.Modules.InsureeModule.Helpers.Messages; -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Helpers.Messages; +using OpenImis.ModulesV1.InsureeModule.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers +namespace OpenImis.ModulesV1.InsureeModule.Helpers { public class GetMemberFamilyResponse : ImisApiResponse { diff --git a/OpenImis.Modules/InsureeModule/Helpers/ImisApiResponse.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/ImisApiResponse.cs similarity index 91% rename from OpenImis.Modules/InsureeModule/Helpers/ImisApiResponse.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/ImisApiResponse.cs index ac063faa..b0d3ca90 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/ImisApiResponse.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/ImisApiResponse.cs @@ -1,10 +1,10 @@ using Newtonsoft.Json; -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers +namespace OpenImis.ModulesV1.InsureeModule.Helpers { public class ImisApiResponse { diff --git a/OpenImis.Modules/PaymentModule/Helpers/Messages/Language.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/Messages/Language.cs similarity index 92% rename from OpenImis.Modules/PaymentModule/Helpers/Messages/Language.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/Messages/Language.cs index 94e28837..b250fd55 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/Messages/Language.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/Messages/Language.cs @@ -3,7 +3,7 @@ using System.Reflection; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers.Messages +namespace OpenImis.ModulesV1.InsureeModule.Helpers.Messages { public class Language { diff --git a/OpenImis.Modules/CoverageModule/Helpers/Messages/PrimaryLanguage.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/Messages/PrimaryLanguage.cs similarity index 99% rename from OpenImis.Modules/CoverageModule/Helpers/Messages/PrimaryLanguage.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/Messages/PrimaryLanguage.cs index 77d4a1b3..127deb64 100644 --- a/OpenImis.Modules/CoverageModule/Helpers/Messages/PrimaryLanguage.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/Messages/PrimaryLanguage.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.CoverageModule.Helpers.Messages +namespace OpenImis.ModulesV1.InsureeModule.Helpers.Messages { public static class PrimaryLanguage { diff --git a/OpenImis.Modules/CoverageModule/Helpers/Messages/SecondaryLanguage.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/Messages/SecondaryLanguage.cs similarity index 98% rename from OpenImis.Modules/CoverageModule/Helpers/Messages/SecondaryLanguage.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/Messages/SecondaryLanguage.cs index 2f09c804..145e93f0 100644 --- a/OpenImis.Modules/CoverageModule/Helpers/Messages/SecondaryLanguage.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/Messages/SecondaryLanguage.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.CoverageModule.Helpers.Messages +namespace OpenImis.ModulesV1.InsureeModule.Helpers.Messages { public static class SecondaryLanguage { diff --git a/OpenImis.Modules/InsureeModule/Helpers/RenewPolicyResponse.cs b/OpenImis.ModulesV1/InsureeModule/Helpers/RenewPolicyResponse.cs similarity index 94% rename from OpenImis.Modules/InsureeModule/Helpers/RenewPolicyResponse.cs rename to OpenImis.ModulesV1/InsureeModule/Helpers/RenewPolicyResponse.cs index 27ec3fb8..89821c3a 100644 --- a/OpenImis.Modules/InsureeModule/Helpers/RenewPolicyResponse.cs +++ b/OpenImis.ModulesV1/InsureeModule/Helpers/RenewPolicyResponse.cs @@ -1,10 +1,10 @@ -using OpenImis.Modules.InsureeModule.Helpers.Messages; +using OpenImis.ModulesV1.InsureeModule.Helpers.Messages; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.InsureeModule.Helpers +namespace OpenImis.ModulesV1.InsureeModule.Helpers { public class RenewPolicyResponse : ImisApiResponse { diff --git a/OpenImis.ModulesV1/InsureeModule/IInsureeModule.cs b/OpenImis.ModulesV1/InsureeModule/IInsureeModule.cs new file mode 100644 index 00000000..1449c527 --- /dev/null +++ b/OpenImis.ModulesV1/InsureeModule/IInsureeModule.cs @@ -0,0 +1,17 @@ +using OpenImis.ModulesV1.InsureeModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV1.InsureeModule +{ + public interface IInsureeModule + { + IFamilyLogic GetFamilyLogic(); + IContributionLogic GetContributionLogic(); + IPolicyLogic GetPolicyLogic(); + IInsureeModule SetFamilyLogic(IFamilyLogic familyLogic); + IInsureeModule SetPolicyLogic(IPolicyLogic policyLogic); + IInsureeModule SetContributionLogic(IContributionLogic contributionLogic); + } +} diff --git a/OpenImis.Modules/InsureeModule/InsureeModule.cs b/OpenImis.ModulesV1/InsureeModule/InsureeModule.cs similarity index 50% rename from OpenImis.Modules/InsureeModule/InsureeModule.cs rename to OpenImis.ModulesV1/InsureeModule/InsureeModule.cs index ed09b9c6..009b96ad 100644 --- a/OpenImis.Modules/InsureeModule/InsureeModule.cs +++ b/OpenImis.ModulesV1/InsureeModule/InsureeModule.cs @@ -1,28 +1,29 @@ using Microsoft.Extensions.Configuration; -using OpenImis.Modules.InsureeModule.Logic; +using OpenImis.ModulesV1.InsureeModule.Logic; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule +namespace OpenImis.ModulesV1.InsureeModule { public class InsureeModule : IInsureeModule { - private IConfiguration Configuration; + private IConfiguration _configuration; + private IFamilyLogic _familyLogic; private IContributionLogic _contributionLogic; private IPolicyLogic _policyLogic; public InsureeModule(IConfiguration configuration) { - Configuration = configuration; + _configuration = configuration; } public IFamilyLogic GetFamilyLogic() { if (_familyLogic == null) { - _familyLogic = new FamilyLogic(Configuration); + _familyLogic = new FamilyLogic(_configuration); } return _familyLogic; } @@ -31,7 +32,7 @@ public IContributionLogic GetContributionLogic() { if (_contributionLogic == null) { - _contributionLogic = new ContributionLogic(Configuration); + _contributionLogic = new ContributionLogic(_configuration); } return _contributionLogic; } @@ -40,9 +41,27 @@ public IPolicyLogic GetPolicyLogic() { if (_policyLogic == null) { - _policyLogic = new PolicyLogic(Configuration); + _policyLogic = new PolicyLogic(_configuration); } return _policyLogic; } + + public IInsureeModule SetFamilyLogic(IFamilyLogic familyLogic) + { + _familyLogic = familyLogic; + return this; + } + + public IInsureeModule SetPolicyLogic(IPolicyLogic policyLogic) + { + _policyLogic = policyLogic; + return this; + } + + public IInsureeModule SetContributionLogic(IContributionLogic contributionLogic) + { + _contributionLogic = contributionLogic; + return this; + } } } diff --git a/OpenImis.Modules/InsureeModule/Logic/ContributionLogic.cs b/OpenImis.ModulesV1/InsureeModule/Logic/ContributionLogic.cs similarity index 84% rename from OpenImis.Modules/InsureeModule/Logic/ContributionLogic.cs rename to OpenImis.ModulesV1/InsureeModule/Logic/ContributionLogic.cs index 0a029c55..1012c854 100644 --- a/OpenImis.Modules/InsureeModule/Logic/ContributionLogic.cs +++ b/OpenImis.ModulesV1/InsureeModule/Logic/ContributionLogic.cs @@ -1,11 +1,11 @@ using Microsoft.Extensions.Configuration; -using OpenImis.Modules.InsureeModule.Models; -using OpenImis.Modules.InsureeModule.Repositories; +using OpenImis.ModulesV1.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Repositories; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Logic +namespace OpenImis.ModulesV1.InsureeModule.Logic { public class ContributionLogic : IContributionLogic { diff --git a/OpenImis.Modules/InsureeModule/Logic/FamilyLogic.cs b/OpenImis.ModulesV1/InsureeModule/Logic/FamilyLogic.cs similarity index 93% rename from OpenImis.Modules/InsureeModule/Logic/FamilyLogic.cs rename to OpenImis.ModulesV1/InsureeModule/Logic/FamilyLogic.cs index 62297819..999ac318 100644 --- a/OpenImis.Modules/InsureeModule/Logic/FamilyLogic.cs +++ b/OpenImis.ModulesV1/InsureeModule/Logic/FamilyLogic.cs @@ -1,12 +1,12 @@ using Microsoft.Extensions.Configuration; -using OpenImis.Modules.InsureeModule.Models; -using OpenImis.Modules.InsureeModule.Repositories; +using OpenImis.ModulesV1.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Repositories; using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; -namespace OpenImis.Modules.InsureeModule.Logic +namespace OpenImis.ModulesV1.InsureeModule.Logic { public class FamilyLogic : IFamilyLogic { diff --git a/OpenImis.Modules/InsureeModule/Logic/IContributionLogic.cs b/OpenImis.ModulesV1/InsureeModule/Logic/IContributionLogic.cs similarity index 67% rename from OpenImis.Modules/InsureeModule/Logic/IContributionLogic.cs rename to OpenImis.ModulesV1/InsureeModule/Logic/IContributionLogic.cs index 15c60549..92d87e9c 100644 --- a/OpenImis.Modules/InsureeModule/Logic/IContributionLogic.cs +++ b/OpenImis.ModulesV1/InsureeModule/Logic/IContributionLogic.cs @@ -1,9 +1,9 @@ -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Logic +namespace OpenImis.ModulesV1.InsureeModule.Logic { public interface IContributionLogic { diff --git a/OpenImis.Modules/InsureeModule/Logic/IFamilyLogic.cs b/OpenImis.ModulesV1/InsureeModule/Logic/IFamilyLogic.cs similarity index 84% rename from OpenImis.Modules/InsureeModule/Logic/IFamilyLogic.cs rename to OpenImis.ModulesV1/InsureeModule/Logic/IFamilyLogic.cs index e93cb81b..fd4f87dd 100644 --- a/OpenImis.Modules/InsureeModule/Logic/IFamilyLogic.cs +++ b/OpenImis.ModulesV1/InsureeModule/Logic/IFamilyLogic.cs @@ -1,9 +1,9 @@ -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Logic +namespace OpenImis.ModulesV1.InsureeModule.Logic { public interface IFamilyLogic { diff --git a/OpenImis.Modules/InsureeModule/Logic/IPolicyLogic.cs b/OpenImis.ModulesV1/InsureeModule/Logic/IPolicyLogic.cs similarity index 75% rename from OpenImis.Modules/InsureeModule/Logic/IPolicyLogic.cs rename to OpenImis.ModulesV1/InsureeModule/Logic/IPolicyLogic.cs index 183ec25a..29101c9e 100644 --- a/OpenImis.Modules/InsureeModule/Logic/IPolicyLogic.cs +++ b/OpenImis.ModulesV1/InsureeModule/Logic/IPolicyLogic.cs @@ -1,9 +1,9 @@ -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Logic +namespace OpenImis.ModulesV1.InsureeModule.Logic { public interface IPolicyLogic { diff --git a/OpenImis.Modules/InsureeModule/Logic/PolicyLogic.cs b/OpenImis.ModulesV1/InsureeModule/Logic/PolicyLogic.cs similarity index 88% rename from OpenImis.Modules/InsureeModule/Logic/PolicyLogic.cs rename to OpenImis.ModulesV1/InsureeModule/Logic/PolicyLogic.cs index 7bfe6421..387e21e4 100644 --- a/OpenImis.Modules/InsureeModule/Logic/PolicyLogic.cs +++ b/OpenImis.ModulesV1/InsureeModule/Logic/PolicyLogic.cs @@ -1,11 +1,11 @@ using Microsoft.Extensions.Configuration; -using OpenImis.Modules.InsureeModule.Models; -using OpenImis.Modules.InsureeModule.Repositories; +using OpenImis.ModulesV1.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Repositories; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Logic +namespace OpenImis.ModulesV1.InsureeModule.Logic { public class PolicyLogic : IPolicyLogic { diff --git a/OpenImis.Modules/InsureeModule/Models/CommissionMode.cs b/OpenImis.ModulesV1/InsureeModule/Models/CommissionMode.cs similarity index 75% rename from OpenImis.Modules/InsureeModule/Models/CommissionMode.cs rename to OpenImis.ModulesV1/InsureeModule/Models/CommissionMode.cs index a7d90dfa..a8dd18b8 100644 --- a/OpenImis.Modules/InsureeModule/Models/CommissionMode.cs +++ b/OpenImis.ModulesV1/InsureeModule/Models/CommissionMode.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Models +namespace OpenImis.ModulesV1.InsureeModule.Models { public enum CommissionMode { diff --git a/OpenImis.Modules/InsureeModule/Models/Contribution.cs b/OpenImis.ModulesV1/InsureeModule/Models/Contribution.cs similarity index 79% rename from OpenImis.Modules/InsureeModule/Models/Contribution.cs rename to OpenImis.ModulesV1/InsureeModule/Models/Contribution.cs index 7db26377..fa75f839 100644 --- a/OpenImis.Modules/InsureeModule/Models/Contribution.cs +++ b/OpenImis.ModulesV1/InsureeModule/Models/Contribution.cs @@ -1,18 +1,19 @@ -using OpenImis.Modules.Helpers.Validators; -using System; +using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Text; -namespace OpenImis.Modules.InsureeModule.Models +namespace OpenImis.ModulesV1.InsureeModule.Models { public class Contribution { [Required] - [InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number ")] + //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number ")] public string InsuranceNumber { get; set; } [Required(ErrorMessage = "7-Wrong or missing payer")] public string Payer { get; set; } [Required(ErrorMessage = "4:Wrong or missing payment date")] - [ValidDate(ErrorMessage = "4:Wrong or missing payment date")] + //[ValidDate(ErrorMessage = "4:Wrong or missing payment date")] public string PaymentDate { get; set; } [Required(ErrorMessage = "3:Wrong or missing product ")] public string ProductCode { get; set; } diff --git a/OpenImis.Modules/CoverageModule/Models/DataMessage.cs b/OpenImis.ModulesV1/InsureeModule/Models/DataMessage.cs similarity index 85% rename from OpenImis.Modules/CoverageModule/Models/DataMessage.cs rename to OpenImis.ModulesV1/InsureeModule/Models/DataMessage.cs index b9541f04..d35647b3 100644 --- a/OpenImis.Modules/CoverageModule/Models/DataMessage.cs +++ b/OpenImis.ModulesV1/InsureeModule/Models/DataMessage.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.CoverageModule.Models +namespace OpenImis.ModulesV1.InsureeModule.Models { public class DataMessage { diff --git a/OpenImis.Modules/InsureeModule/Models/EditFamilyMember.cs b/OpenImis.ModulesV1/InsureeModule/Models/EditFamilyMember.cs similarity index 80% rename from OpenImis.Modules/InsureeModule/Models/EditFamilyMember.cs rename to OpenImis.ModulesV1/InsureeModule/Models/EditFamilyMember.cs index 1cd99f25..880d191b 100644 --- a/OpenImis.Modules/InsureeModule/Models/EditFamilyMember.cs +++ b/OpenImis.ModulesV1/InsureeModule/Models/EditFamilyMember.cs @@ -1,22 +1,22 @@ -using OpenImis.Modules.Helpers.Validators; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.InsureeModule.Models +namespace OpenImis.ModulesV1.InsureeModule.Models { public class EditFamilyMember { [Required] - [InsureeNumber(ErrorMessage = "3:Wrong format or missing insurance number of member")] + //[InsureeNumber(ErrorMessage = "3:Wrong format or missing insurance number of member")] public string InsureeNumber { get; set; } public string OtherName { get; set; } public string LastName { get; set; } - [ValidDate(ErrorMessage = "5:Wrong format or missing birth date")] + //[ValidDate(ErrorMessage = "5:Wrong format or missing birth date")] public string BirthDate { get; set; } [StringLength(1, ErrorMessage = "6:Wrong gender")] public string Gender { get; set; } + public string Relationship { get; set; } [StringLength(1, ErrorMessage = "7:Wrong marital status")] public string MaritalStatus { get; set; } diff --git a/OpenImis.Modules/InsureeModule/Models/EditFamilyModel.cs b/OpenImis.ModulesV1/InsureeModule/Models/EditFamilyModel.cs similarity index 83% rename from OpenImis.Modules/InsureeModule/Models/EditFamilyModel.cs rename to OpenImis.ModulesV1/InsureeModule/Models/EditFamilyModel.cs index 8eaa4203..91654357 100644 --- a/OpenImis.Modules/InsureeModule/Models/EditFamilyModel.cs +++ b/OpenImis.ModulesV1/InsureeModule/Models/EditFamilyModel.cs @@ -1,20 +1,19 @@ -using OpenImis.Modules.Helpers.Validators; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.InsureeModule.Models +namespace OpenImis.ModulesV1.InsureeModule.Models { public class EditFamily { public string VillageCode { get; set; } [Required(ErrorMessage = "1:Wrong format or missing insurance number of head")] - [InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] + //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] public string HeadOfFamilyId { get; set; } public string OtherName { get; set; } public string LastName { get; set; } - [ValidDate(ErrorMessage = "6:Wrong format or missing birth date")] + //[ValidDate(ErrorMessage = "6:Wrong format or missing birth date")] public string BirthDate { get; set; } public string Gender { get; set; } public bool PovertyStatus { get; set; } diff --git a/OpenImis.Modules/InsureeModule/Models/Family.cs b/OpenImis.ModulesV1/InsureeModule/Models/Family.cs similarity index 66% rename from OpenImis.Modules/InsureeModule/Models/Family.cs rename to OpenImis.ModulesV1/InsureeModule/Models/Family.cs index a48174d9..99d26104 100644 --- a/OpenImis.Modules/InsureeModule/Models/Family.cs +++ b/OpenImis.ModulesV1/InsureeModule/Models/Family.cs @@ -1,33 +1,20 @@ -using OpenImis.Modules.Helpers.Validators; -using System; +using System; using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.InsureeModule.Models +namespace OpenImis.ModulesV1.InsureeModule.Models { public abstract class Family { public string InsuranceNumber { get; set; } public string OtherNames { get; set; } - - [Required(ErrorMessage = "7:Missing last name", AllowEmptyStrings = false)] public string LastName { get; set; } - - [Required(ErrorMessage = "6:Wrong format or missing birth date")] - [ValidDate] public DateTime BirthDate { get; set; } - - [Required(ErrorMessage = "5:Wrong or missing gender"), StringLength(1, ErrorMessage = "5:Wrong or missing gender")] public string Gender { get; set; } - public bool? PoveryStatus { get; set; } public string ConfirmationType { get; set; } public string PermanentAddress { get; set; } - - [StringLength(1, ErrorMessage = "11:Wrong marital status")] public string MaritalStatus { get; set; } - public bool BeneficiaryCard { get; set; } public string CurrentVillageCode { get; set; } public string CurrentAddress { get; set; } diff --git a/OpenImis.Modules/InsureeModule/Models/FamilyMember.cs b/OpenImis.ModulesV1/InsureeModule/Models/FamilyMember.cs similarity index 82% rename from OpenImis.Modules/InsureeModule/Models/FamilyMember.cs rename to OpenImis.ModulesV1/InsureeModule/Models/FamilyMember.cs index e40eb71b..46f19c9c 100644 --- a/OpenImis.Modules/InsureeModule/Models/FamilyMember.cs +++ b/OpenImis.ModulesV1/InsureeModule/Models/FamilyMember.cs @@ -1,28 +1,28 @@ -using OpenImis.Modules.Helpers.Validators; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.InsureeModule.Models +namespace OpenImis.ModulesV1.InsureeModule.Models { public class FamilyMember { [Required] - [InsureeNumber(ErrorMessage = "3:Wrong format or missing insurance number of member")] + //[InsureeNumber(ErrorMessage = "3:Wrong format or missing insurance number of member")] public string InsureeNumber { get; set; } [Required] - [InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] + //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] public string HeadInsureeNumber { get; set; } [Required(ErrorMessage = "7:Missing other name", AllowEmptyStrings = false)] public string OtherName { get; set; } [Required(ErrorMessage = "6:Missing last name", AllowEmptyStrings = false)] public string LastName { get; set; } [Required(ErrorMessage = "5:Wrong format or missing birth date")] - [ValidDate] + //[ValidDate] public string BirthDate { get; set; } [StringLength(1, ErrorMessage = "4:Wrong or missing gender")] public string Gender { get; set; } + public string Relationship { get; set; } [StringLength(1, ErrorMessage = "10:Wrong marital status")] public string MaritalStatus { get; set; } diff --git a/OpenImis.Modules/InsureeModule/Models/FamilyModel.cs b/OpenImis.ModulesV1/InsureeModule/Models/FamilyModel.cs similarity index 77% rename from OpenImis.Modules/InsureeModule/Models/FamilyModel.cs rename to OpenImis.ModulesV1/InsureeModule/Models/FamilyModel.cs index d7a1b018..8b22252e 100644 --- a/OpenImis.Modules/InsureeModule/Models/FamilyModel.cs +++ b/OpenImis.ModulesV1/InsureeModule/Models/FamilyModel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Models +namespace OpenImis.ModulesV1.InsureeModule.Models { public class FamilyModel : Family { diff --git a/OpenImis.Modules/InsureeModule/Models/FamilyModelv2.cs b/OpenImis.ModulesV1/InsureeModule/Models/FamilyModelv2.cs similarity index 78% rename from OpenImis.Modules/InsureeModule/Models/FamilyModelv2.cs rename to OpenImis.ModulesV1/InsureeModule/Models/FamilyModelv2.cs index cdae2feb..1b9d1581 100644 --- a/OpenImis.Modules/InsureeModule/Models/FamilyModelv2.cs +++ b/OpenImis.ModulesV1/InsureeModule/Models/FamilyModelv2.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Models +namespace OpenImis.ModulesV1.InsureeModule.Models { public class FamilyModelv2 : Family { diff --git a/OpenImis.Modules/InsureeModule/Models/FamilyModelv3.cs b/OpenImis.ModulesV1/InsureeModule/Models/FamilyModelv3.cs similarity index 58% rename from OpenImis.Modules/InsureeModule/Models/FamilyModelv3.cs rename to OpenImis.ModulesV1/InsureeModule/Models/FamilyModelv3.cs index b8934f9c..060666bc 100644 --- a/OpenImis.Modules/InsureeModule/Models/FamilyModelv3.cs +++ b/OpenImis.ModulesV1/InsureeModule/Models/FamilyModelv3.cs @@ -1,10 +1,9 @@ -using OpenImis.Modules.Helpers.Validators; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.InsureeModule.Models +namespace OpenImis.ModulesV1.InsureeModule.Models { public class FamilyModelv3 : Family { @@ -18,12 +17,23 @@ public class FamilyModelv3 : Family /// An insuree number belonging to the head of a family /// [Required(ErrorMessage = "1:Wrong format or missing insurance number of head")] - [InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] + //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number of head")] public string HeadOfFamilyId { get; set; } [Required(ErrorMessage = "8:Missing other name", AllowEmptyStrings = false)] public string OtherName { get; set; } + //[Required(ErrorMessage = "7:Missing last name", AllowEmptyStrings = false)] + //public string LastName { get; set; } + + //[Required(ErrorMessage = "6:Wrong format or missing birth date")] + //[ValidDate] + //public string BirthDate { get; set; } + + //[Required(ErrorMessage = "5:Wrong or missing gender"), StringLength(1, ErrorMessage = "5:Wrong or missing gender")] + //[BindRequired] + //public string Gender { get; set; } + public bool PovertyStatus { get; set; } public string GroupType { get; set; } @@ -32,6 +42,9 @@ public class FamilyModelv3 : Family public string PermanentAddressDetails { get; set; } + //[StringLength(1, ErrorMessage = "11:Wrong marital status")] + //public string MaritalStatus { get; set; } + public string CurrentAddressDetails { get; set; } public string FspCode { get; set; } diff --git a/OpenImis.Modules/InsureeModule/Models/GetCommissionInputs.cs b/OpenImis.ModulesV1/InsureeModule/Models/GetCommissionInputs.cs similarity index 91% rename from OpenImis.Modules/InsureeModule/Models/GetCommissionInputs.cs rename to OpenImis.ModulesV1/InsureeModule/Models/GetCommissionInputs.cs index 95f49ae6..cb9b4fe3 100644 --- a/OpenImis.Modules/InsureeModule/Models/GetCommissionInputs.cs +++ b/OpenImis.ModulesV1/InsureeModule/Models/GetCommissionInputs.cs @@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.InsureeModule.Models +namespace OpenImis.ModulesV1.InsureeModule.Models { public class GetCommissionInputs { diff --git a/OpenImis.Modules/InsureeModule/Models/Policy.cs b/OpenImis.ModulesV1/InsureeModule/Models/Policy.cs similarity index 63% rename from OpenImis.Modules/InsureeModule/Models/Policy.cs rename to OpenImis.ModulesV1/InsureeModule/Models/Policy.cs index 83d1392f..7525b4be 100644 --- a/OpenImis.Modules/InsureeModule/Models/Policy.cs +++ b/OpenImis.ModulesV1/InsureeModule/Models/Policy.cs @@ -1,21 +1,18 @@ -using OpenImis.Modules.Helpers.Validators; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.InsureeModule.Models +namespace OpenImis.ModulesV1.InsureeModule.Models { public class Policy { [Required] - [InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number")] + //[InsureeNumber(ErrorMessage = "1:Wrong format or missing insurance number")] public string InsuranceNumber { get; set; } - [Required(ErrorMessage = "4:Wrong or missing enrolment date")] - [ValidDate(ErrorMessage = "4:Wrong or missing enrolment date")] + //[ValidDate(ErrorMessage = "4:Wrong or missing enrolment date")] public string Date { get; set; } - [Required] public string ProductCode { get; set; } [Required] diff --git a/OpenImis.Modules/InsureeModule/Models/ReactionType.cs b/OpenImis.ModulesV1/InsureeModule/Models/ReactionType.cs similarity index 75% rename from OpenImis.Modules/InsureeModule/Models/ReactionType.cs rename to OpenImis.ModulesV1/InsureeModule/Models/ReactionType.cs index 628cfdf7..098a7c3b 100644 --- a/OpenImis.Modules/InsureeModule/Models/ReactionType.cs +++ b/OpenImis.ModulesV1/InsureeModule/Models/ReactionType.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Models +namespace OpenImis.ModulesV1.InsureeModule.Models { public enum ReactionType { diff --git a/OpenImis.Modules/InsureeModule/Repositories/ContributionRepository.cs b/OpenImis.ModulesV1/InsureeModule/Repositories/ContributionRepository.cs similarity index 92% rename from OpenImis.Modules/InsureeModule/Repositories/ContributionRepository.cs rename to OpenImis.ModulesV1/InsureeModule/Repositories/ContributionRepository.cs index 4115a42e..6d53d2b5 100644 --- a/OpenImis.Modules/InsureeModule/Repositories/ContributionRepository.cs +++ b/OpenImis.ModulesV1/InsureeModule/Repositories/ContributionRepository.cs @@ -1,11 +1,11 @@ using Microsoft.Extensions.Configuration; using OpenImis.DB.SqlServer.DataHelper; -using OpenImis.Modules.InsureeModule.Helpers; -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Helpers; +using OpenImis.ModulesV1.InsureeModule.Models; using System; using System.Data.SqlClient; -namespace OpenImis.Modules.InsureeModule.Repositories +namespace OpenImis.ModulesV1.InsureeModule.Repositories { public class ContributionRepository : IContributionRepository { diff --git a/OpenImis.Modules/InsureeModule/Repositories/FamilyRepository.cs b/OpenImis.ModulesV1/InsureeModule/Repositories/FamilyRepository.cs similarity index 99% rename from OpenImis.Modules/InsureeModule/Repositories/FamilyRepository.cs rename to OpenImis.ModulesV1/InsureeModule/Repositories/FamilyRepository.cs index 0b325414..54ca7af1 100644 --- a/OpenImis.Modules/InsureeModule/Repositories/FamilyRepository.cs +++ b/OpenImis.ModulesV1/InsureeModule/Repositories/FamilyRepository.cs @@ -1,14 +1,14 @@ using Microsoft.Extensions.Configuration; using OpenImis.DB.SqlServer; using OpenImis.DB.SqlServer.DataHelper; -using OpenImis.Modules.InsureeModule.Helpers; -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Helpers; +using OpenImis.ModulesV1.InsureeModule.Models; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; -namespace OpenImis.Modules.InsureeModule.Repositories +namespace OpenImis.ModulesV1.InsureeModule.Repositories { public class FamilyRepository : IFamilyRepository { diff --git a/OpenImis.Modules/InsureeModule/Repositories/IContributionRepository.cs b/OpenImis.ModulesV1/InsureeModule/Repositories/IContributionRepository.cs similarity index 66% rename from OpenImis.Modules/InsureeModule/Repositories/IContributionRepository.cs rename to OpenImis.ModulesV1/InsureeModule/Repositories/IContributionRepository.cs index bd4527a7..b7cfc7af 100644 --- a/OpenImis.Modules/InsureeModule/Repositories/IContributionRepository.cs +++ b/OpenImis.ModulesV1/InsureeModule/Repositories/IContributionRepository.cs @@ -1,9 +1,9 @@ -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Repositories +namespace OpenImis.ModulesV1.InsureeModule.Repositories { public interface IContributionRepository { diff --git a/OpenImis.Modules/InsureeModule/Repositories/IFamilyRepository.cs b/OpenImis.ModulesV1/InsureeModule/Repositories/IFamilyRepository.cs similarity index 83% rename from OpenImis.Modules/InsureeModule/Repositories/IFamilyRepository.cs rename to OpenImis.ModulesV1/InsureeModule/Repositories/IFamilyRepository.cs index 51a3df53..1d32ccc6 100644 --- a/OpenImis.Modules/InsureeModule/Repositories/IFamilyRepository.cs +++ b/OpenImis.ModulesV1/InsureeModule/Repositories/IFamilyRepository.cs @@ -1,9 +1,9 @@ -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Repositories +namespace OpenImis.ModulesV1.InsureeModule.Repositories { public interface IFamilyRepository { diff --git a/OpenImis.Modules/InsureeModule/Repositories/IPolicyRepository.cs b/OpenImis.ModulesV1/InsureeModule/Repositories/IPolicyRepository.cs similarity index 73% rename from OpenImis.Modules/InsureeModule/Repositories/IPolicyRepository.cs rename to OpenImis.ModulesV1/InsureeModule/Repositories/IPolicyRepository.cs index 13f8a1b1..993ce0ef 100644 --- a/OpenImis.Modules/InsureeModule/Repositories/IPolicyRepository.cs +++ b/OpenImis.ModulesV1/InsureeModule/Repositories/IPolicyRepository.cs @@ -1,9 +1,9 @@ -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Repositories +namespace OpenImis.ModulesV1.InsureeModule.Repositories { public interface IPolicyRepository { diff --git a/OpenImis.Modules/InsureeModule/Repositories/PolicyRepository.cs b/OpenImis.ModulesV1/InsureeModule/Repositories/PolicyRepository.cs similarity index 96% rename from OpenImis.Modules/InsureeModule/Repositories/PolicyRepository.cs rename to OpenImis.ModulesV1/InsureeModule/Repositories/PolicyRepository.cs index 40c7ce95..9c6653c7 100644 --- a/OpenImis.Modules/InsureeModule/Repositories/PolicyRepository.cs +++ b/OpenImis.ModulesV1/InsureeModule/Repositories/PolicyRepository.cs @@ -1,14 +1,14 @@ using Microsoft.Extensions.Configuration; using OpenImis.DB.SqlServer; using OpenImis.DB.SqlServer.DataHelper; -using OpenImis.Modules.InsureeModule.Helpers; -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1.InsureeModule.Helpers; +using OpenImis.ModulesV1.InsureeModule.Models; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; -namespace OpenImis.Modules.InsureeModule.Repositories +namespace OpenImis.ModulesV1.InsureeModule.Repositories { public class PolicyRepository : IPolicyRepository { diff --git a/OpenImis.ModulesV1/LoginModule/ILoginModule.cs b/OpenImis.ModulesV1/LoginModule/ILoginModule.cs new file mode 100644 index 00000000..f133d0f3 --- /dev/null +++ b/OpenImis.ModulesV1/LoginModule/ILoginModule.cs @@ -0,0 +1,11 @@ +using OpenImis.ModulesV1.LoginModule.Logic; + + +namespace OpenImis.ModulesV1.LoginModule +{ + public interface ILoginModule + { + ILoginLogic GetLoginLogic(); + ILoginModule SetLoginLogic(ILoginLogic loginLogic); + } +} diff --git a/OpenImis.Modules/LoginModule/Logic/ILoginLogic.cs b/OpenImis.ModulesV1/LoginModule/Logic/ILoginLogic.cs similarity index 69% rename from OpenImis.Modules/LoginModule/Logic/ILoginLogic.cs rename to OpenImis.ModulesV1/LoginModule/Logic/ILoginLogic.cs index e7830ff9..fb4c1414 100644 --- a/OpenImis.Modules/LoginModule/Logic/ILoginLogic.cs +++ b/OpenImis.ModulesV1/LoginModule/Logic/ILoginLogic.cs @@ -1,9 +1,9 @@ -using OpenImis.Modules.LoginModule.Models; +using OpenImis.ModulesV1.LoginModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.LoginModule.Logic +namespace OpenImis.ModulesV1.LoginModule.Logic { public interface ILoginLogic { diff --git a/OpenImis.Modules/LoginModule/Logic/LoginLogic.cs b/OpenImis.ModulesV1/LoginModule/Logic/LoginLogic.cs similarity index 87% rename from OpenImis.Modules/LoginModule/Logic/LoginLogic.cs rename to OpenImis.ModulesV1/LoginModule/Logic/LoginLogic.cs index 114e73e7..28bce198 100644 --- a/OpenImis.Modules/LoginModule/Logic/LoginLogic.cs +++ b/OpenImis.ModulesV1/LoginModule/Logic/LoginLogic.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.Configuration; -using OpenImis.Modules.LoginModule.Models; -using OpenImis.Modules.LoginModule.Repositories; +using OpenImis.ModulesV1.LoginModule.Models; +using OpenImis.ModulesV1.LoginModule.Repositories; using System; using System.Collections.Generic; using System.Data; @@ -10,17 +10,17 @@ using System.Security.Cryptography; using System.Text; -namespace OpenImis.Modules.LoginModule.Logic +namespace OpenImis.ModulesV1.LoginModule.Logic { public class LoginLogic : ILoginLogic { - private IConfiguration Configuration; + private IConfiguration _configuration; protected ILoginRepository loginRepository; public LoginLogic(IConfiguration configuration) { - Configuration = configuration; - loginRepository = new LoginRepository(Configuration); + _configuration = configuration; + loginRepository = new LoginRepository(_configuration); } public UserData GetById(int userId) @@ -82,4 +82,4 @@ private string GenerateSHA256String(string inputString) return stringBuilder.ToString(); } } -} +} \ No newline at end of file diff --git a/OpenImis.Modules/LoginModule/LoginModule.cs b/OpenImis.ModulesV1/LoginModule/LoginModule.cs similarity index 53% rename from OpenImis.Modules/LoginModule/LoginModule.cs rename to OpenImis.ModulesV1/LoginModule/LoginModule.cs index 3d767a8a..2f4c72de 100644 --- a/OpenImis.Modules/LoginModule/LoginModule.cs +++ b/OpenImis.ModulesV1/LoginModule/LoginModule.cs @@ -1,28 +1,34 @@ using Microsoft.Extensions.Configuration; -using OpenImis.Modules.LoginModule.Logic; +using OpenImis.ModulesV1.LoginModule.Logic; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.LoginModule +namespace OpenImis.ModulesV1.LoginModule { public class LoginModule : ILoginModule { - private IConfiguration Configuration; + private IConfiguration _configuration; private ILoginLogic _loginLogic; public LoginModule(IConfiguration configuration) { - Configuration = configuration; + _configuration = configuration; } public ILoginLogic GetLoginLogic() { if (_loginLogic == null) { - _loginLogic = new LoginLogic(Configuration); + _loginLogic = new LoginLogic(_configuration); } return _loginLogic; } + + public ILoginModule SetLoginLogic(ILoginLogic loginLogic) + { + _loginLogic = loginLogic; + return this; + } } } diff --git a/OpenImis.Modules/PaymentModule/Models/Language.cs b/OpenImis.ModulesV1/LoginModule/Models/Language.cs similarity index 75% rename from OpenImis.Modules/PaymentModule/Models/Language.cs rename to OpenImis.ModulesV1/LoginModule/Models/Language.cs index f2357886..cfa5732e 100644 --- a/OpenImis.Modules/PaymentModule/Models/Language.cs +++ b/OpenImis.ModulesV1/LoginModule/Models/Language.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.LoginModule.Models { public enum Language { diff --git a/OpenImis.Modules/LoginModule/Models/LoginModel.cs b/OpenImis.ModulesV1/LoginModule/Models/LoginModel.cs similarity index 81% rename from OpenImis.Modules/LoginModule/Models/LoginModel.cs rename to OpenImis.ModulesV1/LoginModule/Models/LoginModel.cs index 83208adb..e43d9d1b 100644 --- a/OpenImis.Modules/LoginModule/Models/LoginModel.cs +++ b/OpenImis.ModulesV1/LoginModule/Models/LoginModel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.LoginModule.Models +namespace OpenImis.ModulesV1.LoginModule.Models { public class LoginModel { diff --git a/OpenImis.Modules/LoginModule/Models/UserData.cs b/OpenImis.ModulesV1/LoginModule/Models/UserData.cs similarity index 87% rename from OpenImis.Modules/LoginModule/Models/UserData.cs rename to OpenImis.ModulesV1/LoginModule/Models/UserData.cs index 22cc14df..d43f3edb 100644 --- a/OpenImis.Modules/LoginModule/Models/UserData.cs +++ b/OpenImis.ModulesV1/LoginModule/Models/UserData.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.LoginModule.Models +namespace OpenImis.ModulesV1.LoginModule.Models { public class UserData { diff --git a/OpenImis.Modules/LoginModule/Models/UserLogin.cs b/OpenImis.ModulesV1/LoginModule/Models/UserLogin.cs similarity index 86% rename from OpenImis.Modules/LoginModule/Models/UserLogin.cs rename to OpenImis.ModulesV1/LoginModule/Models/UserLogin.cs index ac795f1f..706d824f 100644 --- a/OpenImis.Modules/LoginModule/Models/UserLogin.cs +++ b/OpenImis.ModulesV1/LoginModule/Models/UserLogin.cs @@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.LoginModule.Models +namespace OpenImis.ModulesV1.LoginModule.Models { public class UserLogin { diff --git a/OpenImis.Modules/LoginModule/Models/ValidateCredentialsResponse.cs b/OpenImis.ModulesV1/LoginModule/Models/ValidateCredentialsResponse.cs similarity index 82% rename from OpenImis.Modules/LoginModule/Models/ValidateCredentialsResponse.cs rename to OpenImis.ModulesV1/LoginModule/Models/ValidateCredentialsResponse.cs index ceb2733a..7244e378 100644 --- a/OpenImis.Modules/LoginModule/Models/ValidateCredentialsResponse.cs +++ b/OpenImis.ModulesV1/LoginModule/Models/ValidateCredentialsResponse.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.LoginModule.Models +namespace OpenImis.ModulesV1.LoginModule.Models { public class ValidateCredentialsResponse { diff --git a/OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs b/OpenImis.ModulesV1/LoginModule/Repositories/ILoginRepository.cs similarity index 69% rename from OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs rename to OpenImis.ModulesV1/LoginModule/Repositories/ILoginRepository.cs index b388a2a4..0de916e0 100644 --- a/OpenImis.Modules/LoginModule/Repositories/ILoginRepository.cs +++ b/OpenImis.ModulesV1/LoginModule/Repositories/ILoginRepository.cs @@ -1,10 +1,10 @@ -using OpenImis.Modules.LoginModule.Models; +using OpenImis.ModulesV1.LoginModule.Models; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.LoginModule.Repositories +namespace OpenImis.ModulesV1.LoginModule.Repositories { public interface ILoginRepository { diff --git a/OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs b/OpenImis.ModulesV1/LoginModule/Repositories/LoginRepository.cs similarity index 95% rename from OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs rename to OpenImis.ModulesV1/LoginModule/Repositories/LoginRepository.cs index 1f992fbb..458e029c 100644 --- a/OpenImis.Modules/LoginModule/Repositories/LoginRepository.cs +++ b/OpenImis.ModulesV1/LoginModule/Repositories/LoginRepository.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Configuration; using OpenImis.DB.SqlServer; using OpenImis.DB.SqlServer.DataHelper; -using OpenImis.Modules.LoginModule.Models; +using OpenImis.ModulesV1.LoginModule.Models; using System; using System.Collections.Generic; using System.Data; @@ -10,7 +10,7 @@ using System.Linq; using System.Text; -namespace OpenImis.Modules.LoginModule.Repositories +namespace OpenImis.ModulesV1.LoginModule.Repositories { public class LoginRepository : ILoginRepository { diff --git a/OpenImis.ModulesV1/OpenImis.ModulesV1.csproj b/OpenImis.ModulesV1/OpenImis.ModulesV1.csproj new file mode 100644 index 00000000..06613e64 --- /dev/null +++ b/OpenImis.ModulesV1/OpenImis.ModulesV1.csproj @@ -0,0 +1,27 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + + ..\..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.configuration.abstractions\2.1.1\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll + + + ..\..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.logging.abstractions\2.1.1\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll + + + ..\..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\newtonsoft.json\11.0.2\lib\netstandard2.0\Newtonsoft.Json.dll + + + + diff --git a/OpenImis.Modules/PaymentModule/Helpers/CtrlNumberResponse.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/CtrlNumberResponse.cs similarity index 92% rename from OpenImis.Modules/PaymentModule/Helpers/CtrlNumberResponse.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/CtrlNumberResponse.cs index 436b7838..0f907c1b 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/CtrlNumberResponse.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/CtrlNumberResponse.cs @@ -1,10 +1,10 @@ -using OpenImis.Modules.PaymentModule.Helpers.Messages; +using OpenImis.ModulesV1.PaymentModule.Helpers.Messages; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers +namespace OpenImis.ModulesV1.PaymentModule.Helpers { public class CtrlNumberResponse : ImisApiResponse { diff --git a/OpenImis.Modules/PaymentModule/Helpers/Extensions/StringExtensions.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/Extensions/StringExtensions.cs similarity index 95% rename from OpenImis.Modules/PaymentModule/Helpers/Extensions/StringExtensions.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/Extensions/StringExtensions.cs index af155ffb..add06905 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/Extensions/StringExtensions.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/Extensions/StringExtensions.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers.Extensions +namespace OpenImis.ModulesV1.PaymentModule.Helpers.Extensions { public static class StringExtensions { diff --git a/OpenImis.Modules/PaymentModule/Helpers/FamilyDefaults.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/FamilyDefaults.cs similarity index 85% rename from OpenImis.Modules/PaymentModule/Helpers/FamilyDefaults.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/FamilyDefaults.cs index 56d57577..dcdcef6b 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/FamilyDefaults.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/FamilyDefaults.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers +namespace OpenImis.ModulesV1.PaymentModule.Helpers { public class FamilyDefaults { diff --git a/OpenImis.Modules/PaymentModule/Helpers/ImisApiResponse.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/ImisApiResponse.cs similarity index 91% rename from OpenImis.Modules/PaymentModule/Helpers/ImisApiResponse.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/ImisApiResponse.cs index 8d05bd4f..d15b1476 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/ImisApiResponse.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/ImisApiResponse.cs @@ -1,11 +1,11 @@ using Newtonsoft.Json; -using OpenImis.Modules.PaymentModule.Models; +using OpenImis.ModulesV1.PaymentModule.Models; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers +namespace OpenImis.ModulesV1.PaymentModule.Helpers { public class ImisApiResponse { diff --git a/OpenImis.Modules/PaymentModule/Helpers/LocalDefault.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/LocalDefault.cs similarity index 97% rename from OpenImis.Modules/PaymentModule/Helpers/LocalDefault.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/LocalDefault.cs index eccba393..bc8b2ee3 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/LocalDefault.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/LocalDefault.cs @@ -1,10 +1,10 @@ using Microsoft.Extensions.Configuration; -using OpenImis.Modules.PaymentModule.Repositories; +using OpenImis.ModulesV1.PaymentModule.Repositories; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers +namespace OpenImis.ModulesV1.PaymentModule.Helpers { public static class LocalDefault { diff --git a/OpenImis.Modules/PaymentModule/Helpers/MatchPayResponse.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/MatchPayResponse.cs similarity index 89% rename from OpenImis.Modules/PaymentModule/Helpers/MatchPayResponse.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/MatchPayResponse.cs index 5ead6d03..08853990 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/MatchPayResponse.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/MatchPayResponse.cs @@ -1,12 +1,12 @@ using Newtonsoft.Json; -using OpenImis.Modules.PaymentModule.Helpers.Messages; -using OpenImis.Modules.PaymentModule.Models; +using OpenImis.ModulesV1.PaymentModule.Helpers.Messages; +using OpenImis.ModulesV1.PaymentModule.Models; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers +namespace OpenImis.ModulesV1.PaymentModule.Helpers { public class MatchPayResponse : ImisApiResponse { diff --git a/OpenImis.Modules/CoverageModule/Helpers/Messages/Language.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/Messages/Language.cs similarity index 92% rename from OpenImis.Modules/CoverageModule/Helpers/Messages/Language.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/Messages/Language.cs index 6f204815..cfe468d3 100644 --- a/OpenImis.Modules/CoverageModule/Helpers/Messages/Language.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/Messages/Language.cs @@ -3,7 +3,7 @@ using System.Reflection; using System.Text; -namespace OpenImis.Modules.CoverageModule.Helpers.Messages +namespace OpenImis.ModulesV1.PaymentModule.Helpers.Messages { public class Language { diff --git a/OpenImis.Modules/PaymentModule/Helpers/Messages/PrimaryLanguage.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/Messages/PrimaryLanguage.cs similarity index 99% rename from OpenImis.Modules/PaymentModule/Helpers/Messages/PrimaryLanguage.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/Messages/PrimaryLanguage.cs index 0d49879a..e6e8461c 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/Messages/PrimaryLanguage.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/Messages/PrimaryLanguage.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers.Messages +namespace OpenImis.ModulesV1.PaymentModule.Helpers.Messages { public static class PrimaryLanguage { diff --git a/OpenImis.Modules/PaymentModule/Helpers/Messages/SecondaryLanguage.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/Messages/SecondaryLanguage.cs similarity index 99% rename from OpenImis.Modules/PaymentModule/Helpers/Messages/SecondaryLanguage.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/Messages/SecondaryLanguage.cs index 143c54ab..32b36ee2 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/Messages/SecondaryLanguage.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/Messages/SecondaryLanguage.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers.Messages +namespace OpenImis.ModulesV1.PaymentModule.Helpers.Messages { public static class SecondaryLanguage { diff --git a/OpenImis.Modules/PaymentModule/Helpers/RequestedCNResponse.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/RequestedCNResponse.cs similarity index 89% rename from OpenImis.Modules/PaymentModule/Helpers/RequestedCNResponse.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/RequestedCNResponse.cs index 8fd6c34f..ce33dffa 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/RequestedCNResponse.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/RequestedCNResponse.cs @@ -1,14 +1,14 @@ using Newtonsoft.Json; -using OpenImis.Modules.PaymentModule.Helpers.Messages; -using OpenImis.Modules.PaymentModule.Models; -using OpenImis.Modules.PaymentModule.Models.Response; +using OpenImis.ModulesV1.PaymentModule.Helpers.Messages; +using OpenImis.ModulesV1.PaymentModule.Models; +using OpenImis.ModulesV1.PaymentModule.Models.Response; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers +namespace OpenImis.ModulesV1.PaymentModule.Helpers { public class RequestedCNResponse : ImisApiResponse { diff --git a/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisBaseSms.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/SMS/ImisBaseSms.cs similarity index 95% rename from OpenImis.Modules/PaymentModule/Helpers/SMS/ImisBaseSms.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/SMS/ImisBaseSms.cs index 9f115e88..8a6ce4b3 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisBaseSms.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/SMS/ImisBaseSms.cs @@ -1,8 +1,8 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; -using OpenImis.Modules.PaymentModule.Models; -using OpenImis.Modules.PaymentModule.Models.SMS; +using OpenImis.ModulesV1.PaymentModule.Models; +using OpenImis.ModulesV1.PaymentModule.Models.SMS; using System; using System.Collections.Generic; using System.IO; @@ -10,7 +10,7 @@ using System.Text; using System.Threading.Tasks; -namespace OpenImis.Modules.PaymentModule.Helpers.SMS +namespace OpenImis.ModulesV1.PaymentModule.Helpers.SMS { public class ImisBaseSms { diff --git a/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisSms.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/SMS/ImisSms.cs similarity index 80% rename from OpenImis.Modules/PaymentModule/Helpers/SMS/ImisSms.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/SMS/ImisSms.cs index 0e69cabb..ac143134 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/SMS/ImisSms.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/SMS/ImisSms.cs @@ -1,11 +1,11 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; -using OpenImis.Modules.PaymentModule.Models; +using OpenImis.ModulesV1.PaymentModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers.SMS +namespace OpenImis.ModulesV1.PaymentModule.Helpers.SMS { public class ImisSms : ImisBaseSms { diff --git a/OpenImis.Modules/PaymentModule/Helpers/SaveAckResponse.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/SaveAckResponse.cs similarity index 90% rename from OpenImis.Modules/PaymentModule/Helpers/SaveAckResponse.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/SaveAckResponse.cs index 849d1f6c..70d82b3a 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/SaveAckResponse.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/SaveAckResponse.cs @@ -1,10 +1,10 @@ -using OpenImis.Modules.PaymentModule.Helpers.Messages; +using OpenImis.ModulesV1.PaymentModule.Helpers.Messages; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers +namespace OpenImis.ModulesV1.PaymentModule.Helpers { public class SaveAckResponse : ImisApiResponse { diff --git a/OpenImis.Modules/PaymentModule/Helpers/SaveIntentResponse.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/SaveIntentResponse.cs similarity index 96% rename from OpenImis.Modules/PaymentModule/Helpers/SaveIntentResponse.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/SaveIntentResponse.cs index a601eb95..ad93ec21 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/SaveIntentResponse.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/SaveIntentResponse.cs @@ -1,10 +1,10 @@ -using OpenImis.Modules.PaymentModule.Helpers.Messages; +using OpenImis.ModulesV1.PaymentModule.Helpers.Messages; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers +namespace OpenImis.ModulesV1.PaymentModule.Helpers { public class SaveIntentResponse : ImisApiResponse { diff --git a/OpenImis.Modules/PaymentModule/Helpers/SavePayResponse.cs b/OpenImis.ModulesV1/PaymentModule/Helpers/SavePayResponse.cs similarity index 96% rename from OpenImis.Modules/PaymentModule/Helpers/SavePayResponse.cs rename to OpenImis.ModulesV1/PaymentModule/Helpers/SavePayResponse.cs index 5d3bf7f6..66d4fc3f 100644 --- a/OpenImis.Modules/PaymentModule/Helpers/SavePayResponse.cs +++ b/OpenImis.ModulesV1/PaymentModule/Helpers/SavePayResponse.cs @@ -1,10 +1,10 @@ -using OpenImis.Modules.PaymentModule.Helpers.Messages; +using OpenImis.ModulesV1.PaymentModule.Helpers.Messages; using System; using System.Collections.Generic; using System.Data; using System.Text; -namespace OpenImis.Modules.PaymentModule.Helpers +namespace OpenImis.ModulesV1.PaymentModule.Helpers { public class SavePayResponse : ImisApiResponse { diff --git a/OpenImis.Modules/PaymentModule/IPaymentModule.cs b/OpenImis.ModulesV1/PaymentModule/IPaymentModule.cs similarity index 50% rename from OpenImis.Modules/PaymentModule/IPaymentModule.cs rename to OpenImis.ModulesV1/PaymentModule/IPaymentModule.cs index eae4def0..df33a178 100644 --- a/OpenImis.Modules/PaymentModule/IPaymentModule.cs +++ b/OpenImis.ModulesV1/PaymentModule/IPaymentModule.cs @@ -1,12 +1,13 @@ -using OpenImis.Modules.PaymentModule.Logic; +using OpenImis.ModulesV1.PaymentModule.Logic; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule +namespace OpenImis.ModulesV1.PaymentModule { public interface IPaymentModule { IPaymentLogic GetPaymentLogic(); + IPaymentModule SetPaymentLogic(IPaymentLogic paymentLogic); } } diff --git a/OpenImis.Modules/PaymentModule/Logic/IPaymentLogic.cs b/OpenImis.ModulesV1/PaymentModule/Logic/IPaymentLogic.cs similarity index 86% rename from OpenImis.Modules/PaymentModule/Logic/IPaymentLogic.cs rename to OpenImis.ModulesV1/PaymentModule/Logic/IPaymentLogic.cs index 74319588..f180e29d 100644 --- a/OpenImis.Modules/PaymentModule/Logic/IPaymentLogic.cs +++ b/OpenImis.ModulesV1/PaymentModule/Logic/IPaymentLogic.cs @@ -1,11 +1,11 @@ -using OpenImis.Modules.PaymentModule.Models; -using OpenImis.Modules.PaymentModule.Repositories; +using OpenImis.ModulesV1.PaymentModule.Models; +using OpenImis.ModulesV1.PaymentModule.Repositories; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; -namespace OpenImis.Modules.PaymentModule.Logic +namespace OpenImis.ModulesV1.PaymentModule.Logic { public interface IPaymentLogic { diff --git a/OpenImis.Modules/PaymentModule/Logic/PaymentLogic.cs b/OpenImis.ModulesV1/PaymentModule/Logic/PaymentLogic.cs similarity index 97% rename from OpenImis.Modules/PaymentModule/Logic/PaymentLogic.cs rename to OpenImis.ModulesV1/PaymentModule/Logic/PaymentLogic.cs index 74ea8089..26b5d462 100644 --- a/OpenImis.Modules/PaymentModule/Logic/PaymentLogic.cs +++ b/OpenImis.ModulesV1/PaymentModule/Logic/PaymentLogic.cs @@ -1,19 +1,17 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration; using Newtonsoft.Json; -using OpenImis.Modules.PaymentModule.Helpers; -using OpenImis.Modules.PaymentModule.Helpers.SMS; -using OpenImis.Modules.PaymentModule.Models; -using OpenImis.Modules.PaymentModule.Models.Response; -using OpenImis.Modules.PaymentModule.Models.SMS; -using OpenImis.Modules.PaymentModule.Repositories; +using OpenImis.ModulesV1.PaymentModule.Helpers; +using OpenImis.ModulesV1.PaymentModule.Helpers.SMS; +using OpenImis.ModulesV1.PaymentModule.Models; +using OpenImis.ModulesV1.PaymentModule.Models.Response; +using OpenImis.ModulesV1.PaymentModule.Models.SMS; +using OpenImis.ModulesV1.PaymentModule.Repositories; using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading.Tasks; -namespace OpenImis.Modules.PaymentModule.Logic +namespace OpenImis.ModulesV1.PaymentModule.Logic { public class PaymentLogic : IPaymentLogic { diff --git a/OpenImis.Modules/PaymentModule/Models/Acknowledgement.cs b/OpenImis.ModulesV1/PaymentModule/Models/Acknowledgement.cs similarity index 87% rename from OpenImis.Modules/PaymentModule/Models/Acknowledgement.cs rename to OpenImis.ModulesV1/PaymentModule/Models/Acknowledgement.cs index d54e0e06..27a960f0 100644 --- a/OpenImis.Modules/PaymentModule/Models/Acknowledgement.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/Acknowledgement.cs @@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public class Acknowledgement { diff --git a/OpenImis.Modules/PaymentModule/Models/CnStatus.cs b/OpenImis.ModulesV1/PaymentModule/Models/CnStatus.cs similarity index 79% rename from OpenImis.Modules/PaymentModule/Models/CnStatus.cs rename to OpenImis.ModulesV1/PaymentModule/Models/CnStatus.cs index 20235656..61e100bf 100644 --- a/OpenImis.Modules/PaymentModule/Models/CnStatus.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/CnStatus.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public enum CnStatus { diff --git a/OpenImis.Modules/PaymentModule/Models/ControlNumberResp.cs b/OpenImis.ModulesV1/PaymentModule/Models/ControlNumberResp.cs similarity index 89% rename from OpenImis.Modules/PaymentModule/Models/ControlNumberResp.cs rename to OpenImis.ModulesV1/PaymentModule/Models/ControlNumberResp.cs index bfd30347..faffe9a9 100644 --- a/OpenImis.Modules/PaymentModule/Models/ControlNumberResp.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/ControlNumberResp.cs @@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public class ControlNumberResp { diff --git a/OpenImis.Modules/InsureeModule/Models/DataMessage.cs b/OpenImis.ModulesV1/PaymentModule/Models/DataMessage.cs similarity index 85% rename from OpenImis.Modules/InsureeModule/Models/DataMessage.cs rename to OpenImis.ModulesV1/PaymentModule/Models/DataMessage.cs index acfc03d2..f3a3f7a0 100644 --- a/OpenImis.Modules/InsureeModule/Models/DataMessage.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/DataMessage.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.InsureeModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public class DataMessage { diff --git a/OpenImis.Modules/PaymentModule/Models/EnrolmentType.cs b/OpenImis.ModulesV1/PaymentModule/Models/EnrolmentType.cs similarity index 74% rename from OpenImis.Modules/PaymentModule/Models/EnrolmentType.cs rename to OpenImis.ModulesV1/PaymentModule/Models/EnrolmentType.cs index e4910478..9f8b23a8 100644 --- a/OpenImis.Modules/PaymentModule/Models/EnrolmentType.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/EnrolmentType.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public enum EnrolmentType { diff --git a/OpenImis.Modules/PaymentModule/Models/InsureeProduct.cs b/OpenImis.ModulesV1/PaymentModule/Models/InsureeProduct.cs similarity index 91% rename from OpenImis.Modules/PaymentModule/Models/InsureeProduct.cs rename to OpenImis.ModulesV1/PaymentModule/Models/InsureeProduct.cs index f8209281..f47743c4 100644 --- a/OpenImis.Modules/PaymentModule/Models/InsureeProduct.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/InsureeProduct.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public class InsureeProduct { diff --git a/OpenImis.Modules/PaymentModule/Models/IntentOfPay.cs b/OpenImis.ModulesV1/PaymentModule/Models/IntentOfPay.cs similarity index 74% rename from OpenImis.Modules/PaymentModule/Models/IntentOfPay.cs rename to OpenImis.ModulesV1/PaymentModule/Models/IntentOfPay.cs index ce5e641b..163e5eff 100644 --- a/OpenImis.Modules/PaymentModule/Models/IntentOfPay.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/IntentOfPay.cs @@ -1,22 +1,21 @@ -using OpenImis.Modules.Helpers.Validators; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public class IntentOfPay { [Required(ErrorMessage = "9: Phone number not provided")] public virtual string phone_number { get; set; } - [ValidDate(ErrorMessage = "10: Request Date not valid")] + //[ValidDate(ErrorMessage = "10: Request Date not valid")] [DataType(DataType.DateTime)] public string request_date { get; set; } - [OfficerCode] + //[OfficerCode] public string enrolment_officer_code { get; set; } public virtual List policies { get; set; } - [RequiredIfEo("amunt to be paid")] + //[RequiredIfEo("amunt to be paid")] public decimal amount_to_be_paid { get; set; } public string language { get; set; } [Range(0, 2, ErrorMessage = "10-Uknown type of payment")] diff --git a/OpenImis.ModulesV1/PaymentModule/Models/Language.cs b/OpenImis.ModulesV1/PaymentModule/Models/Language.cs new file mode 100644 index 00000000..5f017418 --- /dev/null +++ b/OpenImis.ModulesV1/PaymentModule/Models/Language.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV1.PaymentModule.Models +{ + public enum Language + { + Primary, + Secondary + } +} diff --git a/OpenImis.Modules/PaymentModule/Models/MatchModel.cs b/OpenImis.ModulesV1/PaymentModule/Models/MatchModel.cs similarity index 84% rename from OpenImis.Modules/PaymentModule/Models/MatchModel.cs rename to OpenImis.ModulesV1/PaymentModule/Models/MatchModel.cs index 34111ec3..6b7b11ab 100644 --- a/OpenImis.Modules/PaymentModule/Models/MatchModel.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/MatchModel.cs @@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public class MatchModel { diff --git a/OpenImis.Modules/PaymentModule/Models/MatchSms.cs b/OpenImis.ModulesV1/PaymentModule/Models/MatchSms.cs similarity index 83% rename from OpenImis.Modules/PaymentModule/Models/MatchSms.cs rename to OpenImis.ModulesV1/PaymentModule/Models/MatchSms.cs index b3ed5849..a8f54f86 100644 --- a/OpenImis.Modules/PaymentModule/Models/MatchSms.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/MatchSms.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public class MatchSms { diff --git a/OpenImis.Modules/PaymentModule/Models/MatchedPayment.cs b/OpenImis.ModulesV1/PaymentModule/Models/MatchedPayment.cs similarity index 88% rename from OpenImis.Modules/PaymentModule/Models/MatchedPayment.cs rename to OpenImis.ModulesV1/PaymentModule/Models/MatchedPayment.cs index d4176357..20cb4998 100644 --- a/OpenImis.Modules/PaymentModule/Models/MatchedPayment.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/MatchedPayment.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public class MatchedPayment { diff --git a/OpenImis.Modules/PaymentModule/Models/PaymentData.cs b/OpenImis.ModulesV1/PaymentModule/Models/PaymentData.cs similarity index 68% rename from OpenImis.Modules/PaymentModule/Models/PaymentData.cs rename to OpenImis.ModulesV1/PaymentModule/Models/PaymentData.cs index 19b80451..5f88c0fa 100644 --- a/OpenImis.Modules/PaymentModule/Models/PaymentData.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/PaymentData.cs @@ -1,31 +1,30 @@ -using OpenImis.Modules.Helpers.Validators; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public class PaymentData { public string control_number { get; set; } - [InsureeNumber] - [RequiredIf("Insuree number")] //this attributes validates if control number is not provided + //[InsureeNumber] + //[RequiredIf("Insuree number")] //this attributes validates if control number is not provided public string insurance_number { get; set; } - [RequiredIf("Insurance Product Code")] + //[RequiredIf("Insurance Product Code")] public string insurance_product_code { get; set; } - [RequiredIf("Renewal")] + //[RequiredIf("Renewal")] public EnrolmentType? renewal { get; set; } - [RequiredIf("Enrolment Officer Code", 2)] + //[RequiredIf("Enrolment Officer Code", 2)] public string enrolment_officer_code { get; set; } public string transaction_identification { get; set; } public string receipt_identification { get; set; } public double received_amount { get; set; } [Required(ErrorMessage = "1-Wrong or missing receiving date")] - [ValidDate(ErrorMessage = "1-Wrong or missing receiving date")] + //[ValidDate(ErrorMessage = "1-Wrong or missing receiving date")] [DataType(DataType.DateTime)] public string received_date { get; set; } - [ValidDate(ErrorMessage = "5-Invalid Payment Date")] + //[ValidDate(ErrorMessage = "5-Invalid Payment Date")] [DataType(DataType.DateTime)] public string payment_date { get; set; } public string payment_origin { get; set; } diff --git a/OpenImis.Modules/PaymentModule/Models/PaymentDetail.cs b/OpenImis.ModulesV1/PaymentModule/Models/PaymentDetail.cs similarity index 85% rename from OpenImis.Modules/PaymentModule/Models/PaymentDetail.cs rename to OpenImis.ModulesV1/PaymentModule/Models/PaymentDetail.cs index a063be64..dece0441 100644 --- a/OpenImis.Modules/PaymentModule/Models/PaymentDetail.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/PaymentDetail.cs @@ -1,14 +1,13 @@ -using OpenImis.Modules.Helpers.Validators; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public class PaymentDetail { - [InsureeNumber] + //[InsureeNumber] public string insurance_number { get; set; } [Required(ErrorMessage = "2:Not valid insurance or missing product code")] public string insurance_product_code { get; set; } diff --git a/OpenImis.Modules/PaymentModule/Models/PaymentRequest.cs b/OpenImis.ModulesV1/PaymentModule/Models/PaymentRequest.cs similarity index 77% rename from OpenImis.Modules/PaymentModule/Models/PaymentRequest.cs rename to OpenImis.ModulesV1/PaymentModule/Models/PaymentRequest.cs index 517a96bc..bd488ff7 100644 --- a/OpenImis.Modules/PaymentModule/Models/PaymentRequest.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/PaymentRequest.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public class PaymentRequest { diff --git a/OpenImis.Modules/PaymentModule/Models/Request.cs b/OpenImis.ModulesV1/PaymentModule/Models/Request.cs similarity index 85% rename from OpenImis.Modules/PaymentModule/Models/Request.cs rename to OpenImis.ModulesV1/PaymentModule/Models/Request.cs index 9c41860c..67121fba 100644 --- a/OpenImis.Modules/PaymentModule/Models/Request.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/Request.cs @@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public class Request { diff --git a/OpenImis.Modules/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs b/OpenImis.ModulesV1/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs similarity index 81% rename from OpenImis.Modules/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs rename to OpenImis.ModulesV1/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs index 58fe97cb..75975755 100644 --- a/OpenImis.Modules/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models.Response +namespace OpenImis.ModulesV1.PaymentModule.Models.Response { public class AsignedControlNumbersResponse { diff --git a/OpenImis.Modules/PaymentModule/Models/Response/AssignedControlNumber.cs b/OpenImis.ModulesV1/PaymentModule/Models/Response/AssignedControlNumber.cs similarity index 79% rename from OpenImis.Modules/PaymentModule/Models/Response/AssignedControlNumber.cs rename to OpenImis.ModulesV1/PaymentModule/Models/Response/AssignedControlNumber.cs index f5c3541d..34c74972 100644 --- a/OpenImis.Modules/PaymentModule/Models/Response/AssignedControlNumber.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/Response/AssignedControlNumber.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models.Response +namespace OpenImis.ModulesV1.PaymentModule.Models.Response { public class AssignedControlNumber { diff --git a/OpenImis.Modules/PaymentModule/Models/Response/ErrorResponse.cs b/OpenImis.ModulesV1/PaymentModule/Models/Response/ErrorResponse.cs similarity index 74% rename from OpenImis.Modules/PaymentModule/Models/Response/ErrorResponse.cs rename to OpenImis.ModulesV1/PaymentModule/Models/Response/ErrorResponse.cs index 849dfc17..814bf79a 100644 --- a/OpenImis.Modules/PaymentModule/Models/Response/ErrorResponse.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/Response/ErrorResponse.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models.Response +namespace OpenImis.ModulesV1.PaymentModule.Models.Response { public class ErrorResponse { diff --git a/OpenImis.Modules/PaymentModule/Models/Response/ErrorResponseV2.cs b/OpenImis.ModulesV1/PaymentModule/Models/Response/ErrorResponseV2.cs similarity index 78% rename from OpenImis.Modules/PaymentModule/Models/Response/ErrorResponseV2.cs rename to OpenImis.ModulesV1/PaymentModule/Models/Response/ErrorResponseV2.cs index 45b3ae36..51aa8fd3 100644 --- a/OpenImis.Modules/PaymentModule/Models/Response/ErrorResponseV2.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/Response/ErrorResponseV2.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models.Response +namespace OpenImis.ModulesV1.PaymentModule.Models.Response { public class ErrorResponseV2 { diff --git a/OpenImis.Modules/PaymentModule/Models/Response/GetControlNumberResp.cs b/OpenImis.ModulesV1/PaymentModule/Models/Response/GetControlNumberResp.cs similarity index 84% rename from OpenImis.Modules/PaymentModule/Models/Response/GetControlNumberResp.cs rename to OpenImis.ModulesV1/PaymentModule/Models/Response/GetControlNumberResp.cs index cf3e1540..d89ed404 100644 --- a/OpenImis.Modules/PaymentModule/Models/Response/GetControlNumberResp.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/Response/GetControlNumberResp.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models.Response +namespace OpenImis.ModulesV1.PaymentModule.Models.Response { public class GetControlNumberResp { diff --git a/OpenImis.Modules/PaymentModule/Models/Response/PaymentDataBadResp.cs b/OpenImis.ModulesV1/PaymentModule/Models/Response/PaymentDataBadResp.cs similarity index 74% rename from OpenImis.Modules/PaymentModule/Models/Response/PaymentDataBadResp.cs rename to OpenImis.ModulesV1/PaymentModule/Models/Response/PaymentDataBadResp.cs index 1bbd81ed..76915c7e 100644 --- a/OpenImis.Modules/PaymentModule/Models/Response/PaymentDataBadResp.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/Response/PaymentDataBadResp.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models.Response +namespace OpenImis.ModulesV1.PaymentModule.Models.Response { public class PaymentDataBadResp { diff --git a/OpenImis.Modules/PaymentModule/Models/Response/PostReqCNResponse.cs b/OpenImis.ModulesV1/PaymentModule/Models/Response/PostReqCNResponse.cs similarity index 87% rename from OpenImis.Modules/PaymentModule/Models/Response/PostReqCNResponse.cs rename to OpenImis.ModulesV1/PaymentModule/Models/Response/PostReqCNResponse.cs index 3f31add3..e880884e 100644 --- a/OpenImis.Modules/PaymentModule/Models/Response/PostReqCNResponse.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/Response/PostReqCNResponse.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models.Response +namespace OpenImis.ModulesV1.PaymentModule.Models.Response { public class PostReqCNResponse { diff --git a/OpenImis.Modules/PaymentModule/Models/SMS/SmsContainer.cs b/OpenImis.ModulesV1/PaymentModule/Models/SMS/SmsContainer.cs similarity index 79% rename from OpenImis.Modules/PaymentModule/Models/SMS/SmsContainer.cs rename to OpenImis.ModulesV1/PaymentModule/Models/SMS/SmsContainer.cs index 1775e56e..5181b599 100644 --- a/OpenImis.Modules/PaymentModule/Models/SMS/SmsContainer.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/SMS/SmsContainer.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models.SMS +namespace OpenImis.ModulesV1.PaymentModule.Models.SMS { public class SmsContainer { diff --git a/OpenImis.Modules/PaymentModule/Models/TypeOfPayment.cs b/OpenImis.ModulesV1/PaymentModule/Models/TypeOfPayment.cs similarity index 77% rename from OpenImis.Modules/PaymentModule/Models/TypeOfPayment.cs rename to OpenImis.ModulesV1/PaymentModule/Models/TypeOfPayment.cs index 6dd292f4..0c2b9bdd 100644 --- a/OpenImis.Modules/PaymentModule/Models/TypeOfPayment.cs +++ b/OpenImis.ModulesV1/PaymentModule/Models/TypeOfPayment.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule.Models +namespace OpenImis.ModulesV1.PaymentModule.Models { public enum TypeOfPayment { diff --git a/OpenImis.Modules/PaymentModule/PaymentModule.cs b/OpenImis.ModulesV1/PaymentModule/PaymentModule.cs similarity index 55% rename from OpenImis.Modules/PaymentModule/PaymentModule.cs rename to OpenImis.ModulesV1/PaymentModule/PaymentModule.cs index 062a1a83..18b54b3a 100644 --- a/OpenImis.Modules/PaymentModule/PaymentModule.cs +++ b/OpenImis.ModulesV1/PaymentModule/PaymentModule.cs @@ -1,29 +1,35 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; -using OpenImis.Modules.PaymentModule.Logic; +using OpenImis.ModulesV1.PaymentModule.Logic; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.PaymentModule +namespace OpenImis.ModulesV1.PaymentModule { public class PaymentModule : IPaymentModule { - private IConfiguration Configuration; + private IConfiguration _configuration; private IPaymentLogic _paymentLogic; public PaymentModule(IConfiguration configuration) { - Configuration = configuration; + _configuration = configuration; } public IPaymentLogic GetPaymentLogic() { if (_paymentLogic == null) { - _paymentLogic = new PaymentLogic(Configuration); + _paymentLogic = new PaymentLogic(_configuration); } return _paymentLogic; } + + public IPaymentModule SetPaymentLogic(IPaymentLogic paymentLogic) + { + _paymentLogic = paymentLogic; + return this; + } } } diff --git a/OpenImis.Modules/PaymentModule/Repositories/IPaymentRepository.cs b/OpenImis.ModulesV1/PaymentModule/Repositories/IPaymentRepository.cs similarity index 93% rename from OpenImis.Modules/PaymentModule/Repositories/IPaymentRepository.cs rename to OpenImis.ModulesV1/PaymentModule/Repositories/IPaymentRepository.cs index 12b54530..0f23ba4c 100644 --- a/OpenImis.Modules/PaymentModule/Repositories/IPaymentRepository.cs +++ b/OpenImis.ModulesV1/PaymentModule/Repositories/IPaymentRepository.cs @@ -1,11 +1,11 @@ -using OpenImis.Modules.PaymentModule.Models; -using OpenImis.Modules.PaymentModule.Models.Response; +using OpenImis.ModulesV1.PaymentModule.Models; +using OpenImis.ModulesV1.PaymentModule.Models.Response; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; -namespace OpenImis.Modules.PaymentModule.Repositories +namespace OpenImis.ModulesV1.PaymentModule.Repositories { public interface IPaymentRepository { diff --git a/OpenImis.Modules/PaymentModule/Repositories/PaymentRepository.cs b/OpenImis.ModulesV1/PaymentModule/Repositories/PaymentRepository.cs similarity index 99% rename from OpenImis.Modules/PaymentModule/Repositories/PaymentRepository.cs rename to OpenImis.ModulesV1/PaymentModule/Repositories/PaymentRepository.cs index be1c11e1..614391df 100644 --- a/OpenImis.Modules/PaymentModule/Repositories/PaymentRepository.cs +++ b/OpenImis.ModulesV1/PaymentModule/Repositories/PaymentRepository.cs @@ -1,9 +1,9 @@ using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using OpenImis.DB.SqlServer.DataHelper; -using OpenImis.Modules.PaymentModule.Helpers; -using OpenImis.Modules.PaymentModule.Models; -using OpenImis.Modules.PaymentModule.Models.Response; +using OpenImis.ModulesV1.PaymentModule.Helpers; +using OpenImis.ModulesV1.PaymentModule.Models; +using OpenImis.ModulesV1.PaymentModule.Models.Response; using System; using System.Collections.Generic; using System.Data; @@ -13,7 +13,7 @@ using System.Threading.Tasks; using System.Xml.Linq; -namespace OpenImis.Modules.PaymentModule.Repositories +namespace OpenImis.ModulesV1.PaymentModule.Repositories { public class PaymentRepository : IPaymentRepository { diff --git a/OpenImis.ModulesV1/Utils/LinqExtensions.cs b/OpenImis.ModulesV1/Utils/LinqExtensions.cs new file mode 100644 index 00000000..c08a8e0a --- /dev/null +++ b/OpenImis.ModulesV1/Utils/LinqExtensions.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenImis.ModulesV1.Utils +{ + static public class LinqExtensions + { + public static IEnumerable Page(this IEnumerable en, int pageSize, int page) + { + return en.Skip(page * pageSize).Take(pageSize); + } + + public static IQueryable Page(this IQueryable en, int pageSize, int page) + { + return en.Skip(page * pageSize).Take(pageSize); + } + + static public IEnumerable Descendants(this IEnumerable source, Func> DescendBy) + { + foreach (T value in source) + { + yield return value; + + foreach (T child in DescendBy(value).Descendants(DescendBy)) + { + yield return child; + } + } + } + + public static IEnumerable Traverse(this IEnumerable items, Func> childSelector) + { + var stack = new Stack(items); + while (stack.Any()) + { + var next = stack.Pop(); + yield return next; + foreach (var child in childSelector(next)) + stack.Push(child); + } + } + } +} diff --git a/OpenImis.ModulesV1/Utils/Models/PagerModel.cs b/OpenImis.ModulesV1/Utils/Models/PagerModel.cs new file mode 100644 index 00000000..b4dac891 --- /dev/null +++ b/OpenImis.ModulesV1/Utils/Models/PagerModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV1.Utils.Models +{ + /// + /// This class allows to add pagination information to the responses getting list of Entities + /// + /// TODO: think if there should be a string NextPage field with URL for next page (same for PreviousPage) + public class PagerModel + { + public int CurrentPage { get; set; } + public int ResultsPerPage { get; set; } + public int TotalResults { get; set; } + public int TotalPages { get; set; } + } +} diff --git a/OpenImis.ModulesV1/Utils/TypeCast.cs b/OpenImis.ModulesV1/Utils/TypeCast.cs new file mode 100644 index 00000000..566d54d3 --- /dev/null +++ b/OpenImis.ModulesV1/Utils/TypeCast.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace OpenImis.ModulesV1.Utils +{ + public static class TypeCast + { + public static T Cast(Object parentInstance) + { + T result = default(T); + //try + //{ + var serializedParent = JsonConvert.SerializeObject(parentInstance); + result = JsonConvert.DeserializeObject(serializedParent); + //} + //catch (Exception ex) + //{ + // return new T(); + //} + return result; + } + + public static T GetValue(object value) + { + if (value == null || value == DBNull.Value) + return default(T); + else + return (T)value; + } + } +} diff --git a/OpenImis.ModulesV2/ClaimModule/ClaimModule.cs b/OpenImis.ModulesV2/ClaimModule/ClaimModule.cs new file mode 100644 index 00000000..978663b6 --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/ClaimModule.cs @@ -0,0 +1,28 @@ +using OpenImis.ModulesV2.ClaimModule.Logic; + +namespace OpenImis.ModulesV2.ClaimModule +{ + public class ClaimModule : IClaimModule + { + private IClaimLogic _claimLogic; + + public ClaimModule() + { + } + + public IClaimLogic GetClaimLogic() + { + if (_claimLogic == null) + { + _claimLogic = new ClaimLogic(); + } + return _claimLogic; + } + + public IClaimModule SetClaimLogic(IClaimLogic claimLogic) + { + _claimLogic = claimLogic; + return this; + } + } +} diff --git a/OpenImis.ModulesV2/ClaimModule/IClaimModule.cs b/OpenImis.ModulesV2/ClaimModule/IClaimModule.cs new file mode 100644 index 00000000..e642c60a --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/IClaimModule.cs @@ -0,0 +1,10 @@ +using OpenImis.ModulesV2.ClaimModule.Logic; + +namespace OpenImis.ModulesV2.ClaimModule +{ + public interface IClaimModule + { + IClaimLogic GetClaimLogic(); + IClaimModule SetClaimLogic(IClaimLogic claimLogic); + } +} diff --git a/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs b/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs new file mode 100644 index 00000000..20de393d --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.ClaimModule.Logic +{ + public class ClaimLogic : IClaimLogic + { + public ClaimLogic() + { + + } + } +} diff --git a/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs b/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs new file mode 100644 index 00000000..c10a5f4d --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.ClaimModule.Logic +{ + public interface IClaimLogic + { + + } +} diff --git a/OpenImis.ModulesV2/CoverageModule/CoverageModule.cs b/OpenImis.ModulesV2/CoverageModule/CoverageModule.cs new file mode 100644 index 00000000..0cb70831 --- /dev/null +++ b/OpenImis.ModulesV2/CoverageModule/CoverageModule.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.CoverageModule.Logic; + +namespace OpenImis.ModulesV2.CoverageModule +{ + public class CoverageModule : ICoverageModule + { + private IConfiguration _configuration; + private ICoverageLogic _coverageLogic; + + public CoverageModule(IConfiguration configuration) + { + _configuration = configuration; + } + + public ICoverageLogic GetCoverageLogic() + { + if (_coverageLogic == null) + { + _coverageLogic = new CoverageLogic(_configuration); + } + return _coverageLogic; + } + + public ICoverageModule SetCoverageLogic(ICoverageLogic coverageLogic) + { + _coverageLogic = coverageLogic; + return this; + } + } +} diff --git a/OpenImis.ModulesV2/CoverageModule/ICoverageModule.cs b/OpenImis.ModulesV2/CoverageModule/ICoverageModule.cs new file mode 100644 index 00000000..71427958 --- /dev/null +++ b/OpenImis.ModulesV2/CoverageModule/ICoverageModule.cs @@ -0,0 +1,11 @@ +using OpenImis.ModulesV2.CoverageModule.Logic; +using System; + +namespace OpenImis.ModulesV2.CoverageModule +{ + public interface ICoverageModule + { + ICoverageLogic GetCoverageLogic(); + ICoverageModule SetCoverageLogic(ICoverageLogic coverageLogic); + } +} diff --git a/OpenImis.ModulesV2/CoverageModule/Logic/CoverageLogic.cs b/OpenImis.ModulesV2/CoverageModule/Logic/CoverageLogic.cs new file mode 100644 index 00000000..b19e8b1a --- /dev/null +++ b/OpenImis.ModulesV2/CoverageModule/Logic/CoverageLogic.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.Configuration; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.CoverageModule.Logic +{ + public class CoverageLogic : ICoverageLogic + { + private IConfiguration _configuration; + + public CoverageLogic(IConfiguration configuration) + { + _configuration = configuration; + } + } +} diff --git a/OpenImis.ModulesV2/CoverageModule/Logic/ICoverageLogic.cs b/OpenImis.ModulesV2/CoverageModule/Logic/ICoverageLogic.cs new file mode 100644 index 00000000..f8147995 --- /dev/null +++ b/OpenImis.ModulesV2/CoverageModule/Logic/ICoverageLogic.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.CoverageModule.Logic +{ + public interface ICoverageLogic + { + + } +} diff --git a/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs b/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs new file mode 100644 index 00000000..8355b6d4 --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.Helpers +{ + public class ConfigImisModules + { + public string Version { get; set; } + public LoginModule LoginModule { get; set; } + public ClaimModule ClaimModule { get; set; } + public CoverageModule CoverageModule { get; set; } + public InsureeModule InsureeModule { get; set; } + public PaymentModule PaymentModule { get; set; } + } + + public class LoginModule + { + public string LoginLogic { get; set; } + } + + public class ClaimModule + { + public string ClaimLogic { get; set; } + } + + public class CoverageModule + { + public string CoverageLogic { get; set; } + } + + public class InsureeModule + { + public string FamilyLogic { get; set; } + public string PolicyLogic { get; set; } + public string ContributionLogic { get; set; } + } + + public class PaymentModule + { + public string PaymentLogic { get; set; } + } +} diff --git a/OpenImis.ModulesV2/Helpers/Validators/InsureeNumberAttribute.cs b/OpenImis.ModulesV2/Helpers/Validators/InsureeNumberAttribute.cs new file mode 100644 index 00000000..8e25f71b --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/Validators/InsureeNumberAttribute.cs @@ -0,0 +1,26 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace OpenImis.ModulesV2.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class InsureeNumberAttribute : ValidationAttribute + { + public InsureeNumberAttribute() + { + } + + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + if (value != null) + { + Validation val = new Validation(); + ValidationResult result = val.InsureeNumber(value.ToString()); + + return result; + } + + return ValidationResult.Success; + } + } +} diff --git a/OpenImis.ModulesV2/Helpers/Validators/OfficerCodeAttribute.cs b/OpenImis.ModulesV2/Helpers/Validators/OfficerCodeAttribute.cs new file mode 100644 index 00000000..d64b8db4 --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/Validators/OfficerCodeAttribute.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.ModulesV2.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class OfficerCodeAttribute : ValidationAttribute + { + public OfficerCodeAttribute() + { + } + + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + Validation val = new Validation(); + ValidationResult result = val.OfficerCode(value); + + return result; + } + } +} diff --git a/OpenImis.ModulesV2/Helpers/Validators/RequiredIfAttribute.cs b/OpenImis.ModulesV2/Helpers/Validators/RequiredIfAttribute.cs new file mode 100644 index 00000000..13eeb00b --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/Validators/RequiredIfAttribute.cs @@ -0,0 +1,43 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace OpenImis.ModulesV2.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class RequiredIfAttribute : ValidationAttribute + { + private string _fieldName; + private int _fieldNumber; + + public RequiredIfAttribute(string fieldName, int fieldNumber = 0) // fieldNumber = 1:control_number 2:insurance_number, 3:insurance_product_code, 4:renewal, 5:enrolment_officer_code + { + _fieldName = fieldName; + _fieldNumber = fieldNumber; + } + + //protected override ValidationResult IsValid(object value, ValidationContext validationContext) + //{ + // PaymentData payment = (PaymentData)validationContext.ObjectInstance; + + // if (payment.control_number == null && value == null) + // { + // if (_fieldNumber == 2 && payment.insurance_number != null) + // { + // return ValidationResult.Success; + // } + // else + // { + // return new ValidationResult(_fieldName + " is required if Control Number is not provided"); + // } + // } + // if (payment.control_number != null && value != null) + // { + // return new ValidationResult(_fieldName + " is not required if Control Number is provided"); + // } + // else + // { + // return ValidationResult.Success; + // } + //} + } +} diff --git a/OpenImis.ModulesV2/Helpers/Validators/RequiredIfEoAttribute.cs b/OpenImis.ModulesV2/Helpers/Validators/RequiredIfEoAttribute.cs new file mode 100644 index 00000000..5ae56289 --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/Validators/RequiredIfEoAttribute.cs @@ -0,0 +1,32 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace OpenImis.ModulesV2.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class RequiredIfEoAttribute : ValidationAttribute + { + private string _fieldName; + private int _fieldNumber; + + public RequiredIfEoAttribute(string fieldName) // fieldNumber = 1:control_number 2:insurance_number, 3:insurance_product_code, 4:renewal, 5:enrolment_officer_code + { + _fieldName = fieldName; + } + + //protected override ValidationResult IsValid(object value, ValidationContext validationContext) + //{ + // IntentOfPay intent = (IntentOfPay)validationContext.ObjectInstance; + + // if (intent.enrolment_officer_code == null && value != null && Convert.ToInt32(value) != 0) + // { + // return new ValidationResult(_fieldName + " is not required if Enrolment officer is not provided"); + // } + // else + // { + // return ValidationResult.Success; + // } + + //} + } +} diff --git a/OpenImis.ModulesV2/Helpers/Validators/ValidDateAttribute.cs b/OpenImis.ModulesV2/Helpers/Validators/ValidDateAttribute.cs new file mode 100644 index 00000000..b0f3c90c --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/Validators/ValidDateAttribute.cs @@ -0,0 +1,46 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Globalization; + +namespace OpenImis.ModulesV2.Helpers.Validators +{ + [AttributeUsage(AttributeTargets.Property, Inherited = false)] + public class ValidDateAttribute : ValidationAttribute + { + public ValidDateAttribute() + { + } + + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + if (value == null) + return ValidationResult.Success; + + try + { + DateTime date = Convert.ToDateTime(value.ToString()); + DateTime Odate; + + if (date.Year > 1753) + { + if (DateTime.TryParseExact(value.ToString(), "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out Odate)) + { + return ValidationResult.Success; + } + else + { + return new ValidationResult(null); + } + } + else + { + return new ValidationResult(null); + } + } + catch (Exception) + { + return new ValidationResult(null); + } + } + } +} diff --git a/OpenImis.ModulesV2/Helpers/Validators/Validation.cs b/OpenImis.ModulesV2/Helpers/Validators/Validation.cs new file mode 100644 index 00000000..1d53b519 --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/Validators/Validation.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.ModulesV2.Helpers.Validators +{ + public class Validation + { + public virtual ValidationResult InsureeNumber(string insureeNumber) + { + if (insureeNumber != null) + { + if (insureeNumber.Length < 12 && insureeNumber.Length > 0) + return ValidationResult.Success; + else + return new ValidationResult("1:Wrong format of insurance number "); + } + + return ValidationResult.Success; + } + + public virtual ValidationResult OfficerCode(object value) + { + if (value != null) + { + if (value.ToString().Length < 8) + return ValidationResult.Success; + else + return new ValidationResult("3:Not valid enrolment officer code"); + } + + return ValidationResult.Success; + } + } +} diff --git a/OpenImis.ModulesV2/IImisModules.cs b/OpenImis.ModulesV2/IImisModules.cs new file mode 100644 index 00000000..80ade352 --- /dev/null +++ b/OpenImis.ModulesV2/IImisModules.cs @@ -0,0 +1,24 @@ +using OpenImis.ModulesV2.LoginModule; +using OpenImis.ModulesV2.ClaimModule; +using OpenImis.ModulesV2.InsureeModule; +using OpenImis.ModulesV2.CoverageModule; +using OpenImis.ModulesV2.PaymentModule; + +namespace OpenImis.ModulesV2 +{ + /// + /// This interface serves to define a Service for the IMIS modules + /// + public interface IImisModules + { + ILoginModule GetLoginModule(); + + IClaimModule GetClaimModule(); + + IInsureeModule GetInsureeModule(); + + ICoverageModule GetCoverageModule(); + + IPaymentModule GetPaymentModule(); + } +} diff --git a/OpenImis.ModulesV2/ImisModules.cs b/OpenImis.ModulesV2/ImisModules.cs new file mode 100644 index 00000000..b3e37914 --- /dev/null +++ b/OpenImis.ModulesV2/ImisModules.cs @@ -0,0 +1,181 @@ +using System.Reflection; +using System; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using OpenImis.ModulesV2.LoginModule; +using OpenImis.ModulesV2.ClaimModule; +using OpenImis.ModulesV2.InsureeModule; +using OpenImis.ModulesV2.CoverageModule; +using OpenImis.ModulesV2.PaymentModule; +using OpenImis.ModulesV2.Helpers; +using System.Collections.Generic; +using System.Linq; + +namespace OpenImis.ModulesV2 +{ + public class ImisModules : IImisModules + { + private ILoginModule loginModule; + + private InsureeModule.IInsureeModule insureeModule; + private ClaimModule.IClaimModule claimModule; + private CoverageModule.ICoverageModule coverageModule; + private PaymentModule.IPaymentModule paymentModule; + + private readonly IConfiguration _configuration; + private readonly ILogger _logger; + private readonly IServiceProvider _serviceProvider; + + public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory, IServiceProvider serviceProvider) + { + _configuration = configuration; + _logger = loggerFactory.CreateLogger("LoggerCategory"); + _serviceProvider = serviceProvider; + } + + /// + /// Creates and returns the login module version 2. + /// + /// + /// The Login module V2. + /// + public ILoginModule GetLoginModule() + { + if (loginModule == null) + { + loginModule = new LoginModule.LoginModule(_configuration); + + Type loginLogicType = CreateTypeFromConfiguration("LoginModule", "LoginLogic", "OpenImis.ModulesV2.LoginModule.Logic.LoginLogic"); + loginModule.SetLoginLogic((LoginModule.Logic.ILoginLogic)ActivatorUtilities.CreateInstance(_serviceProvider, loginLogicType)); + } + return loginModule; + } + + /// + /// Creates and returns the claim module version 2. + /// + /// + /// The Claim module V2. + /// + public IClaimModule GetClaimModule() + { + if (claimModule == null) + { + claimModule = new ClaimModule.ClaimModule(); + + Type claimLogicType = CreateTypeFromConfiguration("ClaimModule", "ClaimLogic", "OpenImis.ModulesV2.ClaimModule.Logic.ClaimLogic"); + claimModule.SetClaimLogic((ClaimModule.Logic.IClaimLogic)ActivatorUtilities.CreateInstance(_serviceProvider, claimLogicType)); + } + return claimModule; + } + + /// + /// Creates and returns the insuree module version 2. + /// + /// + /// The Insuree module V2. + /// + public IInsureeModule GetInsureeModule() + { + if (insureeModule == null) + { + insureeModule = new InsureeModule.InsureeModule(_configuration); + + Type familyLogicType = CreateTypeFromConfiguration("InsureeModule", "FamilyLogic", "OpenImis.ModulesV2.InsureeModule.Logic.FamilyLogic"); + insureeModule.SetFamilyLogic((InsureeModule.Logic.IFamilyLogic)ActivatorUtilities.CreateInstance(_serviceProvider, familyLogicType)); + + Type policyLogicType = CreateTypeFromConfiguration("InsureeModule", "PolicyLogic", "OpenImis.ModulesV2.InsureeModule.Logic.PolicyLogic"); + insureeModule.SetPolicyLogic((InsureeModule.Logic.IPolicyLogic)ActivatorUtilities.CreateInstance(_serviceProvider, policyLogicType)); + + Type contributionLogicType = CreateTypeFromConfiguration("InsureeModule", "ContributionLogic", "OpenImis.ModulesV2.InsureeModule.Logic.ContributionLogic"); + insureeModule.SetContributionLogic((InsureeModule.Logic.IContributionLogic)ActivatorUtilities.CreateInstance(_serviceProvider, contributionLogicType)); + } + return insureeModule; + } + + /// + /// Creates and returns the payment module version 2. + /// + /// + /// The Payment module V2. + /// + public ICoverageModule GetCoverageModule() + { + if (coverageModule == null) + { + coverageModule = new CoverageModule.CoverageModule(_configuration); + + Type coverageLogicType = CreateTypeFromConfiguration("CoverageModule", "CoverageLogic", "OpenImis.ModulesV2.CoverageModule.Logic.CoverageLogic"); + coverageModule.SetCoverageLogic((CoverageModule.Logic.ICoverageLogic)ActivatorUtilities.CreateInstance(_serviceProvider, coverageLogicType)); + } + return coverageModule; + } + + /// + /// Creates and returns the payment module version 2. + /// + /// + /// The Payment module V2. + /// + public IPaymentModule GetPaymentModule() + { + if (paymentModule == null) + { + paymentModule = new PaymentModule.PaymentModule(_configuration); + + Type paymentLogicType = CreateTypeFromConfiguration("PaymentModule", "PaymentLogic", "OpenImis.ModulesV2.PaymentModule.Logic.PaymentLogic"); + paymentModule.SetPaymentLogic((PaymentModule.Logic.IPaymentLogic)ActivatorUtilities.CreateInstance(_serviceProvider, paymentLogicType)); + } + return paymentModule; + } + + /// + /// Creates and returns the type based on the string from the configuration + /// + /// The module name + /// The section name + /// The default section value + /// Type represented by the section + private Type CreateTypeFromConfiguration(string moduleName, string sectionName, string defaultValue) + { + Type type; + + string part = ""; + + Assembly assembly = Assembly.GetCallingAssembly(); + + var listImisModules = _configuration.GetSection("ImisModules").Get>(); + + if (listImisModules.Where(v => v.Version == "2").Any(x => GetPropValue(x, moduleName) != null)) + { + object module = listImisModules.Where(v => v.Version == "2").Select(x => GetPropValue(x, moduleName)).FirstOrDefault(); + + if (GetPropValue(module, sectionName) != null) + { + part = GetPropValue(module, sectionName).ToString(); + } + } + + type = assembly.GetType(part); + + if (type == null) + { + _logger.LogError(moduleName + " " + sectionName + " error: the type " + part + " was not found. Using default " + defaultValue + " configuration."); + + type = assembly.GetType(defaultValue); + } + else + { + _logger.LogInformation(moduleName + " load OK: " + part); + } + + return type; + } + + public static object GetPropValue(object src, string propName) + { + return src.GetType().GetProperty(propName).GetValue(src, null); + } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/IInsureeModule.cs b/OpenImis.ModulesV2/InsureeModule/IInsureeModule.cs new file mode 100644 index 00000000..e946029e --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/IInsureeModule.cs @@ -0,0 +1,15 @@ +using OpenImis.ModulesV2.InsureeModule.Logic; +using System; + +namespace OpenImis.ModulesV2.InsureeModule +{ + public interface IInsureeModule + { + IFamilyLogic GetFamilyLogic(); + IContributionLogic GetContributionLogic(); + IPolicyLogic GetPolicyLogic(); + IInsureeModule SetFamilyLogic(IFamilyLogic familyLogic); + IInsureeModule SetPolicyLogic(IPolicyLogic policyLogic); + IInsureeModule SetContributionLogic(IContributionLogic contributionLogic); + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs b/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs new file mode 100644 index 00000000..98d9c247 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs @@ -0,0 +1,64 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.InsureeModule.Logic; + +namespace OpenImis.ModulesV2.InsureeModule +{ + public class InsureeModule : IInsureeModule + { + private IConfiguration _configuration; + + private IFamilyLogic _familyLogic; + private IContributionLogic _contributionLogic; + private IPolicyLogic _policyLogic; + + public InsureeModule(IConfiguration configuration) + { + _configuration = configuration; + } + + public IFamilyLogic GetFamilyLogic() + { + if (_familyLogic == null) + { + _familyLogic = new FamilyLogic(_configuration); + } + return _familyLogic; + } + + public IContributionLogic GetContributionLogic() + { + if (_contributionLogic == null) + { + _contributionLogic = new ContributionLogic(_configuration); + } + return _contributionLogic; + } + + public IPolicyLogic GetPolicyLogic() + { + if (_policyLogic == null) + { + _policyLogic = new PolicyLogic(_configuration); + } + return _policyLogic; + } + + public IInsureeModule SetFamilyLogic(IFamilyLogic familyLogic) + { + _familyLogic = familyLogic; + return this; + } + + public IInsureeModule SetPolicyLogic(IPolicyLogic policyLogic) + { + _policyLogic = policyLogic; + return this; + } + + public IInsureeModule SetContributionLogic(IContributionLogic contributionLogic) + { + _contributionLogic = contributionLogic; + return this; + } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/ContributionLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/ContributionLogic.cs new file mode 100644 index 00000000..3b4097ba --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Logic/ContributionLogic.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.Configuration; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Logic +{ + public class ContributionLogic : IContributionLogic + { + private IConfiguration _configuration; + + public ContributionLogic(IConfiguration configuration) + { + _configuration = configuration; + } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs new file mode 100644 index 00000000..eafc97fe --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs @@ -0,0 +1,18 @@ +using Microsoft.Extensions.Configuration; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Logic +{ + public class FamilyLogic : IFamilyLogic + { + private IConfiguration _configuration; + + public FamilyLogic(IConfiguration configuration) + { + _configuration = configuration; + } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/IContributionLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/IContributionLogic.cs new file mode 100644 index 00000000..408465ba --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Logic/IContributionLogic.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Logic +{ + public interface IContributionLogic + { + + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs new file mode 100644 index 00000000..ba971a74 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Logic +{ + public interface IFamilyLogic + { + + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs new file mode 100644 index 00000000..d0200b2c --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Logic +{ + public interface IPolicyLogic + { + + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs new file mode 100644 index 00000000..ac2072b2 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs @@ -0,0 +1,14 @@ +using Microsoft.Extensions.Configuration; + +namespace OpenImis.ModulesV2.InsureeModule.Logic +{ + public class PolicyLogic : IPolicyLogic + { + private IConfiguration _configuration; + + public PolicyLogic(IConfiguration configuration) + { + _configuration = configuration; + } + } +} diff --git a/OpenImis.ModulesV2/LoginModule/ILoginModule.cs b/OpenImis.ModulesV2/LoginModule/ILoginModule.cs new file mode 100644 index 00000000..ab71bf72 --- /dev/null +++ b/OpenImis.ModulesV2/LoginModule/ILoginModule.cs @@ -0,0 +1,10 @@ +using OpenImis.ModulesV2.LoginModule.Logic; + +namespace OpenImis.ModulesV2.LoginModule +{ + public interface ILoginModule + { + ILoginLogic GetLoginLogic(); + ILoginModule SetLoginLogic(ILoginLogic loginLogic); + } +} diff --git a/OpenImis.ModulesV2/LoginModule/Logic/ILoginLogic.cs b/OpenImis.ModulesV2/LoginModule/Logic/ILoginLogic.cs new file mode 100644 index 00000000..bb8e8a4d --- /dev/null +++ b/OpenImis.ModulesV2/LoginModule/Logic/ILoginLogic.cs @@ -0,0 +1,10 @@ +using OpenImis.ModulesV2.LoginModule.Models; + +namespace OpenImis.ModulesV2.LoginModule.Logic +{ + public interface ILoginLogic + { + UserData GetById(int userId); + UserData FindUser(string UserName, string Password); + } +} diff --git a/OpenImis.ModulesV2/LoginModule/Logic/LoginLogic.cs b/OpenImis.ModulesV2/LoginModule/Logic/LoginLogic.cs new file mode 100644 index 00000000..dbbb4a8a --- /dev/null +++ b/OpenImis.ModulesV2/LoginModule/Logic/LoginLogic.cs @@ -0,0 +1,85 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.LoginModule.Models; +using OpenImis.ModulesV2.LoginModule.Repositories; +using System; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Security.Claims; +using System.Security.Cryptography; +using System.Text; + +namespace OpenImis.ModulesV2.LoginModule.Logic +{ + public class LoginLogic : ILoginLogic + { + private IConfiguration _configuration; + protected ILoginRepository loginRepository; + + public LoginLogic(IConfiguration configuration) + { + _configuration = configuration; + loginRepository = new LoginRepository(_configuration); + } + + public UserData GetById(int userId) + { + return loginRepository.GetById(userId); + } + + public UserData FindUser(string UserName, string Password) + { + var users = loginRepository.FindUserByName(UserName); + + if (users.Count == 1) + { + UserData user = users.FirstOrDefault(); + + bool validUser = ValidateLogin(user, Password); + + if (validUser) + { + return user; + } + else + { + return null; + } + } + else + { + return null; + } + } + + private bool ValidateLogin(UserData user, string password) + { + var generatedSHA = GenerateSHA256String(password + user.PrivateKey); + if (generatedSHA == user.StoredPassword) + { + return true; + } + else + { + return false; + } + } + + private string GenerateSHA256String(string inputString) + { + SHA256 sha256 = SHA256Managed.Create(); + byte[] bytes = Encoding.UTF8.GetBytes(inputString); + byte[] hash = sha256.ComputeHash(bytes); + var stringBuilder = new StringBuilder(); + + for (int i = 0; i < hash.Length; i++) + { + var str = hash[i].ToString("X2"); + stringBuilder.Append(str); + } + + return stringBuilder.ToString(); + } + } +} \ No newline at end of file diff --git a/OpenImis.ModulesV2/LoginModule/LoginModule.cs b/OpenImis.ModulesV2/LoginModule/LoginModule.cs new file mode 100644 index 00000000..e7744646 --- /dev/null +++ b/OpenImis.ModulesV2/LoginModule/LoginModule.cs @@ -0,0 +1,34 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.LoginModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.LoginModule +{ + public class LoginModule : ILoginModule + { + private IConfiguration _configuration; + private ILoginLogic _loginLogic; + + public LoginModule(IConfiguration configuration) + { + _configuration = configuration; + } + + public ILoginLogic GetLoginLogic() + { + if (_loginLogic == null) + { + _loginLogic = new LoginLogic(_configuration); + } + return _loginLogic; + } + + public ILoginModule SetLoginLogic(ILoginLogic loginLogic) + { + _loginLogic = loginLogic; + return this; + } + } +} diff --git a/OpenImis.Modules/LoginModule/Models/Language.cs b/OpenImis.ModulesV2/LoginModule/Models/Language.cs similarity index 75% rename from OpenImis.Modules/LoginModule/Models/Language.cs rename to OpenImis.ModulesV2/LoginModule/Models/Language.cs index ab6be323..270ad290 100644 --- a/OpenImis.Modules/LoginModule/Models/Language.cs +++ b/OpenImis.ModulesV2/LoginModule/Models/Language.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.Modules.LoginModule.Models +namespace OpenImis.ModulesV2.LoginModule.Models { public enum Language { diff --git a/OpenImis.ModulesV2/LoginModule/Models/LoginModel.cs b/OpenImis.ModulesV2/LoginModule/Models/LoginModel.cs new file mode 100644 index 00000000..88f02499 --- /dev/null +++ b/OpenImis.ModulesV2/LoginModule/Models/LoginModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.LoginModule.Models +{ + public class LoginModel + { + public string UserName { get; set; } + public string Password { get; set; } + } +} diff --git a/OpenImis.ModulesV2/LoginModule/Models/UserData.cs b/OpenImis.ModulesV2/LoginModule/Models/UserData.cs new file mode 100644 index 00000000..f1a78eb4 --- /dev/null +++ b/OpenImis.ModulesV2/LoginModule/Models/UserData.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.LoginModule.Models +{ + public class UserData + { + public string UserID { get; set; } + public string LoginName { get; set; } + public string PrivateKey { get; set; } + public string StoredPassword { get; set; } + public List Rights { get; set; } + } +} diff --git a/OpenImis.ModulesV2/LoginModule/Models/UserLogin.cs b/OpenImis.ModulesV2/LoginModule/Models/UserLogin.cs new file mode 100644 index 00000000..772b801d --- /dev/null +++ b/OpenImis.ModulesV2/LoginModule/Models/UserLogin.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.ModulesV2.LoginModule.Models +{ + public class UserLogin + { + [Required] + public string UserID { get; set; } + [Required] + [MaxLength(15)] + public string Password { get; set; } + } +} diff --git a/OpenImis.ModulesV2/LoginModule/Models/ValidateCredentialsResponse.cs b/OpenImis.ModulesV2/LoginModule/Models/ValidateCredentialsResponse.cs new file mode 100644 index 00000000..6a10829f --- /dev/null +++ b/OpenImis.ModulesV2/LoginModule/Models/ValidateCredentialsResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.LoginModule.Models +{ + public class ValidateCredentialsResponse + { + public bool ErrorOccured { get; set; } + public bool success { get; set; } + } +} diff --git a/OpenImis.ModulesV2/LoginModule/Repositories/ILoginRepository.cs b/OpenImis.ModulesV2/LoginModule/Repositories/ILoginRepository.cs new file mode 100644 index 00000000..84cd8062 --- /dev/null +++ b/OpenImis.ModulesV2/LoginModule/Repositories/ILoginRepository.cs @@ -0,0 +1,14 @@ +using OpenImis.ModulesV2.LoginModule.Models; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; + +namespace OpenImis.ModulesV2.LoginModule.Repositories +{ + public interface ILoginRepository + { + UserData GetById(int userId); + List FindUserByName(string UserName); + } +} diff --git a/OpenImis.ModulesV2/LoginModule/Repositories/LoginRepository.cs b/OpenImis.ModulesV2/LoginModule/Repositories/LoginRepository.cs new file mode 100644 index 00000000..f3d1ada7 --- /dev/null +++ b/OpenImis.ModulesV2/LoginModule/Repositories/LoginRepository.cs @@ -0,0 +1,65 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.LoginModule.Models; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenImis.ModulesV2.LoginModule.Repositories +{ + public class LoginRepository : ILoginRepository + { + private IConfiguration Configuration; + + public LoginRepository(IConfiguration configuration) + { + Configuration = configuration; + } + + public UserData GetById(int userId) + { + UserData user; + using (var imisContext = new ImisDB()) + { + user = imisContext.TblUsers.Where(u => u.UserId == userId).Select(x => new UserData() + { + UserID = x.UserId.ToString(), + LoginName = x.LoginName, + PrivateKey = x.PrivateKey, + StoredPassword = x.StoredPassword + }) + .FirstOrDefault(); + } + + return user; + } + + public List FindUserByName(string UserName) + { + List response = new List(); + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.TblUsers + .Where(u => u.LoginName == UserName && u.ValidityTo == null) + .Select(x => new UserData() + { + UserID = Convert.ToString(x.UserId), + LoginName = Convert.ToString(x.LoginName), + PrivateKey = Convert.ToString(x.PrivateKey), + StoredPassword = Convert.ToString(x.StoredPassword) + }) + .ToList(); + } + + return response; + } + catch (Exception e) + { + throw e; + } + } + } +} diff --git a/OpenImis.ModulesV2/OpenImis.ModulesV2.csproj b/OpenImis.ModulesV2/OpenImis.ModulesV2.csproj new file mode 100644 index 00000000..b83519ca --- /dev/null +++ b/OpenImis.ModulesV2/OpenImis.ModulesV2.csproj @@ -0,0 +1,16 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + diff --git a/OpenImis.ModulesV2/PaymentModule/IPaymentModule.cs b/OpenImis.ModulesV2/PaymentModule/IPaymentModule.cs new file mode 100644 index 00000000..4c5e71fd --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/IPaymentModule.cs @@ -0,0 +1,11 @@ +using OpenImis.ModulesV2.PaymentModule.Logic; +using System; + +namespace OpenImis.ModulesV2.PaymentModule +{ + public interface IPaymentModule + { + IPaymentLogic GetPaymentLogic(); + IPaymentModule SetPaymentLogic(IPaymentLogic paymentLogic); + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Logic/IPaymentLogic.cs b/OpenImis.ModulesV2/PaymentModule/Logic/IPaymentLogic.cs new file mode 100644 index 00000000..f19af037 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Logic/IPaymentLogic.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace OpenImis.ModulesV2.PaymentModule.Logic +{ + public interface IPaymentLogic + { + + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Logic/PaymentLogic.cs b/OpenImis.ModulesV2/PaymentModule/Logic/PaymentLogic.cs new file mode 100644 index 00000000..bb0bd7fc --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Logic/PaymentLogic.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; + +namespace OpenImis.ModulesV2.PaymentModule.Logic +{ + public class PaymentLogic : IPaymentLogic + { + private IConfiguration _configuration; + + public PaymentLogic(IConfiguration configuration) + { + _configuration = configuration; + } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/PaymentModule.cs b/OpenImis.ModulesV2/PaymentModule/PaymentModule.cs new file mode 100644 index 00000000..2daabbfa --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/PaymentModule.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.PaymentModule.Logic; + +namespace OpenImis.ModulesV2.PaymentModule +{ + public class PaymentModule : IPaymentModule + { + private IConfiguration _configuration; + private IPaymentLogic _paymentLogic; + + public PaymentModule(IConfiguration configuration) + { + _configuration = configuration; + } + + public IPaymentLogic GetPaymentLogic() + { + if (_paymentLogic == null) + { + _paymentLogic = new PaymentLogic(_configuration); + } + return _paymentLogic; + } + + public IPaymentModule SetPaymentLogic(IPaymentLogic paymentLogic) + { + _paymentLogic = paymentLogic; + return this; + } + } +} diff --git a/OpenImis.ModulesV2/Utils/LinqExtensions.cs b/OpenImis.ModulesV2/Utils/LinqExtensions.cs new file mode 100644 index 00000000..3531fa0a --- /dev/null +++ b/OpenImis.ModulesV2/Utils/LinqExtensions.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenImis.ModulesV2.Utils +{ + static public class LinqExtensions + { + public static IEnumerable Page(this IEnumerable en, int pageSize, int page) + { + return en.Skip(page * pageSize).Take(pageSize); + } + + public static IQueryable Page(this IQueryable en, int pageSize, int page) + { + return en.Skip(page * pageSize).Take(pageSize); + } + + static public IEnumerable Descendants(this IEnumerable source, Func> DescendBy) + { + foreach (T value in source) + { + yield return value; + + foreach (T child in DescendBy(value).Descendants(DescendBy)) + { + yield return child; + } + } + } + + public static IEnumerable Traverse(this IEnumerable items, Func> childSelector) + { + var stack = new Stack(items); + while (stack.Any()) + { + var next = stack.Pop(); + yield return next; + foreach (var child in childSelector(next)) + stack.Push(child); + } + } + } +} diff --git a/OpenImis.ModulesV2/Utils/Models/PagerModel.cs b/OpenImis.ModulesV2/Utils/Models/PagerModel.cs new file mode 100644 index 00000000..4eaba9bc --- /dev/null +++ b/OpenImis.ModulesV2/Utils/Models/PagerModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.Utils.Models +{ + /// + /// This class allows to add pagination information to the responses getting list of Entities + /// + /// TODO: think if there should be a string NextPage field with URL for next page (same for PreviousPage) + public class PagerModel + { + public int CurrentPage { get; set; } + public int ResultsPerPage { get; set; } + public int TotalResults { get; set; } + public int TotalPages { get; set; } + } +} diff --git a/OpenImis.ModulesV2/Utils/TypeCast.cs b/OpenImis.ModulesV2/Utils/TypeCast.cs new file mode 100644 index 00000000..ba281e2a --- /dev/null +++ b/OpenImis.ModulesV2/Utils/TypeCast.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace OpenImis.ModulesV2.Utils +{ + public static class TypeCast + { + public static T Cast(Object parentInstance) + { + T result = default(T); + //try + //{ + var serializedParent = JsonConvert.SerializeObject(parentInstance); + result = JsonConvert.DeserializeObject(serializedParent); + //} + //catch (Exception ex) + //{ + // return new T(); + //} + return result; + } + + public static T GetValue(object value) + { + if (value == null || value == DBNull.Value) + return default(T); + else + return (T)value; + } + } +} diff --git a/OpenImis.RestApi/Controllers/ClaimsControllerV1.cs b/OpenImis.RestApi/Controllers/ClaimsControllerV1.cs index 542c962e..ffe45c4f 100644 --- a/OpenImis.RestApi/Controllers/ClaimsControllerV1.cs +++ b/OpenImis.RestApi/Controllers/ClaimsControllerV1.cs @@ -1,14 +1,9 @@ using System; -using System.Collections.Generic; -using System.Diagnostics; using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using OpenImis.Modules; -using OpenImis.Modules.ClaimModule.Models; +using OpenImis.ModulesV1; +using OpenImis.ModulesV1.ClaimModule.Models; using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers @@ -16,7 +11,6 @@ namespace OpenImis.RestApi.Controllers [ApiVersion("1")] [Route("api/")] [ApiController] - [EnableCors("AllowSpecificOrigin")] public class ClaimsControllerV1 : Controller { private readonly IImisModules _imisModules; diff --git a/OpenImis.RestApi/Controllers/ContributionControllerV1.cs b/OpenImis.RestApi/Controllers/ContributionControllerV1.cs index 28c44353..b30b965c 100644 --- a/OpenImis.RestApi/Controllers/ContributionControllerV1.cs +++ b/OpenImis.RestApi/Controllers/ContributionControllerV1.cs @@ -1,14 +1,11 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using OpenImis.Modules; -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1; +using OpenImis.ModulesV1.InsureeModule.Models; using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers diff --git a/OpenImis.RestApi/Controllers/CoverageControllerV1.cs b/OpenImis.RestApi/Controllers/CoverageControllerV1.cs index d718091e..2fe74a14 100644 --- a/OpenImis.RestApi/Controllers/CoverageControllerV1.cs +++ b/OpenImis.RestApi/Controllers/CoverageControllerV1.cs @@ -1,18 +1,14 @@ using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Data.SqlClient; -using System.Diagnostics; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; -using OpenImis.Modules; -using OpenImis.Modules.CoverageModule.Helpers; -using OpenImis.Modules.CoverageModule.Models; -using OpenImis.Modules.Helpers.Validators; +using OpenImis.ModulesV1.CoverageModule.Helpers; +using OpenImis.ModulesV1.CoverageModule.Models; using OpenImis.RestApi.Security; +using OpenImis.ModulesV1; +using OpenImis.ModulesV1.Helpers.Validators; namespace OpenImis.RestApi.Controllers { @@ -20,7 +16,6 @@ namespace OpenImis.RestApi.Controllers [Authorize] [Route("api/")] [ApiController] - [EnableCors("AllowSpecificOrigin")] public class CoverageControllerV1 : Controller { private readonly IImisModules _imisModules; diff --git a/OpenImis.RestApi/Controllers/FamilyControllerV1.cs b/OpenImis.RestApi/Controllers/FamilyControllerV1.cs index e0c8d4f2..bb93fe74 100644 --- a/OpenImis.RestApi/Controllers/FamilyControllerV1.cs +++ b/OpenImis.RestApi/Controllers/FamilyControllerV1.cs @@ -1,19 +1,14 @@ using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Diagnostics; using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; -using OpenImis.Modules; -using OpenImis.Modules.InsureeModule.Helpers; -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1; +using OpenImis.ModulesV1.InsureeModule.Helpers; +using OpenImis.ModulesV1.InsureeModule.Models; using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers @@ -31,7 +26,7 @@ public FamilyControllerV1(IImisModules imisModules) _imisModules = imisModules; } - [HasRights(Rights.FamilySearch)] + //[HasRights(Rights.FamilySearch)] [HttpGet] [Route("Families/Get_Family")] public IActionResult Get(string insureeNumber) diff --git a/OpenImis.RestApi/Controllers/LoginController.cs b/OpenImis.RestApi/Controllers/LoginControllerV1.cs similarity index 91% rename from OpenImis.RestApi/Controllers/LoginController.cs rename to OpenImis.RestApi/Controllers/LoginControllerV1.cs index 20454589..85092b92 100644 --- a/OpenImis.RestApi/Controllers/LoginController.cs +++ b/OpenImis.RestApi/Controllers/LoginControllerV1.cs @@ -1,31 +1,30 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IdentityModel.Tokens.Jwt; using System.Linq; using System.Security.Claims; using System.Text; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.IdentityModel.Tokens; -using OpenImis.Modules; -using OpenImis.Modules.LoginModule.Models; +using OpenImis.ModulesV1; +using OpenImis.ModulesV1.LoginModule.Models; namespace OpenImis.RestApi.Controllers { - [ApiVersionNeutral] + [ApiVersion("1")] [Authorize] [ApiController] [EnableCors("AllowSpecificOrigin")] - public class LoginController : Controller + public class LoginControllerV1 : Controller { private readonly IConfiguration _configuration; private readonly IImisModules _imisModules; - public LoginController(IConfiguration configuration, IImisModules imisModules) + public LoginControllerV1(IConfiguration configuration, IImisModules imisModules) { _configuration = configuration; _imisModules = imisModules; diff --git a/OpenImis.RestApi/Controllers/LoginControllerV2.cs b/OpenImis.RestApi/Controllers/LoginControllerV2.cs new file mode 100644 index 00000000..204f73b7 --- /dev/null +++ b/OpenImis.RestApi/Controllers/LoginControllerV2.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IdentityModel.Tokens.Jwt; +using System.Linq; +using System.Security.Claims; +using System.Text; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Cors; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Tokens; +using OpenImis.ModulesV2; +using OpenImis.ModulesV2.LoginModule.Models; + +namespace OpenImis.RestApi.Controllers +{ + [ApiVersion("2")] + [Authorize] + [ApiController] + [EnableCors("AllowSpecificOrigin")] + public class LoginControllerV2 : Controller + { + private readonly IConfiguration _configuration; + private readonly IImisModules _imisModules; + + public LoginControllerV2(IConfiguration configuration, IImisModules imisModules) + { + _configuration = configuration; + _imisModules = imisModules; + } + + [AllowAnonymous] + [HttpPost] + [Route("login")] + public IActionResult Index([FromBody]LoginModel model) + { + var user = _imisModules.GetLoginModule().GetLoginLogic().FindUser(model.UserName, model.Password); + + if (user != null) + { + DateTime expirationDate = DateTime.Now.AddDays(double.Parse(_configuration["JwtExpireDays"])); + + List claims = new List() + { + new Claim("UserId", user.UserID) + }; + + var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(user.PrivateKey)); + var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); + + var token = new JwtSecurityToken( + issuer: _configuration["JwtIssuer"], + audience: _configuration["JwtIssuer"], + claims: claims, + expires: expirationDate, + signingCredentials: creds); + + return Ok(new + { + access_token = new JwtSecurityTokenHandler().WriteToken(token), + expires_on = expirationDate + }); + } + + return Unauthorized(); + } + + [AllowAnonymous] + [HttpPost] + [Route("api/Validate/Credentials")] + public virtual IActionResult Validate_Credentials([FromBody]UserLogin userlogin) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + ValidateCredentialsResponse response = new ValidateCredentialsResponse(); + + try + { + var user = _imisModules.GetLoginModule().GetLoginLogic().FindUser(userlogin.UserID, userlogin.Password); + + if (user != null) + { + response.success = true; + response.ErrorOccured = false; + } + else + { + throw new Exception(); + } + } + catch (Exception) + { + response.success = false; + response.ErrorOccured = true; + } + + return Json(response); + } + } +} \ No newline at end of file diff --git a/OpenImis.RestApi/Controllers/PaymentControllerV1.cs b/OpenImis.RestApi/Controllers/PaymentControllerV1.cs index 3bd2ac55..0220355a 100644 --- a/OpenImis.RestApi/Controllers/PaymentControllerV1.cs +++ b/OpenImis.RestApi/Controllers/PaymentControllerV1.cs @@ -7,10 +7,10 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; -using OpenImis.Modules; -using OpenImis.Modules.PaymentModule.Helpers.Extensions; -using OpenImis.Modules.PaymentModule.Models; -using OpenImis.Modules.PaymentModule.Models.Response; +using OpenImis.ModulesV1; +using OpenImis.ModulesV1.PaymentModule.Helpers.Extensions; +using OpenImis.ModulesV1.PaymentModule.Models; +using OpenImis.ModulesV1.PaymentModule.Models.Response; using OpenImis.RestApi.Security; using Rights = OpenImis.RestApi.Security.Rights; diff --git a/OpenImis.RestApi/Controllers/PolicyControllerV1.cs b/OpenImis.RestApi/Controllers/PolicyControllerV1.cs index efa2dc48..3a2db952 100644 --- a/OpenImis.RestApi/Controllers/PolicyControllerV1.cs +++ b/OpenImis.RestApi/Controllers/PolicyControllerV1.cs @@ -4,8 +4,8 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; -using OpenImis.Modules; -using OpenImis.Modules.InsureeModule.Models; +using OpenImis.ModulesV1; +using OpenImis.ModulesV1.InsureeModule.Models; using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers diff --git a/OpenImis.RestApi/Escape/Sms/Headers.cs b/OpenImis.RestApi/Escape/Sms/Headers.cs index 68a01bb4..53d8479e 100644 --- a/OpenImis.RestApi/Escape/Sms/Headers.cs +++ b/OpenImis.RestApi/Escape/Sms/Headers.cs @@ -6,7 +6,7 @@ using System.Security.Cryptography; using System.Threading.Tasks; -namespace ImisRestApi.Chanels.Sms +namespace OpenImis.RestApi.Escape.Sms { public class Headers { diff --git a/OpenImis.RestApi/Protocol/GetMasterDataResponse.cs b/OpenImis.RestApi/Protocol/GetMasterDataResponse.cs deleted file mode 100644 index 307545c0..00000000 --- a/OpenImis.RestApi/Protocol/GetMasterDataResponse.cs +++ /dev/null @@ -1,21 +0,0 @@ -using OpenImis.Modules.MasterDataManagementModule.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace OpenImis.RestApi.Protocol -{ - public class GetMasterDataResponse - { - public LocationModel[] Locations { get; set; } - public FamilyTypeModel[] FamilyTypes { get; set; } - public ConfirmationTypeModel[] ConfirmationTypes { get; set; } - public EducationLevelModel[] EducationLevels { get; set; } - public GenderTypeModel[] GenderTypes { get; set; } - public RelationTypeModel[] RelationTypes { get; set; } - public ProfessionTypeModel[] ProfessionTypes { get; set; } - public IdentificationTypeModel[] IdentificationTypes { get; set; } - - } -} diff --git a/OpenImis.RestApi/Protocol/LoginModels/LoginBadRequestModel.cs b/OpenImis.RestApi/Protocol/LoginModels/LoginBadRequestModel.cs index 0a796947..3724baa1 100644 --- a/OpenImis.RestApi/Protocol/LoginModels/LoginBadRequestModel.cs +++ b/OpenImis.RestApi/Protocol/LoginModels/LoginBadRequestModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Threading.Tasks; -namespace OpenImis.RestApi.Protocol.LoginModel +namespace OpenImis.RestApi.Protocol.LoginModels { /// /// Error messages for Login Bad Request diff --git a/OpenImis.RestApi/Protocol/LoginModels/LoginRequestModel.cs b/OpenImis.RestApi/Protocol/LoginModels/LoginRequestModel.cs index 873e98d7..b7df47e8 100644 --- a/OpenImis.RestApi/Protocol/LoginModels/LoginRequestModel.cs +++ b/OpenImis.RestApi/Protocol/LoginModels/LoginRequestModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Threading.Tasks; -namespace OpenImis.RestApi.Protocol.LoginModel +namespace OpenImis.RestApi.Protocol.LoginModels { /// /// This class serves as a parameter class for the Login call diff --git a/OpenImis.RestApi/Protocol/LoginModels/LoginResponseModel.cs b/OpenImis.RestApi/Protocol/LoginModels/LoginResponseModel.cs index 1fafe8c0..1aabb024 100644 --- a/OpenImis.RestApi/Protocol/LoginModels/LoginResponseModel.cs +++ b/OpenImis.RestApi/Protocol/LoginModels/LoginResponseModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Threading.Tasks; -namespace OpenImis.RestApi.Protocol.LoginModel +namespace OpenImis.RestApi.Protocol.LoginModels { /// /// This class serves as a parameter class for the Login call diff --git a/OpenImis.RestApi/Security/AuthorizationPolicyProvider.cs b/OpenImis.RestApi/Security/AuthorizationPolicyProvider.cs deleted file mode 100644 index abf1cb03..00000000 --- a/OpenImis.RestApi/Security/AuthorizationPolicyProvider.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace OpenImis.RestApi.Security -{ - public class AuthorizationPolicyProvider : DefaultAuthorizationPolicyProvider - { - private readonly AuthorizationOptions _options; - private readonly IConfiguration _configuration; - - public AuthorizationPolicyProvider(IOptions options, IConfiguration configuration) : base(options) - { - _options = options.Value; - _configuration = configuration; - } - - public override async Task GetPolicyAsync(string policyName) - { - // Check static policies first - var policy = await base.GetPolicyAsync(policyName); - - if (policy == null) - { - policy = new AuthorizationPolicyBuilder() - .AddRequirements(new HasAuthorityRequirement(policyName, _configuration["JwtIssuer"])) - .Build(); - - // Add policy to the AuthorizationOptions, so we don't have to re-create it each time - _options.AddPolicy(policyName, policy); - } - - return policy; - } - } -} diff --git a/OpenImis.RestApi/Security/HasAuthorityHandler.cs b/OpenImis.RestApi/Security/HasAuthorityHandler.cs deleted file mode 100644 index ab505a99..00000000 --- a/OpenImis.RestApi/Security/HasAuthorityHandler.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Microsoft.AspNetCore.Authorization; -using OpenImis.Modules; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; - -namespace OpenImis.RestApi.Security -{ - public class HasAuthorityHandler : AuthorizationHandler - { - IImisModules _imisModules; - - public HasAuthorityHandler(IImisModules imisModules) - { - _imisModules = imisModules; - } - - protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasAuthorityRequirement requirement) - { - // If user does not have the scope claim, get out of here - if (!context.User.HasClaim(c => c.Type == ClaimTypes.Name && c.Issuer == requirement.Issuer)) - return Task.CompletedTask; - - // Split the scopes string into an array - //var scopes = context.User.FindFirst(c => c.Type == ClaimTypes.Name && c.Issuer == requirement.Issuer).Value.Split(' '); - var username = context.User.FindFirst(claim => claim.Type == ClaimTypes.Name).Value; - var scopes = _imisModules.GetUserModule().GetUserController().GetByUsername(username).GetRolesStringArray(); - - // Succeed if the scope array contains the required scope - if (scopes.Any(s => s == requirement.Authority)) - context.Succeed(requirement); - - return Task.CompletedTask; - } - } -} diff --git a/OpenImis.RestApi/Security/HasAuthorityRequirement.cs b/OpenImis.RestApi/Security/HasAuthorityRequirement.cs deleted file mode 100644 index b9afb92d..00000000 --- a/OpenImis.RestApi/Security/HasAuthorityRequirement.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.AspNetCore.Authorization; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace OpenImis.RestApi.Security -{ - public class HasAuthorityRequirement : IAuthorizationRequirement - { - public string Issuer { get; } - public string Authority { get; } - - public HasAuthorityRequirement(string authority, string issuer) - { - Authority = authority ?? throw new ArgumentNullException(nameof(authority)); - Issuer = issuer ?? throw new ArgumentNullException(nameof(issuer)); - } - } -} diff --git a/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs b/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs index e4189b8d..ac6c2a9d 100644 --- a/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs +++ b/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs @@ -1,5 +1,4 @@ -using OpenImis.Modules; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.IdentityModel.Tokens; using System; using System.Collections.Generic; @@ -7,9 +6,8 @@ using System.Linq; using System.Security.Claims; using System.Text; -using OpenImis.Modules.UserModule.Entities; -using OpenImis.Modules.LoginModule.Models; using System.Diagnostics; +using Microsoft.AspNetCore.Http; namespace OpenImis.RestApi.Security { @@ -20,12 +18,19 @@ public class IMISJwtSecurityTokenHandler : ISecurityTokenValidator { private int _maxTokenSizeInBytes = TokenValidationParameters.DefaultMaximumTokenSizeInBytes; private readonly JwtSecurityTokenHandler _tokenHandler; - private readonly IImisModules _imisModules; - - public IMISJwtSecurityTokenHandler(IImisModules imisModules) + + private readonly ModulesV1.IImisModules _imisModulesV1; + private readonly ModulesV2.IImisModules _imisModulesV2; + + private readonly IHttpContextAccessor _httpContextAccessor; + + public IMISJwtSecurityTokenHandler(ModulesV1.IImisModules imisModulesV1, ModulesV2.IImisModules imisModulesV2, IHttpContextAccessor httpContextAccessor) { _tokenHandler = new JwtSecurityTokenHandler(); - _imisModules = imisModules; + _httpContextAccessor = httpContextAccessor; + + _imisModulesV1 = imisModulesV1; + _imisModulesV2 = imisModulesV2; } public bool CanValidateToken @@ -69,11 +74,15 @@ public ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParame var tokenS = handler.ReadToken(securityToken) as JwtSecurityToken; int userId = Convert.ToInt32(tokenS.Claims.Where(w => w.Type == "UserId").Select(x => x.Value).FirstOrDefault()); - UserData user = _imisModules.GetLoginModule().GetLoginLogic().GetById(userId); + string apiVersion = _httpContextAccessor.HttpContext.Request.Headers.Where(x => x.Key == "api-version").Select(s => s.Value).FirstOrDefault(); + + UserData user; + + if (apiVersion.StartsWith("1")) user = (UserData)_imisModulesV1.GetLoginModule().GetLoginLogic().GetById(userId); + else user = (UserData)_imisModulesV2.GetLoginModule().GetLoginLogic().GetById(userId); if (user != null) { - TokenValidationParameters tokenValidationParameters = new TokenValidationParameters { ValidateIssuer = validationParameters.ValidateIssuer, diff --git a/OpenImis.RestApi/Security/UserData.cs b/OpenImis.RestApi/Security/UserData.cs new file mode 100644 index 00000000..4a2f72ab --- /dev/null +++ b/OpenImis.RestApi/Security/UserData.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using OpenImis.ModulesV1.LoginModule.Models; + +namespace OpenImis.RestApi.Security +{ + public class UserData + { + public string UserID { get; set; } + public string LoginName { get; set; } + public string PrivateKey { get; set; } + public string StoredPassword { get; set; } + public List Rights { get; set; } + + public static explicit operator UserData(ModulesV1.LoginModule.Models.UserData v) + { + return new UserData() + { + UserID = v.UserID, + LoginName = v.LoginName, + PrivateKey = v.PrivateKey + }; + } + + public static explicit operator UserData(ModulesV2.LoginModule.Models.UserData v) + { + return new UserData() + { + UserID = v.UserID, + LoginName = v.LoginName, + PrivateKey = v.PrivateKey + }; + } + } +} diff --git a/OpenImis.RestApi/Startup.cs b/OpenImis.RestApi/Startup.cs index accb01a8..8869c9c8 100644 --- a/OpenImis.RestApi/Startup.cs +++ b/OpenImis.RestApi/Startup.cs @@ -1,23 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using OpenImis.Modules; using Microsoft.AspNetCore.Mvc; using Microsoft.IdentityModel.Tokens; using OpenImis.RestApi.Security; -using Swashbuckle.AspNetCore.SwaggerGen; using OpenImis.RestApi.Docs; using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.Extensions.Logging; -using Microsoft.AspNetCore.Authorization; +using OpenImis.RestApi.Controllers; +using OpenImis.ModulesV1; +using OpenImis.ModulesV2; +using Microsoft.AspNetCore.Http; namespace OpenImis.RestApi { @@ -35,7 +31,10 @@ public void ConfigureServices(IServiceCollection services) // Add the DbContext //services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("IMISDatabase"))); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + + services.AddSingleton(); // Add the authentication scheme with the custom validator services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) @@ -52,25 +51,20 @@ public void ConfigureServices(IServiceCollection services) options.SecurityTokenValidators.Clear(); //below line adds the custom validator class - options.SecurityTokenValidators.Add(new IMISJwtSecurityTokenHandler(services.BuildServiceProvider().GetService())); + options.SecurityTokenValidators.Add(new IMISJwtSecurityTokenHandler( + services.BuildServiceProvider().GetService(), + services.BuildServiceProvider().GetService(), + services.BuildServiceProvider().GetService())); }); services.AddAuthorization(); - //(options => - //{ - // options.AddPolicy("MedicalOfficer", policy => policy.Requirements.Add(new HasAuthorityRequirement("MedicalOfficer", Configuration["JwtIssuer"]))); - // options.AddPolicy("EnrollmentOfficer", policy => policy.Requirements.Add(new HasAuthorityRequirement("EnrollmentOfficer", Configuration["JwtIssuer"]))); - //}); - - // register the scope authorization handler - services.AddSingleton(); - services.AddSingleton(); services.AddMvc(options => { options.AllowCombiningAuthorizeFilters = false; }) - .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) + .AddControllersAsServices(); services.AddApiVersioning(o => { diff --git a/OpenImis.RestApi/openImisModules.json b/OpenImis.RestApi/openImisModules.json index b3183cf2..1dc493ef 100644 --- a/OpenImis.RestApi/openImisModules.json +++ b/OpenImis.RestApi/openImisModules.json @@ -1,20 +1,44 @@ { - "ImisModules": { - "UserModule": { - "UserController": "OpenImis.Modules.UserModule.Controllers.UserController" - }, - "InsureeManagementModule": { - "FamilyLogic": "OpenImis.Modules.InsureeManagementModule.Logic.FamilyLogic", - "InsureeLogic": "OpenImis.Modules.InsureeManagementModule.Logic.InsureeLogic" - }, - "MasterDataManagementModule": { - "LocationLogic": "OpenImis.Modules.MasterDataManagementModule.Logic.LocationLogic", - "FamilyTypeLogic": "OpenImis.Modules.MasterDataManagementModule.Logic.FamilyTypeLogic", - "ConfirmationTypeLogic": "OpenImis.Modules.MasterDataManagementModule.Logic.ConfirmationTypeLogic", - "EducationLevelLogic": "OpenImis.Modules.MasterDataManagementModule.Logic.EducationLevelLogic", - "GenderTypeLogic": "OpenImis.Modules.MasterDataManagementModule.Logic.GenderTypeLogic", - "ProfessionTypeLogic": "OpenImis.Modules.MasterDataManagementModule.Logic.ProfessionTypeLogic", - "IdentificationTypeLogic": "OpenImis.Modules.MasterDataManagementModule.Logic.IdentificationTypeLogic" - } - } + "ImisModules": [ + { + "Version": "1", + "LoginModule": { + "LoginLogic": "OpenImis.ModulesV1.LoginModule.Logic.LoginLogic" + }, + "ClaimModule": { + "ClaimLogic": "OpenImis.ModulesV1.ClaimModule.Logic.ClaimLogic" + }, + "CoverageModule": { + "CoverageLogic": "OpenImis.ModulesV1.CoverageModule.Logic.CoverageLogic" + }, + "InsureeModule": { + "FamilyLogic": "OpenImis.ModulesV1.InsureeModule.Logic.FamilyLogic", + "PolicyLogic": "OpenImis.ModulesV1.InsureeModule.Logic.PolicyLogic", + "ContributionLogic": "OpenImis.ModulesV1.InsureeModule.Logic.ContributionLogic" + }, + "PaymentModule": { + "PaymentLogic": "OpenImis.ModulesV1.PaymentModule.Logic.PaymentLogic" + } + }, + { + "Version": "2", + "LoginModule": { + "LoginLogic": "OpenImis.ModulesV2.LoginModule.Logic.LoginLogic" + }, + "ClaimModule": { + "ClaimLogic": "OpenImis.ModulesV2.ClaimModule.Logic.ClaimLogic" + }, + "CoverageModule": { + "CoverageLogic": "OpenImis.ModulesV2.CoverageModule.Logic.CoverageLogic" + }, + "InsureeModule": { + "FamilyLogic": "OpenImis.ModulesV2.InsureeModule.Logic.FamilyLogic", + "PolicyLogic": "OpenImis.ModulesV2.InsureeModule.Logic.PolicyLogic", + "ContributionLogic": "OpenImis.ModulesV2.InsureeModule.Logic.ContributionLogic" + }, + "PaymentModule": { + "PaymentLogic": "OpenImis.ModulesV2.PaymentModule.Logic.PaymentLogic" + } + } + ] } From de599ee407aabc89be54ed65c7aeea795b9a870e Mon Sep 17 00:00:00 2001 From: bkaminski Date: Mon, 29 Jul 2019 09:32:42 +0200 Subject: [PATCH 20/86] OS-36: The structure of controllers has been improved --- .../{ClaimsControllerV1.cs => V1/ClaimsController.cs} | 6 +++--- .../ContributionController.cs} | 6 +++--- .../{CoverageControllerV1.cs => V1/CoverageController.cs} | 6 +++--- .../{FamilyControllerV1.cs => V1/FamilyController.cs} | 6 +++--- .../{LoginControllerV1.cs => V1/LoginController.cs} | 6 +++--- .../{PaymentControllerV1.cs => V1/PaymentController.cs} | 6 +++--- .../{PolicyControllerV1.cs => V1/PolicyController.cs} | 6 +++--- .../{LoginControllerV2.cs => V2/LoginController.cs} | 6 +++--- 8 files changed, 24 insertions(+), 24 deletions(-) rename OpenImis.RestApi/Controllers/{ClaimsControllerV1.cs => V1/ClaimsController.cs} (95%) rename OpenImis.RestApi/Controllers/{ContributionControllerV1.cs => V1/ContributionController.cs} (89%) rename OpenImis.RestApi/Controllers/{CoverageControllerV1.cs => V1/CoverageController.cs} (93%) rename OpenImis.RestApi/Controllers/{FamilyControllerV1.cs => V1/FamilyController.cs} (98%) rename OpenImis.RestApi/Controllers/{LoginControllerV1.cs => V1/LoginController.cs} (94%) rename OpenImis.RestApi/Controllers/{PaymentControllerV1.cs => V1/PaymentController.cs} (97%) rename OpenImis.RestApi/Controllers/{PolicyControllerV1.cs => V1/PolicyController.cs} (95%) rename OpenImis.RestApi/Controllers/{LoginControllerV2.cs => V2/LoginController.cs} (94%) diff --git a/OpenImis.RestApi/Controllers/ClaimsControllerV1.cs b/OpenImis.RestApi/Controllers/V1/ClaimsController.cs similarity index 95% rename from OpenImis.RestApi/Controllers/ClaimsControllerV1.cs rename to OpenImis.RestApi/Controllers/V1/ClaimsController.cs index ffe45c4f..d8b81e34 100644 --- a/OpenImis.RestApi/Controllers/ClaimsControllerV1.cs +++ b/OpenImis.RestApi/Controllers/V1/ClaimsController.cs @@ -6,15 +6,15 @@ using OpenImis.ModulesV1.ClaimModule.Models; using OpenImis.RestApi.Security; -namespace OpenImis.RestApi.Controllers +namespace OpenImis.RestApi.Controllers.V1 { [ApiVersion("1")] [Route("api/")] [ApiController] - public class ClaimsControllerV1 : Controller + public class ClaimsController : Controller { private readonly IImisModules _imisModules; - public ClaimsControllerV1(IImisModules imisModules) + public ClaimsController(IImisModules imisModules) { _imisModules = imisModules; } diff --git a/OpenImis.RestApi/Controllers/ContributionControllerV1.cs b/OpenImis.RestApi/Controllers/V1/ContributionController.cs similarity index 89% rename from OpenImis.RestApi/Controllers/ContributionControllerV1.cs rename to OpenImis.RestApi/Controllers/V1/ContributionController.cs index b30b965c..a929001a 100644 --- a/OpenImis.RestApi/Controllers/ContributionControllerV1.cs +++ b/OpenImis.RestApi/Controllers/V1/ContributionController.cs @@ -8,17 +8,17 @@ using OpenImis.ModulesV1.InsureeModule.Models; using OpenImis.RestApi.Security; -namespace OpenImis.RestApi.Controllers +namespace OpenImis.RestApi.Controllers.V1 { [ApiVersion("1")] [Authorize] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] - public class ContributionControllerV1 : Controller + public class ContributionController : Controller { private readonly IImisModules _imisModules; - public ContributionControllerV1(IImisModules imisModules) + public ContributionController(IImisModules imisModules) { _imisModules = imisModules; } diff --git a/OpenImis.RestApi/Controllers/CoverageControllerV1.cs b/OpenImis.RestApi/Controllers/V1/CoverageController.cs similarity index 93% rename from OpenImis.RestApi/Controllers/CoverageControllerV1.cs rename to OpenImis.RestApi/Controllers/V1/CoverageController.cs index 2fe74a14..e597d6a8 100644 --- a/OpenImis.RestApi/Controllers/CoverageControllerV1.cs +++ b/OpenImis.RestApi/Controllers/V1/CoverageController.cs @@ -10,16 +10,16 @@ using OpenImis.ModulesV1; using OpenImis.ModulesV1.Helpers.Validators; -namespace OpenImis.RestApi.Controllers +namespace OpenImis.RestApi.Controllers.V1 { [ApiVersion("1")] [Authorize] [Route("api/")] [ApiController] - public class CoverageControllerV1 : Controller + public class CoverageController : Controller { private readonly IImisModules _imisModules; - public CoverageControllerV1(IImisModules imisModules) + public CoverageController(IImisModules imisModules) { _imisModules = imisModules; } diff --git a/OpenImis.RestApi/Controllers/FamilyControllerV1.cs b/OpenImis.RestApi/Controllers/V1/FamilyController.cs similarity index 98% rename from OpenImis.RestApi/Controllers/FamilyControllerV1.cs rename to OpenImis.RestApi/Controllers/V1/FamilyController.cs index bb93fe74..80afa118 100644 --- a/OpenImis.RestApi/Controllers/FamilyControllerV1.cs +++ b/OpenImis.RestApi/Controllers/V1/FamilyController.cs @@ -11,17 +11,17 @@ using OpenImis.ModulesV1.InsureeModule.Models; using OpenImis.RestApi.Security; -namespace OpenImis.RestApi.Controllers +namespace OpenImis.RestApi.Controllers.V1 { [ApiVersion("1")] [Authorize] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] - public class FamilyControllerV1 : Controller + public class FamilyController : Controller { private readonly IImisModules _imisModules; - public FamilyControllerV1(IImisModules imisModules) + public FamilyController(IImisModules imisModules) { _imisModules = imisModules; } diff --git a/OpenImis.RestApi/Controllers/LoginControllerV1.cs b/OpenImis.RestApi/Controllers/V1/LoginController.cs similarity index 94% rename from OpenImis.RestApi/Controllers/LoginControllerV1.cs rename to OpenImis.RestApi/Controllers/V1/LoginController.cs index 85092b92..07ba1750 100644 --- a/OpenImis.RestApi/Controllers/LoginControllerV1.cs +++ b/OpenImis.RestApi/Controllers/V1/LoginController.cs @@ -13,18 +13,18 @@ using OpenImis.ModulesV1; using OpenImis.ModulesV1.LoginModule.Models; -namespace OpenImis.RestApi.Controllers +namespace OpenImis.RestApi.Controllers.V1 { [ApiVersion("1")] [Authorize] [ApiController] [EnableCors("AllowSpecificOrigin")] - public class LoginControllerV1 : Controller + public class LoginController : Controller { private readonly IConfiguration _configuration; private readonly IImisModules _imisModules; - public LoginControllerV1(IConfiguration configuration, IImisModules imisModules) + public LoginController(IConfiguration configuration, IImisModules imisModules) { _configuration = configuration; _imisModules = imisModules; diff --git a/OpenImis.RestApi/Controllers/PaymentControllerV1.cs b/OpenImis.RestApi/Controllers/V1/PaymentController.cs similarity index 97% rename from OpenImis.RestApi/Controllers/PaymentControllerV1.cs rename to OpenImis.RestApi/Controllers/V1/PaymentController.cs index 0220355a..8ca2d7a7 100644 --- a/OpenImis.RestApi/Controllers/PaymentControllerV1.cs +++ b/OpenImis.RestApi/Controllers/V1/PaymentController.cs @@ -14,19 +14,19 @@ using OpenImis.RestApi.Security; using Rights = OpenImis.RestApi.Security.Rights; -namespace OpenImis.RestApi.Controllers +namespace OpenImis.RestApi.Controllers.V1 { [ApiVersion("1")] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] - public class PaymentControllerV1 : Controller + public class PaymentController : Controller { private readonly IConfiguration _configuration; private readonly IImisModules _imisModules; public readonly IHostingEnvironment _hostingEnvironment; - public PaymentControllerV1(IConfiguration configuration, IHostingEnvironment hostingEnvironment, IImisModules imisModules) + public PaymentController(IConfiguration configuration, IHostingEnvironment hostingEnvironment, IImisModules imisModules) { _configuration = configuration; _hostingEnvironment = hostingEnvironment; diff --git a/OpenImis.RestApi/Controllers/PolicyControllerV1.cs b/OpenImis.RestApi/Controllers/V1/PolicyController.cs similarity index 95% rename from OpenImis.RestApi/Controllers/PolicyControllerV1.cs rename to OpenImis.RestApi/Controllers/V1/PolicyController.cs index 3a2db952..ec5426e2 100644 --- a/OpenImis.RestApi/Controllers/PolicyControllerV1.cs +++ b/OpenImis.RestApi/Controllers/V1/PolicyController.cs @@ -8,17 +8,17 @@ using OpenImis.ModulesV1.InsureeModule.Models; using OpenImis.RestApi.Security; -namespace OpenImis.RestApi.Controllers +namespace OpenImis.RestApi.Controllers.V1 { [ApiVersion("1")] [Authorize] [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] - public class PolicyControllerV1 : Controller + public class PolicyController : Controller { private readonly IImisModules _imisModules; - public PolicyControllerV1(IImisModules imisModules) + public PolicyController(IImisModules imisModules) { _imisModules = imisModules; } diff --git a/OpenImis.RestApi/Controllers/LoginControllerV2.cs b/OpenImis.RestApi/Controllers/V2/LoginController.cs similarity index 94% rename from OpenImis.RestApi/Controllers/LoginControllerV2.cs rename to OpenImis.RestApi/Controllers/V2/LoginController.cs index 204f73b7..00bd1004 100644 --- a/OpenImis.RestApi/Controllers/LoginControllerV2.cs +++ b/OpenImis.RestApi/Controllers/V2/LoginController.cs @@ -13,18 +13,18 @@ using OpenImis.ModulesV2; using OpenImis.ModulesV2.LoginModule.Models; -namespace OpenImis.RestApi.Controllers +namespace OpenImis.RestApi.Controllers.V2 { [ApiVersion("2")] [Authorize] [ApiController] [EnableCors("AllowSpecificOrigin")] - public class LoginControllerV2 : Controller + public class LoginController : Controller { private readonly IConfiguration _configuration; private readonly IImisModules _imisModules; - public LoginControllerV2(IConfiguration configuration, IImisModules imisModules) + public LoginController(IConfiguration configuration, IImisModules imisModules) { _configuration = configuration; _imisModules = imisModules; From b82bf57e77761c8f1a68dd01116629cabc39a4c3 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Mon, 29 Jul 2019 09:59:19 +0200 Subject: [PATCH 21/86] OS-36: Improved code for creating modules from configuration --- OpenImis.ModulesV1/ImisModules.cs | 36 +++++++++++++++-------------- OpenImis.ModulesV2/ImisModules.cs | 38 +++++++++++++++++-------------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/OpenImis.ModulesV1/ImisModules.cs b/OpenImis.ModulesV1/ImisModules.cs index f5085da1..a630feb1 100644 --- a/OpenImis.ModulesV1/ImisModules.cs +++ b/OpenImis.ModulesV1/ImisModules.cs @@ -10,8 +10,6 @@ using Microsoft.Extensions.DependencyInjection; using OpenImis.ModulesV1.Helpers; using System.Collections.Generic; -using Newtonsoft.Json; -using System.Diagnostics; using System.Linq; namespace OpenImis.ModulesV1 @@ -37,10 +35,10 @@ public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory, I } /// - /// Creates and returns the login module. + /// Creates and returns the login module version 1. /// /// - /// The Login module. + /// The Login module V1. /// public ILoginModule GetLoginModule() { @@ -143,21 +141,9 @@ private Type CreateTypeFromConfiguration(string moduleName, string sectionName, { Type type; - string part = ""; - Assembly assembly = Assembly.GetCallingAssembly(); - var listImisModules = _configuration.GetSection("ImisModules").Get>(); - - if (listImisModules.Where(v => v.Version == "1").Any(x => GetPropValue(x, moduleName) != null)) - { - object module = listImisModules.Where(v => v.Version == "1").Select(x => GetPropValue(x, moduleName)).FirstOrDefault(); - - if (GetPropValue(module, sectionName) != null) - { - part = GetPropValue(module, sectionName).ToString(); - } - } + string part = GetSectionName(moduleName, sectionName, "1"); type = assembly.GetType(part); @@ -175,6 +161,22 @@ private Type CreateTypeFromConfiguration(string moduleName, string sectionName, return type; } + public string GetSectionName(string moduleName, string sectionName, string apiVersion) + { + string part = ""; + + var listImisModules = _configuration.GetSection("ImisModules").Get>(); + + var module = listImisModules.Where(m => m.Version == apiVersion).Select(x => GetPropValue(x, moduleName)).FirstOrDefault(); + + if (GetPropValue(module, sectionName) != null) + { + part = GetPropValue(module, sectionName).ToString(); + } + + return part; + } + public static object GetPropValue(object src, string propName) { return src.GetType().GetProperty(propName).GetValue(src, null); diff --git a/OpenImis.ModulesV2/ImisModules.cs b/OpenImis.ModulesV2/ImisModules.cs index b3e37914..8b30f724 100644 --- a/OpenImis.ModulesV2/ImisModules.cs +++ b/OpenImis.ModulesV2/ImisModules.cs @@ -18,10 +18,10 @@ public class ImisModules : IImisModules { private ILoginModule loginModule; - private InsureeModule.IInsureeModule insureeModule; - private ClaimModule.IClaimModule claimModule; - private CoverageModule.ICoverageModule coverageModule; - private PaymentModule.IPaymentModule paymentModule; + private IInsureeModule insureeModule; + private IClaimModule claimModule; + private ICoverageModule coverageModule; + private IPaymentModule paymentModule; private readonly IConfiguration _configuration; private readonly ILogger _logger; @@ -141,21 +141,9 @@ private Type CreateTypeFromConfiguration(string moduleName, string sectionName, { Type type; - string part = ""; - Assembly assembly = Assembly.GetCallingAssembly(); - var listImisModules = _configuration.GetSection("ImisModules").Get>(); - - if (listImisModules.Where(v => v.Version == "2").Any(x => GetPropValue(x, moduleName) != null)) - { - object module = listImisModules.Where(v => v.Version == "2").Select(x => GetPropValue(x, moduleName)).FirstOrDefault(); - - if (GetPropValue(module, sectionName) != null) - { - part = GetPropValue(module, sectionName).ToString(); - } - } + string part = GetSectionName(moduleName, sectionName, "2"); type = assembly.GetType(part); @@ -173,6 +161,22 @@ private Type CreateTypeFromConfiguration(string moduleName, string sectionName, return type; } + public string GetSectionName(string moduleName, string sectionName, string apiVersion) + { + string part = ""; + + var listImisModules = _configuration.GetSection("ImisModules").Get>(); + + var module = listImisModules.Where(m => m.Version == apiVersion).Select(x => GetPropValue(x, moduleName)).FirstOrDefault(); + + if (GetPropValue(module, sectionName) != null) + { + part = GetPropValue(module, sectionName).ToString(); + } + + return part; + } + public static object GetPropValue(object src, string propName) { return src.GetType().GetProperty(propName).GetValue(src, null); From ac3cb819271d11177e99b54df1a59309ea59fd24 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Mon, 29 Jul 2019 13:28:01 +0200 Subject: [PATCH 22/86] OS-36: Added OpenImis.RestApi.csproj --- OpenImis.RestApi/OpenImis.RestApi.csproj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/OpenImis.RestApi/OpenImis.RestApi.csproj b/OpenImis.RestApi/OpenImis.RestApi.csproj index 873989b4..4be1c80e 100644 --- a/OpenImis.RestApi/OpenImis.RestApi.csproj +++ b/OpenImis.RestApi/OpenImis.RestApi.csproj @@ -36,14 +36,12 @@ - - @@ -71,7 +69,8 @@ - + + From e615d69182f6dde21209a51cc8ddb8bf6eb22e1a Mon Sep 17 00:00:00 2001 From: bkaminski Date: Mon, 29 Jul 2019 13:34:22 +0200 Subject: [PATCH 23/86] OS-36: Added ImisApi --- ImisRestApi.sln | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ImisRestApi.sln b/ImisRestApi.sln index 1ec6df48..7b309fb5 100644 --- a/ImisRestApi.sln +++ b/ImisRestApi.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27703.2026 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29102.190 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenImis.RestApi", "OpenImis.RestApi\OpenImis.RestApi.csproj", "{0F650C61-A020-4549-AC0C-C49F0334E2D7}" EndProject @@ -9,9 +9,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenImis.RestApi.Integratio EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenImis.Extensions.Configuration", "OpenImis.Extensions.Configuration\OpenImis.Extensions.Configuration.csproj", "{E2CEBBAF-6DF7-41E9-815D-9AD4CF90C844}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenImis.DB.SqlServer", "OpenImis.DB.SqlServer\OpenImis.DB.SqlServer.csproj", "{563662BC-9B77-46CA-AF68-4143A146601E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenImis.DB.SqlServer", "OpenImis.DB.SqlServer\OpenImis.DB.SqlServer.csproj", "{563662BC-9B77-46CA-AF68-4143A146601E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenImis.Modules", "OpenImis.Modules\OpenImis.Modules.csproj", "{F18EF622-6FC3-40A0-B58C-7A9F6B6018FC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenImis.ModulesV1", "OpenImis.ModulesV1\OpenImis.ModulesV1.csproj", "{F323C452-F4D9-4825-8954-30BE26A81874}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenImis.ModulesV2", "OpenImis.ModulesV2\OpenImis.ModulesV2.csproj", "{2AE88A62-30F2-4D13-8E71-6C1F8E6D5B61}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -35,10 +37,14 @@ Global {563662BC-9B77-46CA-AF68-4143A146601E}.Debug|Any CPU.Build.0 = Debug|Any CPU {563662BC-9B77-46CA-AF68-4143A146601E}.Release|Any CPU.ActiveCfg = Release|Any CPU {563662BC-9B77-46CA-AF68-4143A146601E}.Release|Any CPU.Build.0 = Release|Any CPU - {F18EF622-6FC3-40A0-B58C-7A9F6B6018FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F18EF622-6FC3-40A0-B58C-7A9F6B6018FC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F18EF622-6FC3-40A0-B58C-7A9F6B6018FC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F18EF622-6FC3-40A0-B58C-7A9F6B6018FC}.Release|Any CPU.Build.0 = Release|Any CPU + {F323C452-F4D9-4825-8954-30BE26A81874}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F323C452-F4D9-4825-8954-30BE26A81874}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F323C452-F4D9-4825-8954-30BE26A81874}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F323C452-F4D9-4825-8954-30BE26A81874}.Release|Any CPU.Build.0 = Release|Any CPU + {2AE88A62-30F2-4D13-8E71-6C1F8E6D5B61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2AE88A62-30F2-4D13-8E71-6C1F8E6D5B61}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2AE88A62-30F2-4D13-8E71-6C1F8E6D5B61}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2AE88A62-30F2-4D13-8E71-6C1F8E6D5B61}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From ece6520232349af8d6d5e1229d6c571e221833b7 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Mon, 29 Jul 2019 17:56:26 +0200 Subject: [PATCH 24/86] OS-36: Support for the latest API --- .../Security/IMISJwtSecurityTokenHandler.cs | 11 +++++++---- OpenImis.RestApi/Startup.cs | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs b/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs index ac6c2a9d..0360a131 100644 --- a/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs +++ b/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs @@ -23,14 +23,17 @@ public class IMISJwtSecurityTokenHandler : ISecurityTokenValidator private readonly ModulesV2.IImisModules _imisModulesV2; private readonly IHttpContextAccessor _httpContextAccessor; + private int _lastApiVersion; - public IMISJwtSecurityTokenHandler(ModulesV1.IImisModules imisModulesV1, ModulesV2.IImisModules imisModulesV2, IHttpContextAccessor httpContextAccessor) + public IMISJwtSecurityTokenHandler(ModulesV1.IImisModules imisModulesV1, ModulesV2.IImisModules imisModulesV2, IHttpContextAccessor httpContextAccessor, int lastApiVersion) { _tokenHandler = new JwtSecurityTokenHandler(); _httpContextAccessor = httpContextAccessor; _imisModulesV1 = imisModulesV1; _imisModulesV2 = imisModulesV2; + + _lastApiVersion = lastApiVersion; } public bool CanValidateToken @@ -77,9 +80,9 @@ public ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParame string apiVersion = _httpContextAccessor.HttpContext.Request.Headers.Where(x => x.Key == "api-version").Select(s => s.Value).FirstOrDefault(); UserData user; - - if (apiVersion.StartsWith("1")) user = (UserData)_imisModulesV1.GetLoginModule().GetLoginLogic().GetById(userId); - else user = (UserData)_imisModulesV2.GetLoginModule().GetLoginLogic().GetById(userId); + + if (apiVersion == null || apiVersion.StartsWith(_lastApiVersion.ToString())) user = (UserData)_imisModulesV2.GetLoginModule().GetLoginLogic().GetById(userId); + else user = (UserData)_imisModulesV1.GetLoginModule().GetLoginLogic().GetById(userId); if (user != null) { diff --git a/OpenImis.RestApi/Startup.cs b/OpenImis.RestApi/Startup.cs index 8869c9c8..eb2a9c7d 100644 --- a/OpenImis.RestApi/Startup.cs +++ b/OpenImis.RestApi/Startup.cs @@ -14,6 +14,8 @@ using OpenImis.ModulesV1; using OpenImis.ModulesV2; using Microsoft.AspNetCore.Http; +using OpenImis.ModulesV1.Helpers; +using System.Collections.Generic; namespace OpenImis.RestApi { @@ -28,8 +30,8 @@ public Startup(IConfiguration configuration) public void ConfigureServices(IServiceCollection services) { - // Add the DbContext - //services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("IMISDatabase"))); + var configImisModules = Configuration.GetSection("ImisModules").Get>(); + int lastApiVersion = int.Parse(configImisModules[configImisModules.Count - 1].Version); services.AddSingleton(); services.AddSingleton(); @@ -54,7 +56,8 @@ public void ConfigureServices(IServiceCollection services) options.SecurityTokenValidators.Add(new IMISJwtSecurityTokenHandler( services.BuildServiceProvider().GetService(), services.BuildServiceProvider().GetService(), - services.BuildServiceProvider().GetService())); + services.BuildServiceProvider().GetService(), + lastApiVersion)); }); services.AddAuthorization(); @@ -70,7 +73,7 @@ public void ConfigureServices(IServiceCollection services) { o.ReportApiVersions = true; o.AssumeDefaultVersionWhenUnspecified = true; - o.DefaultApiVersion = new ApiVersion(1, 0); + o.DefaultApiVersion = new ApiVersion(lastApiVersion, 0); o.ApiVersionReader = ApiVersionReader.Combine(new QueryStringApiVersionReader(), new HeaderApiVersionReader("api-version")); }); From d09fd37fa7f9381e719d01d3708296058774d901 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Tue, 30 Jul 2019 10:24:44 +0200 Subject: [PATCH 25/86] OS-36: Getting the latest version of the API --- OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs | 7 ++----- OpenImis.RestApi/Startup.cs | 7 ++++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs b/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs index 0360a131..8c890559 100644 --- a/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs +++ b/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs @@ -23,17 +23,14 @@ public class IMISJwtSecurityTokenHandler : ISecurityTokenValidator private readonly ModulesV2.IImisModules _imisModulesV2; private readonly IHttpContextAccessor _httpContextAccessor; - private int _lastApiVersion; - public IMISJwtSecurityTokenHandler(ModulesV1.IImisModules imisModulesV1, ModulesV2.IImisModules imisModulesV2, IHttpContextAccessor httpContextAccessor, int lastApiVersion) + public IMISJwtSecurityTokenHandler(ModulesV1.IImisModules imisModulesV1, ModulesV2.IImisModules imisModulesV2, IHttpContextAccessor httpContextAccessor) { _tokenHandler = new JwtSecurityTokenHandler(); _httpContextAccessor = httpContextAccessor; _imisModulesV1 = imisModulesV1; _imisModulesV2 = imisModulesV2; - - _lastApiVersion = lastApiVersion; } public bool CanValidateToken @@ -81,7 +78,7 @@ public ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParame UserData user; - if (apiVersion == null || apiVersion.StartsWith(_lastApiVersion.ToString())) user = (UserData)_imisModulesV2.GetLoginModule().GetLoginLogic().GetById(userId); + if (apiVersion == null || apiVersion.StartsWith("2")) user = (UserData)_imisModulesV2.GetLoginModule().GetLoginLogic().GetById(userId); else user = (UserData)_imisModulesV1.GetLoginModule().GetLoginLogic().GetById(userId); if (user != null) diff --git a/OpenImis.RestApi/Startup.cs b/OpenImis.RestApi/Startup.cs index eb2a9c7d..62068e53 100644 --- a/OpenImis.RestApi/Startup.cs +++ b/OpenImis.RestApi/Startup.cs @@ -16,6 +16,8 @@ using Microsoft.AspNetCore.Http; using OpenImis.ModulesV1.Helpers; using System.Collections.Generic; +using System.Linq; +using System.Diagnostics; namespace OpenImis.RestApi { @@ -31,7 +33,7 @@ public Startup(IConfiguration configuration) public void ConfigureServices(IServiceCollection services) { var configImisModules = Configuration.GetSection("ImisModules").Get>(); - int lastApiVersion = int.Parse(configImisModules[configImisModules.Count - 1].Version); + int lastApiVersion = configImisModules.Max(c => int.Parse(c.Version)); services.AddSingleton(); services.AddSingleton(); @@ -56,8 +58,7 @@ public void ConfigureServices(IServiceCollection services) options.SecurityTokenValidators.Add(new IMISJwtSecurityTokenHandler( services.BuildServiceProvider().GetService(), services.BuildServiceProvider().GetService(), - services.BuildServiceProvider().GetService(), - lastApiVersion)); + services.BuildServiceProvider().GetService())); }); services.AddAuthorization(); From cf2cdf3c58f2e28b031c7dbc10886d693659b550 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Fri, 2 Aug 2019 15:02:12 +0200 Subject: [PATCH 26/86] OS-40: Endpoint for adding Claim --- OpenImis.ModulesV2/ClaimModule/ClaimModule.cs | 10 ++- .../ClaimModule/Logic/ClaimLogic.cs | 21 +++++- .../ClaimModule/Logic/IClaimLogic.cs | 6 +- .../ClaimModule/Models/RegisterClaim/Claim.cs | 44 +++++++++++ .../Repositories/ClaimRepository.cs | 74 +++++++++++++++++++ .../Repositories/IClaimRepository.cs | 9 +++ OpenImis.ModulesV2/Helpers/Extensions.cs | 39 ++++++++++ OpenImis.ModulesV2/ImisModules.cs | 2 +- .../Controllers/V2/ClaimController.cs | 40 ++++++++++ 9 files changed, 233 insertions(+), 12 deletions(-) create mode 100644 OpenImis.ModulesV2/ClaimModule/Models/RegisterClaim/Claim.cs create mode 100644 OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs create mode 100644 OpenImis.ModulesV2/ClaimModule/Repositories/IClaimRepository.cs create mode 100644 OpenImis.ModulesV2/Helpers/Extensions.cs create mode 100644 OpenImis.RestApi/Controllers/V2/ClaimController.cs diff --git a/OpenImis.ModulesV2/ClaimModule/ClaimModule.cs b/OpenImis.ModulesV2/ClaimModule/ClaimModule.cs index 978663b6..d16d0388 100644 --- a/OpenImis.ModulesV2/ClaimModule/ClaimModule.cs +++ b/OpenImis.ModulesV2/ClaimModule/ClaimModule.cs @@ -1,20 +1,24 @@ -using OpenImis.ModulesV2.ClaimModule.Logic; +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.ClaimModule.Logic; namespace OpenImis.ModulesV2.ClaimModule { public class ClaimModule : IClaimModule { + private IConfiguration _configuration; + private IClaimLogic _claimLogic; - public ClaimModule() + public ClaimModule(IConfiguration configuration) { + _configuration = configuration; } public IClaimLogic GetClaimLogic() { if (_claimLogic == null) { - _claimLogic = new ClaimLogic(); + _claimLogic = new ClaimLogic(_configuration); } return _claimLogic; } diff --git a/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs b/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs index 20de393d..5da81a39 100644 --- a/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs +++ b/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs @@ -1,14 +1,27 @@ -using System; -using System.Collections.Generic; -using System.Text; +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; +using OpenImis.ModulesV2.ClaimModule.Repositories; namespace OpenImis.ModulesV2.ClaimModule.Logic { public class ClaimLogic : IClaimLogic { - public ClaimLogic() + private IConfiguration _configuration; + protected IClaimRepository claimRepository; + + public ClaimLogic(IConfiguration configuration) { + _configuration = configuration; + claimRepository = new ClaimRepository(_configuration); + } + + public int RegisterClaim(Claim claim) + { + int response; + + response = claimRepository.RegisterClaim(claim); + return response; } } } diff --git a/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs b/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs index c10a5f4d..455f4951 100644 --- a/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs +++ b/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs @@ -1,11 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Text; +using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; namespace OpenImis.ModulesV2.ClaimModule.Logic { public interface IClaimLogic { - + int RegisterClaim(Claim claim); } } diff --git a/OpenImis.ModulesV2/ClaimModule/Models/RegisterClaim/Claim.cs b/OpenImis.ModulesV2/ClaimModule/Models/RegisterClaim/Claim.cs new file mode 100644 index 00000000..17645adc --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/Models/RegisterClaim/Claim.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; + +namespace OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim +{ + public class Claim + { + public Details Details { get; set; } + public List Items { get; set; } + public List Services { get; set; } + } + + public class Details + { + public string ClaimDate { get; set; } + public string HFCode { get; set; } + public string ClaimAdmin { get; set; } + public string ClaimCode { get; set; } + public string CHFID { get; set; } + public string StartDate { get; set; } + public string EndDate { get; set; } + public string ICDCode { get; set; } + public string Comment { get; set; } + public float Total { get; set; } + public string ICDCode1 { get; set; } + public string ICDCode2 { get; set; } + public string ICDCode3 { get; set; } + public string ICDCode4 { get; set; } + public int VisitType { get; set; } + } + + public class Item + { + public string ItemCode { get; set; } + public float ItemPrice { get; set; } + public int ItemQuantity { get; set; } + } + + public class Service + { + public string ServiceCode { get; set; } + public float ServicePrice { get; set; } + public int ServiceQuantity { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs b/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs new file mode 100644 index 00000000..a485fdd5 --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs @@ -0,0 +1,74 @@ +using System; +using System.Data; +using System.Data.Common; +using System.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; +using OpenImis.ModulesV2.Helpers; + +namespace OpenImis.ModulesV2.ClaimModule.Repositories +{ + public class ClaimRepository : IClaimRepository + { + private IConfiguration _configuration; + + public ClaimRepository(IConfiguration configuration) + { + _configuration = configuration; + } + + public int RegisterClaim(Claim claim) + { + try + { + var XML = claim.Serialize(); + var RV = -99; + + using (var imisContext = new ImisDB()) + { + var xmlParameter = new SqlParameter("@XML", XML) { DbType = DbType.Xml }; + var returnParameter = new SqlParameter("@RV", SqlDbType.Int) { Direction = ParameterDirection.Output }; + + var sql = "exec @RV = uspUpdateClaimFromPhone @XML"; + + DbConnection connection = imisContext.Database.GetDbConnection(); + + using (DbCommand cmd = connection.CreateCommand()) + { + cmd.CommandText = sql; + + cmd.Parameters.AddRange(new[] { xmlParameter, returnParameter }); + + if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); + + using (var reader = cmd.ExecuteReader()) + { + // Displaying errors in the Stored Procedure in Debug mode + //do + //{ + // while (reader.Read()) + // { + // Debug.WriteLine("Error/Warning: " + reader.GetValue(0)); + // } + //} while (reader.NextResult()); + } + } + + RV = (int)returnParameter.Value; + } + + return RV; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + } +} diff --git a/OpenImis.ModulesV2/ClaimModule/Repositories/IClaimRepository.cs b/OpenImis.ModulesV2/ClaimModule/Repositories/IClaimRepository.cs new file mode 100644 index 00000000..71fdc74a --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/Repositories/IClaimRepository.cs @@ -0,0 +1,9 @@ +using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; + +namespace OpenImis.ModulesV2.ClaimModule.Repositories +{ + public interface IClaimRepository + { + int RegisterClaim(Claim claim); + } +} diff --git a/OpenImis.ModulesV2/Helpers/Extensions.cs b/OpenImis.ModulesV2/Helpers/Extensions.cs new file mode 100644 index 00000000..cbd0615a --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/Extensions.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Xml; +using System.Xml.Serialization; + +namespace OpenImis.ModulesV2.Helpers +{ + public static class Extensions + { + public static string Serialize(this T value) + { + if (value == null) + { + return string.Empty; + } + try + { + var xmlserializer = new XmlSerializer(typeof(T)); + var stringWriter = new StringWriter(); + var emptyNs = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty }); + var settings = new XmlWriterSettings(); + settings.Indent = true; + settings.OmitXmlDeclaration = true; + + using (var writer = XmlWriter.Create(stringWriter, settings)) + { + xmlserializer.Serialize(writer, value, emptyNs); + return stringWriter.ToString(); + } + } + catch (Exception ex) + { + throw new Exception("An error occurred", ex); + } + } + } +} diff --git a/OpenImis.ModulesV2/ImisModules.cs b/OpenImis.ModulesV2/ImisModules.cs index 8b30f724..5680e8a8 100644 --- a/OpenImis.ModulesV2/ImisModules.cs +++ b/OpenImis.ModulesV2/ImisModules.cs @@ -62,7 +62,7 @@ public IClaimModule GetClaimModule() { if (claimModule == null) { - claimModule = new ClaimModule.ClaimModule(); + claimModule = new ClaimModule.ClaimModule(_configuration); Type claimLogicType = CreateTypeFromConfiguration("ClaimModule", "ClaimLogic", "OpenImis.ModulesV2.ClaimModule.Logic.ClaimLogic"); claimModule.SetClaimLogic((ClaimModule.Logic.IClaimLogic)ActivatorUtilities.CreateInstance(_serviceProvider, claimLogicType)); diff --git a/OpenImis.RestApi/Controllers/V2/ClaimController.cs b/OpenImis.RestApi/Controllers/V2/ClaimController.cs new file mode 100644 index 00000000..fedc0c51 --- /dev/null +++ b/OpenImis.RestApi/Controllers/V2/ClaimController.cs @@ -0,0 +1,40 @@ +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using OpenImis.ModulesV2; +using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; + +namespace OpenImis.RestApi.Controllers.V2 +{ + [ApiVersion("2")] + [Authorize] + [Route("api/claim")] + [ApiController] + public class ClaimController : Controller + { + private readonly IImisModules _imisModules; + + public ClaimController(IImisModules imisModules) + { + _imisModules = imisModules; + } + + //[HasRights(Rights.ClaimAdd, Rights.ClaimAdministrator)] + [HttpPost] + public IActionResult Create([FromBody] Claim claim) + { + int response; + + try + { + response = _imisModules.GetClaimModule().GetClaimLogic().RegisterClaim(claim); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + return Ok(response); + } + } +} \ No newline at end of file From 84bef286d07425b27ca5410895de86e068756400 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 8 Aug 2019 09:45:53 +0200 Subject: [PATCH 27/86] OS-37: A controller has been added with the module --- OpenImis.DB.SqlServer/TblFamilies.cs | 1 + OpenImis.DB.SqlServer/TblInsuree.cs | 1 + OpenImis.DB.SqlServer/TblUsers.cs | 1 + OpenImis.ModulesV2/Helpers/Extensions.cs | 39 +++ OpenImis.ModulesV2/ImisModules.cs | 7 +- .../InsureeModule/Helpers/OutputParameter.cs | 16 ++ .../InsureeModule/InsureeModule.cs | 9 +- .../InsureeModule/Logic/FamilyLogic.cs | 53 +++- .../InsureeModule/Logic/IFamilyLogic.cs | 11 +- .../InsureeModule/Models/DataMessage.cs | 14 + .../EnrollFamilyModels/EnrollFamilyModel.cs | 29 ++ .../Models/EnrollFamilyModels/Enrolment.cs | 16 ++ .../Models/EnrollFamilyModels/Family.cs | 21 ++ .../Models/EnrollFamilyModels/FileInfo.cs | 12 + .../Models/EnrollFamilyModels/Insuree.cs | 34 +++ .../Models/EnrollFamilyModels/InsureeImage.cs | 12 + .../EnrollFamilyModels/InsureePolicy.cs | 13 + .../Models/EnrollFamilyModels/Policy.cs | 22 ++ .../Models/EnrollFamilyModels/Premium.cs | 19 ++ .../InsureeModule/Models/Family.cs | 29 ++ .../InsureeModule/Models/FamilyModel.cs | 45 ++++ .../InsureeModule/Models/InsureeModel.cs | 99 +++++++ .../InsureeModule/Models/LocationModel.cs | 24 ++ .../InsureeModule/Models/PhotoModel.cs | 19 ++ .../Repositories/FamilyRepository.cs | 252 ++++++++++++++++++ .../Repositories/IFamilyRepository.cs | 14 + .../LoginModule/Models/UserData.cs | 2 +- .../Repositories/LoginRepository.cs | 4 +- .../Controllers/V2/FamilyController.cs | 74 +++++ .../Controllers/V2/LoginController.cs | 2 +- .../Security/IMISJwtSecurityTokenHandler.cs | 20 +- OpenImis.RestApi/Security/UserData.cs | 3 +- 32 files changed, 893 insertions(+), 24 deletions(-) create mode 100644 OpenImis.ModulesV2/Helpers/Extensions.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Helpers/OutputParameter.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/DataMessage.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Enrolment.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Family.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/FileInfo.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureeImage.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureePolicy.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Policy.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Premium.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/Family.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/FamilyModel.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/LocationModel.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/PhotoModel.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Repositories/IFamilyRepository.cs create mode 100644 OpenImis.RestApi/Controllers/V2/FamilyController.cs diff --git a/OpenImis.DB.SqlServer/TblFamilies.cs b/OpenImis.DB.SqlServer/TblFamilies.cs index fd07c31d..ac700b19 100644 --- a/OpenImis.DB.SqlServer/TblFamilies.cs +++ b/OpenImis.DB.SqlServer/TblFamilies.cs @@ -12,6 +12,7 @@ public TblFamilies() } public int FamilyId { get; set; } + public Guid FamilyUUID { get; set; } public int InsureeId { get; set; } public int? LocationId { get; set; } public bool? Poverty { get; set; } diff --git a/OpenImis.DB.SqlServer/TblInsuree.cs b/OpenImis.DB.SqlServer/TblInsuree.cs index 7c8054d1..f6b1f3e0 100644 --- a/OpenImis.DB.SqlServer/TblInsuree.cs +++ b/OpenImis.DB.SqlServer/TblInsuree.cs @@ -17,6 +17,7 @@ public TblInsuree() } public int InsureeId { get; set; } + public Guid InsureeUUID { get; set; } public int FamilyId { get; set; } public string Chfid { get; set; } public string LastName { get; set; } diff --git a/OpenImis.DB.SqlServer/TblUsers.cs b/OpenImis.DB.SqlServer/TblUsers.cs index 385da50b..59fedfd7 100644 --- a/OpenImis.DB.SqlServer/TblUsers.cs +++ b/OpenImis.DB.SqlServer/TblUsers.cs @@ -13,6 +13,7 @@ public TblUsers() } public int UserId { get; set; } + public Guid UserUUID { get; set; } public string LanguageId { get; set; } public string LastName { get; set; } public string OtherNames { get; set; } diff --git a/OpenImis.ModulesV2/Helpers/Extensions.cs b/OpenImis.ModulesV2/Helpers/Extensions.cs new file mode 100644 index 00000000..cbd0615a --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/Extensions.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Xml; +using System.Xml.Serialization; + +namespace OpenImis.ModulesV2.Helpers +{ + public static class Extensions + { + public static string Serialize(this T value) + { + if (value == null) + { + return string.Empty; + } + try + { + var xmlserializer = new XmlSerializer(typeof(T)); + var stringWriter = new StringWriter(); + var emptyNs = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty }); + var settings = new XmlWriterSettings(); + settings.Indent = true; + settings.OmitXmlDeclaration = true; + + using (var writer = XmlWriter.Create(stringWriter, settings)) + { + xmlserializer.Serialize(writer, value, emptyNs); + return stringWriter.ToString(); + } + } + catch (Exception ex) + { + throw new Exception("An error occurred", ex); + } + } + } +} diff --git a/OpenImis.ModulesV2/ImisModules.cs b/OpenImis.ModulesV2/ImisModules.cs index 8b30f724..f79f4fc1 100644 --- a/OpenImis.ModulesV2/ImisModules.cs +++ b/OpenImis.ModulesV2/ImisModules.cs @@ -11,6 +11,7 @@ using OpenImis.ModulesV2.Helpers; using System.Collections.Generic; using System.Linq; +using Microsoft.AspNetCore.Hosting; namespace OpenImis.ModulesV2 { @@ -24,12 +25,14 @@ public class ImisModules : IImisModules private IPaymentModule paymentModule; private readonly IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; private readonly ILogger _logger; private readonly IServiceProvider _serviceProvider; - public ImisModules(IConfiguration configuration, ILoggerFactory loggerFactory, IServiceProvider serviceProvider) + public ImisModules(IConfiguration configuration, IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory, IServiceProvider serviceProvider) { _configuration = configuration; + _hostingEnvironment = hostingEnvironment; _logger = loggerFactory.CreateLogger("LoggerCategory"); _serviceProvider = serviceProvider; } @@ -80,7 +83,7 @@ public IInsureeModule GetInsureeModule() { if (insureeModule == null) { - insureeModule = new InsureeModule.InsureeModule(_configuration); + insureeModule = new InsureeModule.InsureeModule(_configuration, _hostingEnvironment); Type familyLogicType = CreateTypeFromConfiguration("InsureeModule", "FamilyLogic", "OpenImis.ModulesV2.InsureeModule.Logic.FamilyLogic"); insureeModule.SetFamilyLogic((InsureeModule.Logic.IFamilyLogic)ActivatorUtilities.CreateInstance(_serviceProvider, familyLogicType)); diff --git a/OpenImis.ModulesV2/InsureeModule/Helpers/OutputParameter.cs b/OpenImis.ModulesV2/InsureeModule/Helpers/OutputParameter.cs new file mode 100644 index 00000000..b2b5a34d --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Helpers/OutputParameter.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Helpers +{ + public static class OutputParameter + { + public static SqlParameter CreateOutputParameter(string parameterName, SqlDbType sqlDbType) + { + return new SqlParameter(parameterName, sqlDbType) { Direction = ParameterDirection.Output }; + } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs b/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs index 98d9c247..19a0dd77 100644 --- a/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs +++ b/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using OpenImis.ModulesV2.InsureeModule.Logic; namespace OpenImis.ModulesV2.InsureeModule @@ -6,21 +7,23 @@ namespace OpenImis.ModulesV2.InsureeModule public class InsureeModule : IInsureeModule { private IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; private IFamilyLogic _familyLogic; private IContributionLogic _contributionLogic; private IPolicyLogic _policyLogic; - public InsureeModule(IConfiguration configuration) + public InsureeModule(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { _configuration = configuration; + _hostingEnvironment = hostingEnvironment; } public IFamilyLogic GetFamilyLogic() { if (_familyLogic == null) { - _familyLogic = new FamilyLogic(_configuration); + _familyLogic = new FamilyLogic(_configuration, _hostingEnvironment); } return _familyLogic; } diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs index eafc97fe..085ada50 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs @@ -1,18 +1,61 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.InsureeModule.Models; +using OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels; +using OpenImis.ModulesV2.InsureeModule.Repositories; using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Text; namespace OpenImis.ModulesV2.InsureeModule.Logic { public class FamilyLogic : IFamilyLogic { private IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; - public FamilyLogic(IConfiguration configuration) + protected IFamilyRepository familyRepository; + + public FamilyLogic(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { _configuration = configuration; + _hostingEnvironment = hostingEnvironment; + + familyRepository = new FamilyRepository(_configuration, _hostingEnvironment); + } + + public FamilyModel GetByCHFID(string chfid) + { + FamilyModel response; + + response = familyRepository.GetByCHFID(chfid); + + return response; + } + + public int Create(EnrollFamilyModel model, int userId, int officerId) + { + int response; + + response = familyRepository.Create(model, userId, officerId); + + return response; + } + + public int GetUserIdByUUID(Guid uuid) + { + int response; + + response = familyRepository.GetUserIdByUUID(uuid); + + return response; + } + + public int GetOfficerIdByUserId(int userId) + { + int response; + + response = familyRepository.GetOfficerIdByUserId(userId); + + return response; } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs index ba971a74..68b0aa99 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs @@ -1,11 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Text; +using OpenImis.ModulesV2.InsureeModule.Models; +using OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels; +using System; namespace OpenImis.ModulesV2.InsureeModule.Logic { public interface IFamilyLogic { - + FamilyModel GetByCHFID(string chfid); + int Create(EnrollFamilyModel model, int userId, int officerId); + int GetUserIdByUUID(Guid uuid); + int GetOfficerIdByUserId(int userId); } } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/DataMessage.cs b/OpenImis.ModulesV2/InsureeModule/Models/DataMessage.cs new file mode 100644 index 00000000..225ce6d3 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/DataMessage.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models +{ + public class DataMessage + { + public int Code { get; set; } + public string MessageValue { get; set; } + public bool ErrorOccured { get; set; } + public object Data { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs new file mode 100644 index 00000000..fd78195c --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels +{ + public class EnrollFamilyModel + { + public List Family { get; set; } + public List Insuree { get; set; } + public List Policy { get; set; } + public List Premium { get; set; } + public List InsureePolicy { get; set; } + public List Pictures { get; set; } + + public Enrolment GetEnrolmentFromModel() + { + return new Enrolment() + { + FileInfo = new FileInfo(), + Families = Family, + Insurees = Insuree, + Policies = Policy, + Premiums = Premium, + InsureePolicies = InsureePolicy + }; + } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Enrolment.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Enrolment.cs new file mode 100644 index 00000000..d3d9dafc --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Enrolment.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels +{ + public class Enrolment + { + public FileInfo FileInfo { get; set; } + public List Families { get; set; } + public List Insurees { get; set; } + public List Policies { get; set; } + public List Premiums { get; set; } + public List InsureePolicies { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Family.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Family.cs new file mode 100644 index 00000000..e96754ee --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Family.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels +{ + public class Family + { + public int FamilyId { get; set; } + public int InsureeId { get; set; } + public int LocationId { get; set; } + public string HOFCHFID { get; set; } + public bool Poverty { get; set; } + public bool FamilyType { get; set; } + public string FamilyAddress { get; set; } + public string Ethnicity { get; set; } + public string ConfirmationNo { get; set; } + public string ConfirmationType { get; set; } + public bool isOffline { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/FileInfo.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/FileInfo.cs new file mode 100644 index 00000000..1eda22f2 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/FileInfo.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels +{ + public class FileInfo + { + public int UserId { get; set; } + public int OfficerId { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs new file mode 100644 index 00000000..c85b120c --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels +{ + public class Insuree + { + public int InsureeId { get; set; } + public int FamilyId { get; set; } + public string CHFID { get; set; } + public string LastName { get; set; } + public string OtherNames { get; set; } + public DateTime DOB { get; set; } + public int Gender { get; set; } + public int Marital { get; set; } + public string isHead { get; set; } + public string IdentificationNumber { get; set; } + public string Phone { get; set; } + public string PhotoPath { get; set; } + public bool CardIssued { get; set; } + public int Relationship { get; set; } + public int Profession { get; set; } + public int Education { get; set; } + public string Email { get; set; } + public int TypeOfId { get; set; } + public int HFID { get; set; } + public string CurrentAddress { get; set; } + public string GeoLocation { get; set; } + public int CurVillage { get; set; } + public bool isOffline { get; set; } + public DateTime EffectiveDate { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureeImage.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureeImage.cs new file mode 100644 index 00000000..d50542f5 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureeImage.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels +{ + public class InsureeImage + { + public string ImageName { get; set; } + public byte[] ImageContent { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureePolicy.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureePolicy.cs new file mode 100644 index 00000000..6970756c --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureePolicy.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels +{ + public class InsureePolicy + { + public int InsureeId { get; set; } + public int PolicyId { get; set; } + public DateTime EffectiveDate { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Policy.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Policy.cs new file mode 100644 index 00000000..648e2833 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Policy.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels +{ + public class Policy + { + public int PolicyId { get; set; } + public int FamilyId { get; set; } + public DateTime EnrollDate { get; set; } + public DateTime StartDate { get; set; } + public DateTime EffectiveDate { get; set; } + public DateTime ExpiryDate { get; set; } + public int PolicyStatus { get; set; } + public decimal PolicyValue { get; set; } + public int ProdId { get; set; } + public int OfficerId { get; set; } + public int PolicyStage { get; set; } + public bool isOffline { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Premium.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Premium.cs new file mode 100644 index 00000000..347bd1e6 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Premium.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels +{ + public class Premium + { + public int PremiumId { get; set; } + public int PolicyId { get; set; } + public int PayerId { get; set; } + public string Amount { get; set; } + public string Receipt { get; set; } + public DateTime PayDate { get; set; } + public int PayType { get; set; } + public bool isPhotoFee { get; set; } + public bool isOffline { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/Family.cs b/OpenImis.ModulesV2/InsureeModule/Models/Family.cs new file mode 100644 index 00000000..ffdda7df --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/Family.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models +{ + public abstract class Family + { + public string InsuranceNumber { get; set; } + public string OtherNames { get; set; } + public string LastName { get; set; } + public DateTime BirthDate { get; set; } + public string Gender { get; set; } + public bool? PoveryStatus { get; set; } + public string ConfirmationType { get; set; } + public string PermanentAddress { get; set; } + public string MaritalStatus { get; set; } + public bool BeneficiaryCard { get; set; } + public string CurrentVillageCode { get; set; } + public string CurrentAddress { get; set; } + public string Profession { get; set; } + public short? Education { get; set; } + public string PhoneNumber { get; set; } + public string Email { get; set; } + public string IdentificationType { get; set; } + public string IdentificationNumber { get; set; } + public string FSPCode { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/FamilyModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/FamilyModel.cs new file mode 100644 index 00000000..85cd9fcd --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/FamilyModel.cs @@ -0,0 +1,45 @@ +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.Utils; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenImis.ModulesV2.InsureeModule.Models +{ + public class FamilyModel + { + public Guid FamilyUUID { get; set; } + public IEnumerable Insurees { get; set; } + public Guid InsureeUUID { get; set; } + public int LocationId { get; set; } + public bool Poverty { get; set; } + public string FamilyType { get; set; } + public string FamilyAddress { get; set; } + public string Ethnicity { get; set; } + public string ConfirmationNo { get; set; } + public string ConfirmationType { get; set; } + public bool IsOffline { get; set; } + + public static FamilyModel FromTblFamilies(TblFamilies tblFamilies) + { + FamilyModel familyModel = new FamilyModel() + { + FamilyUUID = tblFamilies.FamilyUUID, + InsureeUUID = tblFamilies.Insuree.InsureeUUID, + LocationId = TypeCast.GetValue(tblFamilies.LocationId), + Poverty = TypeCast.GetValue(tblFamilies.Poverty), + FamilyType = tblFamilies.FamilyType, + FamilyAddress = tblFamilies.FamilyAddress, + Ethnicity = tblFamilies.Ethnicity, + ConfirmationNo = tblFamilies.ConfirmationNo, + ConfirmationType = tblFamilies.ConfirmationType, + IsOffline = TypeCast.GetValue(tblFamilies.IsOffline), + Insurees = tblFamilies.TblInsuree + .Where(i => i.ValidityTo == null) + .Select(i => InsureeModel.FromTblInsuree(i)) + .ToList() + }; + return familyModel; + } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs new file mode 100644 index 00000000..96b5d4dd --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs @@ -0,0 +1,99 @@ +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.Utils; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models +{ + public class InsureeModel + { + public Guid InsureeUUID { get; set; } + public string IdentificationNumber { get; set; } + public string CHFID { get; set; } + public string LastName { get; set; } + public string OtherNames { get; set; } + public DateTime DOB { get; set; } + public string Gender { get; set; } + public string Marital { get; set; } + public bool IsHead { get; set; } + public string Phone { get; set; } + public bool CardIssued { get; set; } + public short? Relationship { get; set; } + public short? Profession { get; set; } + public short? Education { get; set; } + public string Email { get; set; } + public string TypeOfId { get; set; } + public int? HFID { get; set; } + public string CurrentAddress { get; set; } + public string GeoLocation { get; set; } + public string CurVillage { get; set; } + public string PhotoPath { get; set; } + public string IdentificationTypes { get; set; } + public bool IsOffline { get; set; } + + public DateTime ValidFrom { get; set; } + public DateTime? ValidTo { get; set; } + + public static InsureeModel FromTblInsuree(TblInsuree tblInsuree) + { + if (tblInsuree == null) + { + return null; + } + + InsureeModel insuree = new InsureeModel() + { + InsureeUUID = tblInsuree.InsureeUUID, + IdentificationNumber = tblInsuree.Passport, + CHFID = tblInsuree.Chfid, + LastName = tblInsuree.LastName, + OtherNames = tblInsuree.OtherNames, + DOB = tblInsuree.Dob, + IsHead = tblInsuree.IsHead, + Phone = tblInsuree.Phone, + Gender = tblInsuree.Gender, + Marital = tblInsuree.Marital, + TypeOfId = tblInsuree.TypeOfId, + CardIssued = tblInsuree.CardIssued, + Email = tblInsuree.Email, + CurrentAddress = tblInsuree.CurrentAddress, + GeoLocation = tblInsuree.GeoLocation, + IdentificationTypes = tblInsuree.TypeOfId, + PhotoPath = "" // TODO + }; + + if (tblInsuree.Relationship != null) + { + insuree.Relationship = (short)tblInsuree.Relationship; + } + + if (tblInsuree.Profession != null) + { + insuree.Profession = TypeCast.GetValue(tblInsuree.Profession); + } + + if (tblInsuree.Education != null) + { + insuree.Education = TypeCast.GetValue(tblInsuree.Education); + } + + if (tblInsuree.Hfid != null) + { + insuree.HFID = (short)tblInsuree.Hfid; + } + + if (tblInsuree.CurrentVillage != null) + { + insuree.CurVillage = tblInsuree.CurrentVillage.ToString(); + } + + if (tblInsuree.IsOffline != null) + { + insuree.IsOffline = (bool)tblInsuree.IsOffline; + } + + return insuree; + } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/LocationModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/LocationModel.cs new file mode 100644 index 00000000..e04f7c19 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/LocationModel.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models +{ + public class LocationModel + { + public int LocationId { get; set; } + public string LocationCode { get; set; } + public string LocationName { get; set; } + public int? ParentLocationId { get; set; } + public string LocationType { get; set; } /// TODO: this is char or string? + public DateTime? ValidFrom { get; set; } + public DateTime? ValidTo { get; set; } + public int LegacyId { get; set; } + public int MalePopulation { get; set; } + public int FemalePopulation { get; set; } + public int OtherPopulation { get; set; } + public int Families { get; set; } + + public ICollection Locations { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/PhotoModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/PhotoModel.cs new file mode 100644 index 00000000..1e69e893 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/PhotoModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models +{ + public class PhotoModel + { + public int PhotoId { get; set; } + public InsureeModel Insuree { get; set; } + public string CHFID { get; set; } + public string PhotoFolder { get; set; } + public string PhotoFileName { get; set; } + public int OfficerId { get; set; } + public DateTime PhotoDate { get; set; } + public DateTime ValidFrom { get; set; } + public DateTime ValidTo { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs new file mode 100644 index 00000000..451a4d1c --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs @@ -0,0 +1,252 @@ +using System; +using System.Data; +using System.Linq; +using System.Data.SqlClient; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.Helpers; +using OpenImis.ModulesV2.InsureeModule.Models; +using OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels; +using System.Diagnostics; +using OpenImis.ModulesV2.InsureeModule.Helpers; +using System.Data.Common; +using System.IO; +using Microsoft.AspNetCore.Hosting; +using System.Xml; + +namespace OpenImis.ModulesV2.InsureeModule.Repositories +{ + public class FamilyRepository : IFamilyRepository + { + private IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; + + public FamilyRepository(IConfiguration configuration, IHostingEnvironment hostingEnvironment) + { + _configuration = configuration; + _hostingEnvironment = hostingEnvironment; + } + + public FamilyModel GetByCHFID(string chfid) + { + FamilyModel response = new FamilyModel(); + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.TblInsuree + .Where(i => i.ValidityTo == null && i.Chfid == chfid) + .Join(imisContext.TblFamilies, i => i.FamilyId, f => f.FamilyId, (i, f) => f) + .Where(f => f.ValidityTo == null) + .Include(f => f.TblInsuree) + .Select(f => FamilyModel.FromTblFamilies(f)) + .FirstOrDefault(); + } + + if (response == null) + { + return null; + } + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + + public int Create(EnrollFamilyModel model, int userId, int officerId) + { + try + { + string webRootPath = _hostingEnvironment.WebRootPath; + + var XML = model.GetEnrolmentFromModel().Serialize(); + + var EnrollmentDir = _configuration["AppSettings:Enrollment_Phone"]; + var JsonDebugFolder = _configuration["AppSettings:JsonDebugFolder"]; + var UpdatedFolder = _configuration["AppSettings:UpdatedFolder"]; + var SubmittedFolder = _configuration["AppSettings:SubmittedFolder"]; + + var hof = ""; + + if (model.Insuree.Any(x => x.isHead == "true" || x.isHead == "1")) + { + hof = model.Insuree.Where(x => x.isHead == "true" || x.isHead == "1").Select(z => z.CHFID).FirstOrDefault(); + } + else hof = "Unknown"; + + var FileName = string.Format("{0}_{1}_{2}.xml", hof, officerId.ToString(), DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss.XML")); + var JsonFileName = string.Format("{0}_{1}_{2}.xml", hof, officerId.ToString(), DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")); + + + var xmldoc = new XmlDocument(); + xmldoc.InnerXml = XML; + + try + { + if (!Directory.Exists(webRootPath + EnrollmentDir)) Directory.CreateDirectory(webRootPath + EnrollmentDir); + + xmldoc.Save(webRootPath + EnrollmentDir + FileName); + + if (!Directory.Exists(webRootPath + JsonDebugFolder)) Directory.CreateDirectory(webRootPath + JsonDebugFolder); + + File.WriteAllText(webRootPath + JsonDebugFolder + JsonFileName, XML); + } + catch (Exception e) + { + throw e; + } + + int RV = -99; + int InsureeUpd; + int InsureeImported; + + using (var imisContext = new ImisDB()) + { + var xmlParameter = new SqlParameter("@XML", XML) { DbType = DbType.Xml }; + var returnParameter = OutputParameter.CreateOutputParameter("@RV", SqlDbType.Int); + var familySentParameter = OutputParameter.CreateOutputParameter("@FamilySent", SqlDbType.Int); + var familyImportedParameter = OutputParameter.CreateOutputParameter("@FamilyImported", SqlDbType.Int); + var familiesUpdParameter = OutputParameter.CreateOutputParameter("@FamiliesUpd", SqlDbType.Int); + var familyRejectedParameter = OutputParameter.CreateOutputParameter("@FamilyRejected", SqlDbType.Int); + var insureeSentParameter = OutputParameter.CreateOutputParameter("@InsureeSent", SqlDbType.Int); + var insureeUpdParameter = OutputParameter.CreateOutputParameter("@InsureeUpd", SqlDbType.Int); + var insureeImportedParameter = OutputParameter.CreateOutputParameter("@InsureeImported", SqlDbType.Int); + var policySentParameter = OutputParameter.CreateOutputParameter("@PolicySent", SqlDbType.Int); + var policyImportedParameter = OutputParameter.CreateOutputParameter("@PolicyImported", SqlDbType.Int); + var policyRejectedParameter = OutputParameter.CreateOutputParameter("@PolicyRejected", SqlDbType.Int); + var policyChangedParameter = OutputParameter.CreateOutputParameter("@PolicyChanged", SqlDbType.Int); + var premiumSentParameter = OutputParameter.CreateOutputParameter("@PremiumSent", SqlDbType.Int); + var premiumImportedParameter = OutputParameter.CreateOutputParameter("@PremiumImported", SqlDbType.Int); + var premiumRejectedParameter = OutputParameter.CreateOutputParameter("@PremiumRejected", SqlDbType.Int); + + var sql = "exec @RV = uspConsumeEnrollments @XML, @FamilySent OUT, @FamilyImported OUT, @FamiliesUpd OUT, @FamilyRejected OUT, " + + "@InsureeSent OUT, @InsureeUpd OUT, @InsureeImported OUT, " + + "@PolicySent OUT, @PolicyImported OUT, @PolicyRejected OUT, @PolicyChanged OUT," + + "@PremiumSent OUT, @PremiumImported OUT, @PremiumRejected OUT"; + + DbConnection connection = imisContext.Database.GetDbConnection(); + + using (DbCommand cmd = connection.CreateCommand()) + { + + cmd.CommandText = sql; + + cmd.Parameters.AddRange(new[] { xmlParameter, returnParameter, familySentParameter, familyImportedParameter, familiesUpdParameter, + familyRejectedParameter, insureeSentParameter, insureeUpdParameter, insureeImportedParameter, policySentParameter, + policyImportedParameter, policyRejectedParameter, policyChangedParameter, premiumSentParameter, premiumImportedParameter, + premiumRejectedParameter }); + + if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); + + using (var reader = cmd.ExecuteReader()) + { + //Displaying errors in the Stored Procedure in Debug mode + //do + //{ + // while (reader.Read()) + // { + // Debug.WriteLine("Error/Warning: " + reader.GetValue(0)); + // } + //} while (reader.NextResult()); + } + } + + InsureeUpd = insureeUpdParameter.Value == DBNull.Value ? 0 : (int)insureeUpdParameter.Value; + InsureeImported = insureeImportedParameter.Value == DBNull.Value ? 0 : (int)insureeImportedParameter.Value; + RV = (int)returnParameter.Value; + + if (RV == 0 && (InsureeImported > 0 || InsureeUpd > 0)) + { + if (!Directory.Exists(webRootPath + UpdatedFolder)) + { + Directory.CreateDirectory(webRootPath + UpdatedFolder); + } + + foreach (var picture in model.Pictures) + { + if (picture != null) + { + if (picture.ImageContent != null) + { + if (picture.ImageContent.Length == 0) + { + File.WriteAllBytes(webRootPath + UpdatedFolder + Path.DirectorySeparatorChar + picture.ImageName, picture.ImageContent); + } + } + } + } + } + } + + return RV; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + + public int GetUserIdByUUID(Guid uuid) + { + int response; + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.TblUsers + .Where(u => u.UserUUID == uuid) + .Select(x => x.UserId) + .FirstOrDefault(); + } + + return response; + } + catch (SqlException e) + { + throw e; + } + } + + public int GetOfficerIdByUserId(int userId) + { + int response; + + try + { + using (var imisContext = new ImisDB()) + { + var loginName = imisContext.TblUsers + .Where(u => u.UserId == userId) + .Select(x => x.LoginName) + .FirstOrDefault(); + + response = imisContext.TblOfficer + .Where(o => o.Code == loginName) + .Select(x => x.OfficerId) + .FirstOrDefault(); + } + + return response; + } + catch (SqlException e) + { + throw e; + } + } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/IFamilyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/IFamilyRepository.cs new file mode 100644 index 00000000..25176e23 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/IFamilyRepository.cs @@ -0,0 +1,14 @@ +using OpenImis.ModulesV2.InsureeModule.Models; +using OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels; +using System; + +namespace OpenImis.ModulesV2.InsureeModule.Repositories +{ + public interface IFamilyRepository + { + FamilyModel GetByCHFID(string chfid); + int Create(EnrollFamilyModel model, int userId, int officerId); + int GetUserIdByUUID(Guid uuid); + int GetOfficerIdByUserId(int userId); + } +} diff --git a/OpenImis.ModulesV2/LoginModule/Models/UserData.cs b/OpenImis.ModulesV2/LoginModule/Models/UserData.cs index f1a78eb4..5c32908e 100644 --- a/OpenImis.ModulesV2/LoginModule/Models/UserData.cs +++ b/OpenImis.ModulesV2/LoginModule/Models/UserData.cs @@ -6,7 +6,7 @@ namespace OpenImis.ModulesV2.LoginModule.Models { public class UserData { - public string UserID { get; set; } + public Guid UserUUID { get; set; } public string LoginName { get; set; } public string PrivateKey { get; set; } public string StoredPassword { get; set; } diff --git a/OpenImis.ModulesV2/LoginModule/Repositories/LoginRepository.cs b/OpenImis.ModulesV2/LoginModule/Repositories/LoginRepository.cs index f3d1ada7..8c74ed01 100644 --- a/OpenImis.ModulesV2/LoginModule/Repositories/LoginRepository.cs +++ b/OpenImis.ModulesV2/LoginModule/Repositories/LoginRepository.cs @@ -23,7 +23,7 @@ public UserData GetById(int userId) { user = imisContext.TblUsers.Where(u => u.UserId == userId).Select(x => new UserData() { - UserID = x.UserId.ToString(), + UserUUID = x.UserUUID, LoginName = x.LoginName, PrivateKey = x.PrivateKey, StoredPassword = x.StoredPassword @@ -46,7 +46,7 @@ public List FindUserByName(string UserName) .Where(u => u.LoginName == UserName && u.ValidityTo == null) .Select(x => new UserData() { - UserID = Convert.ToString(x.UserId), + UserUUID = x.UserUUID, LoginName = Convert.ToString(x.LoginName), PrivateKey = Convert.ToString(x.PrivateKey), StoredPassword = Convert.ToString(x.StoredPassword) diff --git a/OpenImis.RestApi/Controllers/V2/FamilyController.cs b/OpenImis.RestApi/Controllers/V2/FamilyController.cs new file mode 100644 index 00000000..9f418b0e --- /dev/null +++ b/OpenImis.RestApi/Controllers/V2/FamilyController.cs @@ -0,0 +1,74 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics; +using System.Linq; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using OpenImis.ModulesV2; +using OpenImis.ModulesV2.InsureeModule.Models; +using OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels; +using OpenImis.RestApi.Security; + +namespace OpenImis.RestApi.Controllers.V2 +{ + [ApiVersion("2")] + [Authorize] + [Route("api/family/")] + [ApiController] + public class FamilyController : Controller + { + private readonly IImisModules _imisModules; + + public FamilyController(IImisModules imisModules) + { + _imisModules = imisModules; + } + + //[HasRights(Rights.FamilyAdd)] + [HttpGet] + [Route("{chfid}")] + public IActionResult GetByCHFID(string chfid) + { + FamilyModel familyModel; + + try + { + familyModel = _imisModules.GetInsureeModule().GetFamilyLogic().GetByCHFID(chfid); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + if (familyModel == null) + { + return NotFound(); + } + + return Ok(familyModel); + } + + //[HasRights(Rights.FamilyAdd)] + [HttpPost] + public IActionResult Create([FromBody] EnrollFamilyModel model) + { + int response; + + try + { + Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); + + int userId = _imisModules.GetInsureeModule().GetFamilyLogic().GetUserIdByUUID(userUUID); + int officerId = _imisModules.GetInsureeModule().GetFamilyLogic().GetOfficerIdByUserId(userId); + + response = _imisModules.GetInsureeModule().GetFamilyLogic().Create(model, userId, officerId); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + return Ok(response); + } + } +} \ No newline at end of file diff --git a/OpenImis.RestApi/Controllers/V2/LoginController.cs b/OpenImis.RestApi/Controllers/V2/LoginController.cs index 00bd1004..666de0e1 100644 --- a/OpenImis.RestApi/Controllers/V2/LoginController.cs +++ b/OpenImis.RestApi/Controllers/V2/LoginController.cs @@ -43,7 +43,7 @@ public IActionResult Index([FromBody]LoginModel model) List claims = new List() { - new Claim("UserId", user.UserID) + new Claim("UserUUID", user.UserUUID.ToString()) }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(user.PrivateKey)); diff --git a/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs b/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs index 8c890559..5596f061 100644 --- a/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs +++ b/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs @@ -72,14 +72,24 @@ public ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParame var handler = new JwtSecurityTokenHandler(); var tokenS = handler.ReadToken(securityToken) as JwtSecurityToken; - int userId = Convert.ToInt32(tokenS.Claims.Where(w => w.Type == "UserId").Select(x => x.Value).FirstOrDefault()); - + string apiVersion = _httpContextAccessor.HttpContext.Request.Headers.Where(x => x.Key == "api-version").Select(s => s.Value).FirstOrDefault(); UserData user; - - if (apiVersion == null || apiVersion.StartsWith("2")) user = (UserData)_imisModulesV2.GetLoginModule().GetLoginLogic().GetById(userId); - else user = (UserData)_imisModulesV1.GetLoginModule().GetLoginLogic().GetById(userId); + + if (apiVersion == null || apiVersion.StartsWith("2")) + { + Guid userUUID = Guid.Parse(tokenS.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); + int userId = _imisModulesV2.GetInsureeModule().GetFamilyLogic().GetUserIdByUUID(userUUID); + + user = (UserData)_imisModulesV2.GetLoginModule().GetLoginLogic().GetById(userId); + } + else + { + int userId = Convert.ToInt32(tokenS.Claims.Where(w => w.Type == "UserId").Select(x => x.Value).FirstOrDefault()); + + user = (UserData)_imisModulesV1.GetLoginModule().GetLoginLogic().GetById(userId); + } if (user != null) { diff --git a/OpenImis.RestApi/Security/UserData.cs b/OpenImis.RestApi/Security/UserData.cs index 4a2f72ab..2e470360 100644 --- a/OpenImis.RestApi/Security/UserData.cs +++ b/OpenImis.RestApi/Security/UserData.cs @@ -9,6 +9,7 @@ namespace OpenImis.RestApi.Security public class UserData { public string UserID { get; set; } + public Guid UserUUID { get; set; } public string LoginName { get; set; } public string PrivateKey { get; set; } public string StoredPassword { get; set; } @@ -28,7 +29,7 @@ public static explicit operator UserData(ModulesV2.LoginModule.Models.UserData v { return new UserData() { - UserID = v.UserID, + UserUUID = v.UserUUID, LoginName = v.LoginName, PrivateKey = v.PrivateKey }; From 72108f83238a8f167ce7f8adb5e91507ea82368f Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 8 Aug 2019 09:57:41 +0200 Subject: [PATCH 28/86] OS-37: Added Hoisting to Module v2 --- OpenImis.ModulesV2/OpenImis.ModulesV2.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/OpenImis.ModulesV2/OpenImis.ModulesV2.csproj b/OpenImis.ModulesV2/OpenImis.ModulesV2.csproj index b83519ca..633ec930 100644 --- a/OpenImis.ModulesV2/OpenImis.ModulesV2.csproj +++ b/OpenImis.ModulesV2/OpenImis.ModulesV2.csproj @@ -5,6 +5,7 @@ + From f2a16382acfcfd76f09339b44f4608be60dd8331 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 8 Aug 2019 10:47:13 +0200 Subject: [PATCH 29/86] OS-37: Added PhotoPath --- OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs | 8 ++++++-- .../InsureeModule/Repositories/FamilyRepository.cs | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs index 96b5d4dd..74783167 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs @@ -59,8 +59,7 @@ public static InsureeModel FromTblInsuree(TblInsuree tblInsuree) Email = tblInsuree.Email, CurrentAddress = tblInsuree.CurrentAddress, GeoLocation = tblInsuree.GeoLocation, - IdentificationTypes = tblInsuree.TypeOfId, - PhotoPath = "" // TODO + IdentificationTypes = tblInsuree.TypeOfId }; if (tblInsuree.Relationship != null) @@ -93,6 +92,11 @@ public static InsureeModel FromTblInsuree(TblInsuree tblInsuree) insuree.IsOffline = (bool)tblInsuree.IsOffline; } + if (tblInsuree.Photo != null) + { + insuree.PhotoPath = tblInsuree.Photo.PhotoFileName; + } + return insuree; } } diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs index 451a4d1c..e22944b0 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs @@ -42,6 +42,7 @@ public FamilyModel GetByCHFID(string chfid) .Join(imisContext.TblFamilies, i => i.FamilyId, f => f.FamilyId, (i, f) => f) .Where(f => f.ValidityTo == null) .Include(f => f.TblInsuree) + .ThenInclude(f => f.Photo) .Select(f => FamilyModel.FromTblFamilies(f)) .FirstOrDefault(); } From cf2e25e96cfb38a9655ecd5a3d12b73e31d0512b Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 8 Aug 2019 11:34:01 +0200 Subject: [PATCH 30/86] OS-40: Removed unnecessary right --- OpenImis.RestApi/Controllers/V2/ClaimController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenImis.RestApi/Controllers/V2/ClaimController.cs b/OpenImis.RestApi/Controllers/V2/ClaimController.cs index fedc0c51..d7044ddc 100644 --- a/OpenImis.RestApi/Controllers/V2/ClaimController.cs +++ b/OpenImis.RestApi/Controllers/V2/ClaimController.cs @@ -19,7 +19,7 @@ public ClaimController(IImisModules imisModules) _imisModules = imisModules; } - //[HasRights(Rights.ClaimAdd, Rights.ClaimAdministrator)] + //[HasRights(Rights.ClaimAdd)] [HttpPost] public IActionResult Create([FromBody] Claim claim) { From b623e0537d6552b94731c75fa270dd4df4d6a969 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Fri, 9 Aug 2019 10:20:52 +0200 Subject: [PATCH 31/86] OS-37: Directory path settings moved to appsettings.json --- OpenImis.RestApi/appsettings.json | 40 +++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/OpenImis.RestApi/appsettings.json b/OpenImis.RestApi/appsettings.json index 6509d20a..db0a7fb0 100644 --- a/OpenImis.RestApi/appsettings.json +++ b/OpenImis.RestApi/appsettings.json @@ -2,17 +2,31 @@ "JwtIssuer": "http://openimis.org", "JwtAudience": "http://openimis.org", "JwtExpireDays": 5, - "Logging": { - "IncludeScopes": false, - "Debug": { - "LogLevel": { - "Default": "Warning" - } - }, - "Console": { - "LogLevel": { - "Default": "Warning" - } - } - } + "Logging": { + "IncludeScopes": false, + "Debug": { + "LogLevel": { + "Default": "Warning" + } + }, + "Console": { + "LogLevel": { + "Default": "Warning" + } + } + }, + "AppSettings": { + "FromPhone_Renewal": "\\FromPhone\\Renewal\\", + "FromPhone_Renewal_Rejected": "\\FromPhone\\Renewal\\Rejected\\", + "FromPhone_Claim": "\\FromPhone\\Claim\\", + "FromPhone_Claim_Rejected": "\\FromPhone\\Claim\\Rejected\\", + "FromPhone_Feedback": "\\FromPhone\\Feedback\\", + "FromPhone_Feedback_Rejected": "\\FromPhone\\Feedback\\Rejected\\", + "Extracts_Phone": "\\Extracts\\Phone\\", + "Enrollment_Phone": "\\FromPhone\\Enrollment\\", + "Extracts_Offline": "\\Extracts\\Offline\\", + "JsonDebugFolder": "\\FromPhone\\Enrollment\\Debug\\", + "SubmittedFolder": "\\Images\\Submitted\\", + "UpdatedFolder": "\\Images\\Updated\\" + } } From b0e1f16500d0cf0b6516846e09dbbdf3a8ac3083 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Fri, 9 Aug 2019 11:06:18 +0200 Subject: [PATCH 32/86] OS-37: Unnecessary classes have been removed and the way data is displayed in response has been changed --- .../InsureeModule/Models/DataMessage.cs | 14 --------- .../InsureeModule/Models/Family.cs | 29 ------------------- .../InsureeModule/Models/InsureeModel.cs | 5 ++-- .../InsureeModule/Models/LocationModel.cs | 24 --------------- .../InsureeModule/Models/PhotoModel.cs | 19 ------------ 5 files changed, 3 insertions(+), 88 deletions(-) delete mode 100644 OpenImis.ModulesV2/InsureeModule/Models/DataMessage.cs delete mode 100644 OpenImis.ModulesV2/InsureeModule/Models/Family.cs delete mode 100644 OpenImis.ModulesV2/InsureeModule/Models/LocationModel.cs delete mode 100644 OpenImis.ModulesV2/InsureeModule/Models/PhotoModel.cs diff --git a/OpenImis.ModulesV2/InsureeModule/Models/DataMessage.cs b/OpenImis.ModulesV2/InsureeModule/Models/DataMessage.cs deleted file mode 100644 index 225ce6d3..00000000 --- a/OpenImis.ModulesV2/InsureeModule/Models/DataMessage.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenImis.ModulesV2.InsureeModule.Models -{ - public class DataMessage - { - public int Code { get; set; } - public string MessageValue { get; set; } - public bool ErrorOccured { get; set; } - public object Data { get; set; } - } -} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/Family.cs b/OpenImis.ModulesV2/InsureeModule/Models/Family.cs deleted file mode 100644 index ffdda7df..00000000 --- a/OpenImis.ModulesV2/InsureeModule/Models/Family.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenImis.ModulesV2.InsureeModule.Models -{ - public abstract class Family - { - public string InsuranceNumber { get; set; } - public string OtherNames { get; set; } - public string LastName { get; set; } - public DateTime BirthDate { get; set; } - public string Gender { get; set; } - public bool? PoveryStatus { get; set; } - public string ConfirmationType { get; set; } - public string PermanentAddress { get; set; } - public string MaritalStatus { get; set; } - public bool BeneficiaryCard { get; set; } - public string CurrentVillageCode { get; set; } - public string CurrentAddress { get; set; } - public string Profession { get; set; } - public short? Education { get; set; } - public string PhoneNumber { get; set; } - public string Email { get; set; } - public string IdentificationType { get; set; } - public string IdentificationNumber { get; set; } - public string FSPCode { get; set; } - } -} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs index 74783167..cac6ed3a 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs @@ -2,6 +2,7 @@ using OpenImis.ModulesV2.Utils; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Text; namespace OpenImis.ModulesV2.InsureeModule.Models @@ -13,7 +14,7 @@ public class InsureeModel public string CHFID { get; set; } public string LastName { get; set; } public string OtherNames { get; set; } - public DateTime DOB { get; set; } + public string DOB { get; set; } public string Gender { get; set; } public string Marital { get; set; } public bool IsHead { get; set; } @@ -49,7 +50,7 @@ public static InsureeModel FromTblInsuree(TblInsuree tblInsuree) CHFID = tblInsuree.Chfid, LastName = tblInsuree.LastName, OtherNames = tblInsuree.OtherNames, - DOB = tblInsuree.Dob, + DOB = tblInsuree.Dob.ToString("yyyy-mm-dd"), IsHead = tblInsuree.IsHead, Phone = tblInsuree.Phone, Gender = tblInsuree.Gender, diff --git a/OpenImis.ModulesV2/InsureeModule/Models/LocationModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/LocationModel.cs deleted file mode 100644 index e04f7c19..00000000 --- a/OpenImis.ModulesV2/InsureeModule/Models/LocationModel.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenImis.ModulesV2.InsureeModule.Models -{ - public class LocationModel - { - public int LocationId { get; set; } - public string LocationCode { get; set; } - public string LocationName { get; set; } - public int? ParentLocationId { get; set; } - public string LocationType { get; set; } /// TODO: this is char or string? - public DateTime? ValidFrom { get; set; } - public DateTime? ValidTo { get; set; } - public int LegacyId { get; set; } - public int MalePopulation { get; set; } - public int FemalePopulation { get; set; } - public int OtherPopulation { get; set; } - public int Families { get; set; } - - public ICollection Locations { get; set; } - } -} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/PhotoModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/PhotoModel.cs deleted file mode 100644 index 1e69e893..00000000 --- a/OpenImis.ModulesV2/InsureeModule/Models/PhotoModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenImis.ModulesV2.InsureeModule.Models -{ - public class PhotoModel - { - public int PhotoId { get; set; } - public InsureeModel Insuree { get; set; } - public string CHFID { get; set; } - public string PhotoFolder { get; set; } - public string PhotoFileName { get; set; } - public int OfficerId { get; set; } - public DateTime PhotoDate { get; set; } - public DateTime ValidFrom { get; set; } - public DateTime ValidTo { get; set; } - } -} From 099c068af2ddde48f38a06c0750e2935f3ee5784 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Fri, 9 Aug 2019 11:20:21 +0200 Subject: [PATCH 33/86] OS-37: Removed properties for valid date --- OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs index cac6ed3a..3f14d3c7 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs @@ -33,9 +33,6 @@ public class InsureeModel public string IdentificationTypes { get; set; } public bool IsOffline { get; set; } - public DateTime ValidFrom { get; set; } - public DateTime? ValidTo { get; set; } - public static InsureeModel FromTblInsuree(TblInsuree tblInsuree) { if (tblInsuree == null) From 9eec7895a8fe2c70423004fdea381b6fbfff76f4 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Fri, 9 Aug 2019 17:14:06 +0200 Subject: [PATCH 34/86] OS-37: Rebuilt GetByCHFID() --- OpenImis.DB.SqlServer/IMISContext.cs | 19 +++++++++++++++ OpenImis.DB.SqlServer/TblDistricts.cs | 15 ++++++++++++ OpenImis.DB.SqlServer/TblVillages.cs | 16 +++++++++++++ OpenImis.DB.SqlServer/TblWards.cs | 16 +++++++++++++ .../InsureeModule/Logic/FamilyLogic.cs | 4 ++-- .../InsureeModule/Logic/IFamilyLogic.cs | 2 +- .../Repositories/FamilyRepository.cs | 24 +++++++++++++++++-- .../Repositories/IFamilyRepository.cs | 2 +- .../Controllers/V2/FamilyController.cs | 5 +++- 9 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 OpenImis.DB.SqlServer/TblDistricts.cs create mode 100644 OpenImis.DB.SqlServer/TblVillages.cs create mode 100644 OpenImis.DB.SqlServer/TblWards.cs diff --git a/OpenImis.DB.SqlServer/IMISContext.cs b/OpenImis.DB.SqlServer/IMISContext.cs index 3c5fbc50..5b81a37b 100644 --- a/OpenImis.DB.SqlServer/IMISContext.cs +++ b/OpenImis.DB.SqlServer/IMISContext.cs @@ -73,6 +73,10 @@ public IMISContext(DbContextOptions options) public virtual DbSet TblUsersDistricts { get; set; } public virtual DbSet TblRoleRight { get; set; } public virtual DbSet TblUserRole { get; set; } + public virtual DbSet TblVillages { get; set; } + public virtual DbSet TblWards { get; set; } + public virtual DbSet TblDistricts { get; set; } + // Unable to generate entity type for table 'dbo.tblIMISDetaulsPhone'. Please see the warning messages. // Unable to generate entity type for table 'dbo.tblEmailSettings'. Please see the warning messages. @@ -2657,6 +2661,21 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { entity.HasKey(e => e.UserRoleID); }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.VillageId); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.WardId); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.DistrictId); + }); } } } diff --git a/OpenImis.DB.SqlServer/TblDistricts.cs b/OpenImis.DB.SqlServer/TblDistricts.cs new file mode 100644 index 00000000..29ee3180 --- /dev/null +++ b/OpenImis.DB.SqlServer/TblDistricts.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.DB.SqlServer +{ + public class TblDistricts + { + public int DistrictId { get; set; } + public string DistrictCode { get; set; } + public string DistrictName { get; set; } + public DateTime ValidityFrom { get; set; } + public DateTime? ValidityTo { get; set; } + } +} diff --git a/OpenImis.DB.SqlServer/TblVillages.cs b/OpenImis.DB.SqlServer/TblVillages.cs new file mode 100644 index 00000000..966597c6 --- /dev/null +++ b/OpenImis.DB.SqlServer/TblVillages.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.DB.SqlServer +{ + public class TblVillages + { + public int VillageId { get; set; } + public int? WardId { get; set; } + public string VillageCode { get; set; } + public string VillageName { get; set; } + public DateTime ValidityFrom { get; set; } + public DateTime? ValidityTo { get; set; } + } +} diff --git a/OpenImis.DB.SqlServer/TblWards.cs b/OpenImis.DB.SqlServer/TblWards.cs new file mode 100644 index 00000000..9f379a60 --- /dev/null +++ b/OpenImis.DB.SqlServer/TblWards.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.DB.SqlServer +{ + public class TblWards + { + public int WardId { get; set; } + public int? DistrictId { get; set; } + public string WardCode { get; set; } + public string WardName { get; set; } + public DateTime ValidityFrom { get; set; } + public DateTime? ValidityTo { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs index 085ada50..ceb8d53b 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs @@ -22,11 +22,11 @@ public FamilyLogic(IConfiguration configuration, IHostingEnvironment hostingEnvi familyRepository = new FamilyRepository(_configuration, _hostingEnvironment); } - public FamilyModel GetByCHFID(string chfid) + public FamilyModel GetByCHFID(string chfid, int userId) { FamilyModel response; - response = familyRepository.GetByCHFID(chfid); + response = familyRepository.GetByCHFID(chfid, userId); return response; } diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs index 68b0aa99..e498f6d3 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs @@ -6,7 +6,7 @@ namespace OpenImis.ModulesV2.InsureeModule.Logic { public interface IFamilyLogic { - FamilyModel GetByCHFID(string chfid); + FamilyModel GetByCHFID(string chfid, int userId); int Create(EnrollFamilyModel model, int userId, int officerId); int GetUserIdByUUID(Guid uuid); int GetOfficerIdByUserId(int userId); diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs index e22944b0..f383f5f9 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs @@ -29,7 +29,7 @@ public FamilyRepository(IConfiguration configuration, IHostingEnvironment hostin _hostingEnvironment = hostingEnvironment; } - public FamilyModel GetByCHFID(string chfid) + public FamilyModel GetByCHFID(string chfid, int userId) { FamilyModel response = new FamilyModel(); @@ -37,8 +37,28 @@ public FamilyModel GetByCHFID(string chfid) { using (var imisContext = new ImisDB()) { + var locationIds = imisContext.TblUsersDistricts + .Where(d => d.UserId == userId && d.ValidityTo == null) + .Select(x => x.LocationId).ToList(); + + var familyId = (from item in locationIds + from I in imisContext.TblInsuree + join F in imisContext.TblFamilies on I.FamilyId equals F.FamilyId + join V in imisContext.TblVillages on F.LocationId equals V.VillageId + join W in imisContext.TblWards on V.WardId equals W.WardId + join D in imisContext.TblDistricts on W.DistrictId equals D.DistrictId + where (I.Chfid == chfid + && D.DistrictId == item + && F.ValidityTo == null + && I.ValidityTo == null + && V.ValidityTo == null + && W.ValidityTo == null + && D.ValidityTo == null) + select F.FamilyId) + .FirstOrDefault(); + response = imisContext.TblInsuree - .Where(i => i.ValidityTo == null && i.Chfid == chfid) + .Where(i => i.ValidityTo == null && i.FamilyId == familyId) .Join(imisContext.TblFamilies, i => i.FamilyId, f => f.FamilyId, (i, f) => f) .Where(f => f.ValidityTo == null) .Include(f => f.TblInsuree) diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/IFamilyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/IFamilyRepository.cs index 25176e23..b3f0f6a0 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/IFamilyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/IFamilyRepository.cs @@ -6,7 +6,7 @@ namespace OpenImis.ModulesV2.InsureeModule.Repositories { public interface IFamilyRepository { - FamilyModel GetByCHFID(string chfid); + FamilyModel GetByCHFID(string chfid, int userId); int Create(EnrollFamilyModel model, int userId, int officerId); int GetUserIdByUUID(Guid uuid); int GetOfficerIdByUserId(int userId); diff --git a/OpenImis.RestApi/Controllers/V2/FamilyController.cs b/OpenImis.RestApi/Controllers/V2/FamilyController.cs index 9f418b0e..03a4b8f8 100644 --- a/OpenImis.RestApi/Controllers/V2/FamilyController.cs +++ b/OpenImis.RestApi/Controllers/V2/FamilyController.cs @@ -33,7 +33,10 @@ public IActionResult GetByCHFID(string chfid) try { - familyModel = _imisModules.GetInsureeModule().GetFamilyLogic().GetByCHFID(chfid); + Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); + int userId = _imisModules.GetInsureeModule().GetFamilyLogic().GetUserIdByUUID(userUUID); + + familyModel = _imisModules.GetInsureeModule().GetFamilyLogic().GetByCHFID(chfid, userId); } catch (ValidationException e) { From 80c1d4e387e56bc56378a88a0aeb9cfe0d450274 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Mon, 12 Aug 2019 14:47:17 +0200 Subject: [PATCH 35/86] OS-54: Added support for new modules --- .../FeedbackModule/FeedbackModule.cs | 31 +++++++ .../FeedbackModule/IFeedbackModule.cs | 10 +++ .../FeedbackModule/Logic/FeedbackLogic.cs | 14 +++ .../FeedbackModule/Logic/IFeedbackLogic.cs | 8 ++ OpenImis.ModulesV2/ImisModules.cs | 90 +++++++++++++++++-- .../MasterDataModule/IMasterDataModule.cs | 10 +++ .../Logic/IMasterDataLogic.cs | 8 ++ .../MasterDataModule/Logic/MasterDataLogic.cs | 14 +++ .../MasterDataModule/MasterDataModule.cs | 31 +++++++ .../PremiumModule/IPremiumModule.cs | 10 +++ .../PremiumModule/Logic/IPremiumLogic.cs | 8 ++ .../PremiumModule/Logic/PremiumLogic.cs | 14 +++ .../PremiumModule/PremiumModule.cs | 31 +++++++ .../SystemModule/ISystemModule.cs | 10 +++ .../SystemModule/Logic/ISystemLogic.cs | 8 ++ .../SystemModule/Logic/SystemLogic.cs | 14 +++ .../SystemModule/SystemModule.cs | 31 +++++++ OpenImis.RestApi/openImisModules.json | 12 +++ 18 files changed, 349 insertions(+), 5 deletions(-) create mode 100644 OpenImis.ModulesV2/FeedbackModule/FeedbackModule.cs create mode 100644 OpenImis.ModulesV2/FeedbackModule/IFeedbackModule.cs create mode 100644 OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs create mode 100644 OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/IMasterDataModule.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Logic/IMasterDataLogic.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Logic/MasterDataLogic.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/MasterDataModule.cs create mode 100644 OpenImis.ModulesV2/PremiumModule/IPremiumModule.cs create mode 100644 OpenImis.ModulesV2/PremiumModule/Logic/IPremiumLogic.cs create mode 100644 OpenImis.ModulesV2/PremiumModule/Logic/PremiumLogic.cs create mode 100644 OpenImis.ModulesV2/PremiumModule/PremiumModule.cs create mode 100644 OpenImis.ModulesV2/SystemModule/ISystemModule.cs create mode 100644 OpenImis.ModulesV2/SystemModule/Logic/ISystemLogic.cs create mode 100644 OpenImis.ModulesV2/SystemModule/Logic/SystemLogic.cs create mode 100644 OpenImis.ModulesV2/SystemModule/SystemModule.cs diff --git a/OpenImis.ModulesV2/FeedbackModule/FeedbackModule.cs b/OpenImis.ModulesV2/FeedbackModule/FeedbackModule.cs new file mode 100644 index 00000000..3c0a022d --- /dev/null +++ b/OpenImis.ModulesV2/FeedbackModule/FeedbackModule.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.FeedbackModule.Logic; + +namespace OpenImis.ModulesV2.FeedbackModule +{ + public class FeedbackModule : IFeedbackModule + { + private IConfiguration _configuration; + private IFeedbackLogic _feedbackLogic; + + public FeedbackModule(IConfiguration configuration) + { + _configuration = configuration; + } + + public IFeedbackLogic GetFeedbackLogic() + { + if (_feedbackLogic == null) + { + _feedbackLogic = new FeedbackLogic(_configuration); + } + return _feedbackLogic; + } + + public IFeedbackModule SetFeedbackLogic(IFeedbackLogic feedbackLogic) + { + _feedbackLogic = feedbackLogic; + return this; + } + } +} diff --git a/OpenImis.ModulesV2/FeedbackModule/IFeedbackModule.cs b/OpenImis.ModulesV2/FeedbackModule/IFeedbackModule.cs new file mode 100644 index 00000000..ccd90b35 --- /dev/null +++ b/OpenImis.ModulesV2/FeedbackModule/IFeedbackModule.cs @@ -0,0 +1,10 @@ +using OpenImis.ModulesV2.FeedbackModule.Logic; + +namespace OpenImis.ModulesV2.FeedbackModule +{ + public interface IFeedbackModule + { + IFeedbackLogic GetFeedbackLogic(); + IFeedbackModule SetFeedbackLogic(IFeedbackLogic feedbackLogic); + } +} diff --git a/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs b/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs new file mode 100644 index 00000000..23f180fc --- /dev/null +++ b/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs @@ -0,0 +1,14 @@ +using Microsoft.Extensions.Configuration; + +namespace OpenImis.ModulesV2.FeedbackModule.Logic +{ + public class FeedbackLogic: IFeedbackLogic + { + private IConfiguration _configuration; + + public FeedbackLogic(IConfiguration configuration) + { + _configuration = configuration; + } + } +} diff --git a/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs b/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs new file mode 100644 index 00000000..59f047b4 --- /dev/null +++ b/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs @@ -0,0 +1,8 @@ +using System; + +namespace OpenImis.ModulesV2.FeedbackModule.Logic +{ + public interface IFeedbackLogic + { + } +} diff --git a/OpenImis.ModulesV2/ImisModules.cs b/OpenImis.ModulesV2/ImisModules.cs index 8b30f724..0269d080 100644 --- a/OpenImis.ModulesV2/ImisModules.cs +++ b/OpenImis.ModulesV2/ImisModules.cs @@ -1,5 +1,8 @@ -using System.Reflection; -using System; +using System; +using System.Linq; +using System.Reflection; +using OpenImis.ModulesV2.Helpers; +using System.Collections.Generic; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -8,9 +11,10 @@ using OpenImis.ModulesV2.InsureeModule; using OpenImis.ModulesV2.CoverageModule; using OpenImis.ModulesV2.PaymentModule; -using OpenImis.ModulesV2.Helpers; -using System.Collections.Generic; -using System.Linq; +using OpenImis.ModulesV2.FeedbackModule; +using OpenImis.ModulesV2.MasterDataModule; +using OpenImis.ModulesV2.PremiumModule; +using OpenImis.ModulesV2.SystemModule; namespace OpenImis.ModulesV2 { @@ -22,6 +26,10 @@ public class ImisModules : IImisModules private IClaimModule claimModule; private ICoverageModule coverageModule; private IPaymentModule paymentModule; + private IFeedbackModule feedbackModule; + private IMasterDataModule masterDataModule; + private IPremiumModule premiumModule; + private ISystemModule systemModule; private readonly IConfiguration _configuration; private readonly ILogger _logger; @@ -130,6 +138,78 @@ public IPaymentModule GetPaymentModule() return paymentModule; } + /// + /// Creates and returns the feedback module version 2. + /// + /// + /// The Feedback module V2. + /// + public IFeedbackModule GetFeedbackModule() + { + if (feedbackModule == null) + { + feedbackModule = new FeedbackModule.FeedbackModule(_configuration); + + Type feedbackLogicType = CreateTypeFromConfiguration("FeedbackModule", "FeedbackLogic", "OpenImis.ModulesV2.FeedbackModule.Logic.FeedbackLogic"); + feedbackModule.SetFeedbackLogic((FeedbackModule.Logic.IFeedbackLogic)ActivatorUtilities.CreateInstance(_serviceProvider, feedbackLogicType)); + } + return feedbackModule; + } + + /// + /// Creates and returns the premium module version 2. + /// + /// + /// The Premium module V2. + /// + public IPremiumModule GetPremiumModule() + { + if (premiumModule == null) + { + premiumModule = new PremiumModule.PremiumModule(_configuration); + + Type premiumLogicType = CreateTypeFromConfiguration("PremiumModule", "PremiumLogic", "OpenImis.ModulesV2.PremiumModule.Logic.PremiumLogic"); + premiumModule.SetPremiumLogic((PremiumModule.Logic.IPremiumLogic)ActivatorUtilities.CreateInstance(_serviceProvider, premiumLogicType)); + } + return premiumModule; + } + + /// + /// Creates and returns the system module version 2. + /// + /// + /// The System module V2. + /// + public ISystemModule GetSystemModule() + { + if (systemModule == null) + { + systemModule = new SystemModule.SystemModule(_configuration); + + Type systemLogicType = CreateTypeFromConfiguration("SystemModule", "SystemLogic", "OpenImis.ModulesV2.SystemModule.Logic.SystemLogic"); + systemModule.SetSystemLogic((SystemModule.Logic.ISystemLogic)ActivatorUtilities.CreateInstance(_serviceProvider, systemLogicType)); + } + return systemModule; + } + + /// + /// Creates and returns the master data module version 2. + /// + /// + /// The MasterData module V2. + /// + public IMasterDataModule GetMasterDataModule() + { + if (masterDataModule == null) + { + masterDataModule = new MasterDataModule.MasterDataModule(_configuration); + + Type masterDataLogicType = CreateTypeFromConfiguration("MasterDataModule", "MasterDataLogic", "OpenImis.ModulesV2.MasterDataModule.Logic.MasterDataLogic"); + masterDataModule.SetMasterDataLogic((MasterDataModule.Logic.IMasterDataLogic)ActivatorUtilities.CreateInstance(_serviceProvider, masterDataLogicType)); + } + return masterDataModule; + } + /// /// Creates and returns the type based on the string from the configuration /// diff --git a/OpenImis.ModulesV2/MasterDataModule/IMasterDataModule.cs b/OpenImis.ModulesV2/MasterDataModule/IMasterDataModule.cs new file mode 100644 index 00000000..e93d1a1e --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/IMasterDataModule.cs @@ -0,0 +1,10 @@ +using OpenImis.ModulesV2.MasterDataModule.Logic; + +namespace OpenImis.ModulesV2.MasterDataModule +{ + public interface IMasterDataModule + { + IMasterDataLogic GetMasterDataLogic(); + IMasterDataModule SetMasterDataLogic(IMasterDataLogic masterDataLogic); + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Logic/IMasterDataLogic.cs b/OpenImis.ModulesV2/MasterDataModule/Logic/IMasterDataLogic.cs new file mode 100644 index 00000000..88fe4d0d --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Logic/IMasterDataLogic.cs @@ -0,0 +1,8 @@ +using System; + +namespace OpenImis.ModulesV2.MasterDataModule.Logic +{ + public interface IMasterDataLogic + { + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Logic/MasterDataLogic.cs b/OpenImis.ModulesV2/MasterDataModule/Logic/MasterDataLogic.cs new file mode 100644 index 00000000..c4f04325 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Logic/MasterDataLogic.cs @@ -0,0 +1,14 @@ +using Microsoft.Extensions.Configuration; + +namespace OpenImis.ModulesV2.MasterDataModule.Logic +{ + public class MasterDataLogic : IMasterDataLogic + { + private IConfiguration _configuration; + + public MasterDataLogic(IConfiguration configuration) + { + _configuration = configuration; + } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/MasterDataModule.cs b/OpenImis.ModulesV2/MasterDataModule/MasterDataModule.cs new file mode 100644 index 00000000..7af23483 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/MasterDataModule.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.MasterDataModule.Logic; + +namespace OpenImis.ModulesV2.MasterDataModule +{ + public class MasterDataModule : IMasterDataModule + { + private IConfiguration _configuration; + private IMasterDataLogic _masterDataLogic; + + public MasterDataModule(IConfiguration configuration) + { + _configuration = configuration; + } + + public IMasterDataLogic GetMasterDataLogic() + { + if (_masterDataLogic == null) + { + _masterDataLogic = new MasterDataLogic(_configuration); + } + return _masterDataLogic; + } + + public IMasterDataModule SetMasterDataLogic(IMasterDataLogic masterDataLogic) + { + _masterDataLogic = masterDataLogic; + return this; + } + } +} diff --git a/OpenImis.ModulesV2/PremiumModule/IPremiumModule.cs b/OpenImis.ModulesV2/PremiumModule/IPremiumModule.cs new file mode 100644 index 00000000..5a36deb2 --- /dev/null +++ b/OpenImis.ModulesV2/PremiumModule/IPremiumModule.cs @@ -0,0 +1,10 @@ +using OpenImis.ModulesV2.PremiumModule.Logic; + +namespace OpenImis.ModulesV2.PremiumModule +{ + public interface IPremiumModule + { + IPremiumLogic GetPremiumLogic(); + IPremiumModule SetPremiumLogic(IPremiumLogic premiumLogic); + } +} diff --git a/OpenImis.ModulesV2/PremiumModule/Logic/IPremiumLogic.cs b/OpenImis.ModulesV2/PremiumModule/Logic/IPremiumLogic.cs new file mode 100644 index 00000000..4d57dd43 --- /dev/null +++ b/OpenImis.ModulesV2/PremiumModule/Logic/IPremiumLogic.cs @@ -0,0 +1,8 @@ +using System; + +namespace OpenImis.ModulesV2.PremiumModule.Logic +{ + public interface IPremiumLogic + { + } +} diff --git a/OpenImis.ModulesV2/PremiumModule/Logic/PremiumLogic.cs b/OpenImis.ModulesV2/PremiumModule/Logic/PremiumLogic.cs new file mode 100644 index 00000000..4b36a09d --- /dev/null +++ b/OpenImis.ModulesV2/PremiumModule/Logic/PremiumLogic.cs @@ -0,0 +1,14 @@ +using Microsoft.Extensions.Configuration; + +namespace OpenImis.ModulesV2.PremiumModule.Logic +{ + public class PremiumLogic : IPremiumLogic + { + private IConfiguration _configuration; + + public PremiumLogic(IConfiguration configuration) + { + _configuration = configuration; + } + } +} diff --git a/OpenImis.ModulesV2/PremiumModule/PremiumModule.cs b/OpenImis.ModulesV2/PremiumModule/PremiumModule.cs new file mode 100644 index 00000000..988b5d3b --- /dev/null +++ b/OpenImis.ModulesV2/PremiumModule/PremiumModule.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.PremiumModule.Logic; + +namespace OpenImis.ModulesV2.PremiumModule +{ + public class PremiumModule : IPremiumModule + { + private IConfiguration _configuration; + private IPremiumLogic _premiumLogic; + + public PremiumModule(IConfiguration configuration) + { + _configuration = configuration; + } + + public IPremiumLogic GetPremiumLogic() + { + if (_premiumLogic == null) + { + _premiumLogic = new PremiumLogic(_configuration); + } + return _premiumLogic; + } + + public IPremiumModule SetPremiumLogic(IPremiumLogic premiumLogic) + { + _premiumLogic = premiumLogic; + return this; + } + } +} diff --git a/OpenImis.ModulesV2/SystemModule/ISystemModule.cs b/OpenImis.ModulesV2/SystemModule/ISystemModule.cs new file mode 100644 index 00000000..3b57c0ae --- /dev/null +++ b/OpenImis.ModulesV2/SystemModule/ISystemModule.cs @@ -0,0 +1,10 @@ +using OpenImis.ModulesV2.SystemModule.Logic; + +namespace OpenImis.ModulesV2.SystemModule +{ + public interface ISystemModule + { + ISystemLogic GetSystemLogic(); + ISystemModule SetSystemLogic(ISystemLogic systemLogic); + } +} diff --git a/OpenImis.ModulesV2/SystemModule/Logic/ISystemLogic.cs b/OpenImis.ModulesV2/SystemModule/Logic/ISystemLogic.cs new file mode 100644 index 00000000..aa7670cd --- /dev/null +++ b/OpenImis.ModulesV2/SystemModule/Logic/ISystemLogic.cs @@ -0,0 +1,8 @@ +using System; + +namespace OpenImis.ModulesV2.SystemModule.Logic +{ + public interface ISystemLogic + { + } +} diff --git a/OpenImis.ModulesV2/SystemModule/Logic/SystemLogic.cs b/OpenImis.ModulesV2/SystemModule/Logic/SystemLogic.cs new file mode 100644 index 00000000..1502327a --- /dev/null +++ b/OpenImis.ModulesV2/SystemModule/Logic/SystemLogic.cs @@ -0,0 +1,14 @@ +using Microsoft.Extensions.Configuration; + +namespace OpenImis.ModulesV2.SystemModule.Logic +{ + public class SystemLogic : ISystemLogic + { + private IConfiguration _configuration; + + public SystemLogic(IConfiguration configuration) + { + _configuration = configuration; + } + } +} diff --git a/OpenImis.ModulesV2/SystemModule/SystemModule.cs b/OpenImis.ModulesV2/SystemModule/SystemModule.cs new file mode 100644 index 00000000..d80d2e05 --- /dev/null +++ b/OpenImis.ModulesV2/SystemModule/SystemModule.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.SystemModule.Logic; + +namespace OpenImis.ModulesV2.SystemModule +{ + public class SystemModule : ISystemModule + { + private IConfiguration _configuration; + private ISystemLogic _systemLogic; + + public SystemModule(IConfiguration configuration) + { + _configuration = configuration; + } + + public ISystemLogic GetSystemLogic() + { + if (_systemLogic == null) + { + _systemLogic = new SystemLogic(_configuration); + } + return _systemLogic; + } + + public ISystemModule SetSystemLogic(ISystemLogic systemLogic) + { + _systemLogic = systemLogic; + return this; + } + } +} diff --git a/OpenImis.RestApi/openImisModules.json b/OpenImis.RestApi/openImisModules.json index 1dc493ef..17444b67 100644 --- a/OpenImis.RestApi/openImisModules.json +++ b/OpenImis.RestApi/openImisModules.json @@ -38,6 +38,18 @@ }, "PaymentModule": { "PaymentLogic": "OpenImis.ModulesV2.PaymentModule.Logic.PaymentLogic" + }, + "FeedbackModule": { + "FeedbackLogic": "OpenImis.ModulesV2.FeedbackModule.Logic.FeedbackLogic" + }, + "PremiumModule": { + "PremiumLogic": "OpenImis.ModulesV2.PremiumModule.Logic.PremiumLogic" + }, + "SystemModule": { + "SystemLogic": "OpenImis.ModulesV2.SystemModule.Logic.SystemLogic" + }, + "MasterDataModule": { + "MasterDataLogic": "OpenImis.ModulesV2.MasterDataModule.Logic.MasterDataLogic" } } ] From 4fb66836046cd6229df25f1e78a310a07fb7c2f1 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Tue, 20 Aug 2019 10:01:01 +0200 Subject: [PATCH 36/86] OS-37: Changed Rights --- OpenImis.RestApi/Controllers/V2/FamilyController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenImis.RestApi/Controllers/V2/FamilyController.cs b/OpenImis.RestApi/Controllers/V2/FamilyController.cs index 03a4b8f8..aa6ec878 100644 --- a/OpenImis.RestApi/Controllers/V2/FamilyController.cs +++ b/OpenImis.RestApi/Controllers/V2/FamilyController.cs @@ -24,7 +24,7 @@ public FamilyController(IImisModules imisModules) _imisModules = imisModules; } - //[HasRights(Rights.FamilyAdd)] + [HasRights(Rights.FamilySearch)] [HttpGet] [Route("{chfid}")] public IActionResult GetByCHFID(string chfid) @@ -51,7 +51,7 @@ public IActionResult GetByCHFID(string chfid) return Ok(familyModel); } - //[HasRights(Rights.FamilyAdd)] + [HasRights(Rights.FamilyAdd)] [HttpPost] public IActionResult Create([FromBody] EnrollFamilyModel model) { From 3f83e72bc6b31f08c6b404e06459149dcbd80173 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 21 Aug 2019 10:05:55 +0200 Subject: [PATCH 37/86] OS-37: Fixed comments --- OpenImis.ModulesV2/Helpers/Extensions.cs | 2 +- .../InsureeModule/Logic/FamilyLogic.cs | 8 ++--- .../InsureeModule/Logic/IFamilyLogic.cs | 4 +-- .../EnrollFamilyModels/EnrollFamilyModel.cs | 13 ++++---- .../Repositories/FamilyRepository.cs | 31 ++++++++++++------- .../Repositories/IFamilyRepository.cs | 4 +-- .../LoginModule/Logic/ILoginLogic.cs | 3 +- .../LoginModule/Logic/LoginLogic.cs | 4 +-- .../Repositories/ILoginRepository.cs | 2 +- .../Repositories/LoginRepository.cs | 4 +-- .../Controllers/V2/FamilyController.cs | 5 ++- .../Security/IMISJwtSecurityTokenHandler.cs | 3 +- 12 files changed, 46 insertions(+), 37 deletions(-) diff --git a/OpenImis.ModulesV2/Helpers/Extensions.cs b/OpenImis.ModulesV2/Helpers/Extensions.cs index cbd0615a..7fe94376 100644 --- a/OpenImis.ModulesV2/Helpers/Extensions.cs +++ b/OpenImis.ModulesV2/Helpers/Extensions.cs @@ -9,7 +9,7 @@ namespace OpenImis.ModulesV2.Helpers { public static class Extensions { - public static string Serialize(this T value) + public static string XMLSerialize(this T value) { if (value == null) { diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs index ceb8d53b..6b261904 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/FamilyLogic.cs @@ -22,11 +22,11 @@ public FamilyLogic(IConfiguration configuration, IHostingEnvironment hostingEnvi familyRepository = new FamilyRepository(_configuration, _hostingEnvironment); } - public FamilyModel GetByCHFID(string chfid, int userId) + public FamilyModel GetByCHFID(string chfid, Guid userUUID) { FamilyModel response; - response = familyRepository.GetByCHFID(chfid, userId); + response = familyRepository.GetByCHFID(chfid, userUUID); return response; } @@ -49,11 +49,11 @@ public int GetUserIdByUUID(Guid uuid) return response; } - public int GetOfficerIdByUserId(int userId) + public int GetOfficerIdByUserUUID(Guid userUUID) { int response; - response = familyRepository.GetOfficerIdByUserId(userId); + response = familyRepository.GetOfficerIdByUserUUID(userUUID); return response; } diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs index e498f6d3..6c730cf3 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/IFamilyLogic.cs @@ -6,9 +6,9 @@ namespace OpenImis.ModulesV2.InsureeModule.Logic { public interface IFamilyLogic { - FamilyModel GetByCHFID(string chfid, int userId); + FamilyModel GetByCHFID(string chfid, Guid userUUID); int Create(EnrollFamilyModel model, int userId, int officerId); int GetUserIdByUUID(Guid uuid); - int GetOfficerIdByUserId(int userId); + int GetOfficerIdByUserUUID(Guid userUUID); } } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs index fd78195c..16c91995 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs @@ -13,16 +13,17 @@ public class EnrollFamilyModel public List InsureePolicy { get; set; } public List Pictures { get; set; } - public Enrolment GetEnrolmentFromModel() + + public static explicit operator Enrolment(EnrollFamilyModel efm) { return new Enrolment() { FileInfo = new FileInfo(), - Families = Family, - Insurees = Insuree, - Policies = Policy, - Premiums = Premium, - InsureePolicies = InsureePolicy + Families = efm.Family, + Insurees = efm.Insuree, + Policies = efm.Policy, + Premiums = efm.Premium, + InsureePolicies = efm.InsureePolicy }; } } diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs index f383f5f9..ec060c5a 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs @@ -15,6 +15,7 @@ using System.IO; using Microsoft.AspNetCore.Hosting; using System.Xml; +using Newtonsoft.Json; namespace OpenImis.ModulesV2.InsureeModule.Repositories { @@ -29,7 +30,7 @@ public FamilyRepository(IConfiguration configuration, IHostingEnvironment hostin _hostingEnvironment = hostingEnvironment; } - public FamilyModel GetByCHFID(string chfid, int userId) + public FamilyModel GetByCHFID(string chfid, Guid userUUID) { FamilyModel response = new FamilyModel(); @@ -37,9 +38,11 @@ public FamilyModel GetByCHFID(string chfid, int userId) { using (var imisContext = new ImisDB()) { - var locationIds = imisContext.TblUsersDistricts - .Where(d => d.UserId == userId && d.ValidityTo == null) - .Select(x => x.LocationId).ToList(); + var locationIds = (from UD in imisContext.TblUsersDistricts + join U in imisContext.TblUsers on UD.UserId equals U.UserId + where U.UserUUID == userUUID && UD.ValidityTo == null + select UD.LocationId) + .ToList(); var familyId = (from item in locationIds from I in imisContext.TblInsuree @@ -90,7 +93,13 @@ public int Create(EnrollFamilyModel model, int userId, int officerId) { string webRootPath = _hostingEnvironment.WebRootPath; - var XML = model.GetEnrolmentFromModel().Serialize(); + var enrollFamily = (Enrolment)model; + + enrollFamily.FileInfo.UserId = userId; + enrollFamily.FileInfo.OfficerId = officerId; + + var XML = enrollFamily.XMLSerialize(); + var JSON = JsonConvert.SerializeObject(enrollFamily); var EnrollmentDir = _configuration["AppSettings:Enrollment_Phone"]; var JsonDebugFolder = _configuration["AppSettings:JsonDebugFolder"]; @@ -105,8 +114,8 @@ public int Create(EnrollFamilyModel model, int userId, int officerId) } else hof = "Unknown"; - var FileName = string.Format("{0}_{1}_{2}.xml", hof, officerId.ToString(), DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss.XML")); - var JsonFileName = string.Format("{0}_{1}_{2}.xml", hof, officerId.ToString(), DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")); + var FileName = string.Format("{0}__{1}_{2}.XML.xml", hof, officerId.ToString(), DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss.XML")); + var JsonFileName = string.Format("{0}_{1}_{2}.json", hof, officerId.ToString(), DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")); var xmldoc = new XmlDocument(); @@ -120,7 +129,7 @@ public int Create(EnrollFamilyModel model, int userId, int officerId) if (!Directory.Exists(webRootPath + JsonDebugFolder)) Directory.CreateDirectory(webRootPath + JsonDebugFolder); - File.WriteAllText(webRootPath + JsonDebugFolder + JsonFileName, XML); + File.WriteAllText(webRootPath + JsonDebugFolder + JsonFileName, JSON); } catch (Exception e) { @@ -243,7 +252,7 @@ public int GetUserIdByUUID(Guid uuid) } } - public int GetOfficerIdByUserId(int userId) + public int GetOfficerIdByUserUUID(Guid userUUID) { int response; @@ -252,7 +261,7 @@ public int GetOfficerIdByUserId(int userId) using (var imisContext = new ImisDB()) { var loginName = imisContext.TblUsers - .Where(u => u.UserId == userId) + .Where(u => u.UserUUID == userUUID) .Select(x => x.LoginName) .FirstOrDefault(); @@ -270,4 +279,4 @@ public int GetOfficerIdByUserId(int userId) } } } -} +} \ No newline at end of file diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/IFamilyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/IFamilyRepository.cs index b3f0f6a0..23ae42f0 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/IFamilyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/IFamilyRepository.cs @@ -6,9 +6,9 @@ namespace OpenImis.ModulesV2.InsureeModule.Repositories { public interface IFamilyRepository { - FamilyModel GetByCHFID(string chfid, int userId); + FamilyModel GetByCHFID(string chfid, Guid userUUID); int Create(EnrollFamilyModel model, int userId, int officerId); int GetUserIdByUUID(Guid uuid); - int GetOfficerIdByUserId(int userId); + int GetOfficerIdByUserUUID(Guid userUUID); } } diff --git a/OpenImis.ModulesV2/LoginModule/Logic/ILoginLogic.cs b/OpenImis.ModulesV2/LoginModule/Logic/ILoginLogic.cs index bb8e8a4d..7bf18a76 100644 --- a/OpenImis.ModulesV2/LoginModule/Logic/ILoginLogic.cs +++ b/OpenImis.ModulesV2/LoginModule/Logic/ILoginLogic.cs @@ -1,10 +1,11 @@ using OpenImis.ModulesV2.LoginModule.Models; +using System; namespace OpenImis.ModulesV2.LoginModule.Logic { public interface ILoginLogic { - UserData GetById(int userId); + UserData GetByUUID(Guid userUUID); UserData FindUser(string UserName, string Password); } } diff --git a/OpenImis.ModulesV2/LoginModule/Logic/LoginLogic.cs b/OpenImis.ModulesV2/LoginModule/Logic/LoginLogic.cs index dbbb4a8a..80b70957 100644 --- a/OpenImis.ModulesV2/LoginModule/Logic/LoginLogic.cs +++ b/OpenImis.ModulesV2/LoginModule/Logic/LoginLogic.cs @@ -23,9 +23,9 @@ public LoginLogic(IConfiguration configuration) loginRepository = new LoginRepository(_configuration); } - public UserData GetById(int userId) + public UserData GetByUUID(Guid userUUID) { - return loginRepository.GetById(userId); + return loginRepository.GetByUUID(userUUID); } public UserData FindUser(string UserName, string Password) diff --git a/OpenImis.ModulesV2/LoginModule/Repositories/ILoginRepository.cs b/OpenImis.ModulesV2/LoginModule/Repositories/ILoginRepository.cs index 84cd8062..ccf4f186 100644 --- a/OpenImis.ModulesV2/LoginModule/Repositories/ILoginRepository.cs +++ b/OpenImis.ModulesV2/LoginModule/Repositories/ILoginRepository.cs @@ -8,7 +8,7 @@ namespace OpenImis.ModulesV2.LoginModule.Repositories { public interface ILoginRepository { - UserData GetById(int userId); + UserData GetByUUID(Guid userUUID); List FindUserByName(string UserName); } } diff --git a/OpenImis.ModulesV2/LoginModule/Repositories/LoginRepository.cs b/OpenImis.ModulesV2/LoginModule/Repositories/LoginRepository.cs index 8c74ed01..2a5bb28c 100644 --- a/OpenImis.ModulesV2/LoginModule/Repositories/LoginRepository.cs +++ b/OpenImis.ModulesV2/LoginModule/Repositories/LoginRepository.cs @@ -16,12 +16,12 @@ public LoginRepository(IConfiguration configuration) Configuration = configuration; } - public UserData GetById(int userId) + public UserData GetByUUID(Guid userUUID) { UserData user; using (var imisContext = new ImisDB()) { - user = imisContext.TblUsers.Where(u => u.UserId == userId).Select(x => new UserData() + user = imisContext.TblUsers.Where(u => u.UserUUID == userUUID).Select(x => new UserData() { UserUUID = x.UserUUID, LoginName = x.LoginName, diff --git a/OpenImis.RestApi/Controllers/V2/FamilyController.cs b/OpenImis.RestApi/Controllers/V2/FamilyController.cs index aa6ec878..d1c83455 100644 --- a/OpenImis.RestApi/Controllers/V2/FamilyController.cs +++ b/OpenImis.RestApi/Controllers/V2/FamilyController.cs @@ -34,9 +34,8 @@ public IActionResult GetByCHFID(string chfid) try { Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); - int userId = _imisModules.GetInsureeModule().GetFamilyLogic().GetUserIdByUUID(userUUID); - familyModel = _imisModules.GetInsureeModule().GetFamilyLogic().GetByCHFID(chfid, userId); + familyModel = _imisModules.GetInsureeModule().GetFamilyLogic().GetByCHFID(chfid, userUUID); } catch (ValidationException e) { @@ -62,7 +61,7 @@ public IActionResult Create([FromBody] EnrollFamilyModel model) Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); int userId = _imisModules.GetInsureeModule().GetFamilyLogic().GetUserIdByUUID(userUUID); - int officerId = _imisModules.GetInsureeModule().GetFamilyLogic().GetOfficerIdByUserId(userId); + int officerId = _imisModules.GetInsureeModule().GetFamilyLogic().GetOfficerIdByUserUUID(userUUID); response = _imisModules.GetInsureeModule().GetFamilyLogic().Create(model, userId, officerId); } diff --git a/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs b/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs index 5596f061..83e33ab6 100644 --- a/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs +++ b/OpenImis.RestApi/Security/IMISJwtSecurityTokenHandler.cs @@ -80,9 +80,8 @@ public ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParame if (apiVersion == null || apiVersion.StartsWith("2")) { Guid userUUID = Guid.Parse(tokenS.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); - int userId = _imisModulesV2.GetInsureeModule().GetFamilyLogic().GetUserIdByUUID(userUUID); - user = (UserData)_imisModulesV2.GetLoginModule().GetLoginLogic().GetById(userId); + user = (UserData)_imisModulesV2.GetLoginModule().GetLoginLogic().GetByUUID(userUUID); } else { From 9c79d46e0a07ad6c41f0a224a228e54b485e7c5b Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 21 Aug 2019 15:02:58 +0200 Subject: [PATCH 38/86] OS-37: Added new Family Model --- .../EnrollFamilyModels/EnrollFamilyModel.cs | 33 ++++++++++++------- .../Models/EnrollFamilyModels/Family.cs | 3 ++ .../Models/EnrollFamilyModels/Insuree.cs | 1 + .../Models/EnrollFamilyModels/Policy.cs | 1 + .../Repositories/FamilyRepository.cs | 6 ++-- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs index 16c91995..58aebf1c 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; namespace OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels @@ -7,23 +8,33 @@ namespace OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels public class EnrollFamilyModel { public List Family { get; set; } - public List Insuree { get; set; } - public List Policy { get; set; } - public List Premium { get; set; } - public List InsureePolicy { get; set; } - public List Pictures { get; set; } - public static explicit operator Enrolment(EnrollFamilyModel efm) { return new Enrolment() { FileInfo = new FileInfo(), - Families = efm.Family, - Insurees = efm.Insuree, - Policies = efm.Policy, - Premiums = efm.Premium, - InsureePolicies = efm.InsureePolicy + Families = efm.Family.Select(x => new List() + { + new Family() + { + FamilyId = x.FamilyId, + InsureeId = x.InsureeId, + LocationId = x.LocationId, + HOFCHFID = x.HOFCHFID, + Poverty = x.Poverty, + FamilyType = x.FamilyType, + FamilyAddress = x.FamilyAddress, + Ethnicity = x.Ethnicity, + ConfirmationNo = x.ConfirmationNo, + ConfirmationType = x.ConfirmationType, + isOffline = x.isOffline + } + }).FirstOrDefault(), + Insurees = efm.Family.Select(x => x.Insurees).FirstOrDefault().ToList(), + Policies = efm.Family.Select(x => x.Policies).FirstOrDefault().ToList(), + Premiums = efm.Family.Select(x => x.Policies.Select(s => s.Premium)).FirstOrDefault().ToList(), + InsureePolicies = efm.Family.Select(x => x.InsureePolicy).FirstOrDefault().ToList(), }; } } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Family.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Family.cs index e96754ee..a6ce5c21 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Family.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Family.cs @@ -17,5 +17,8 @@ public class Family public string ConfirmationNo { get; set; } public string ConfirmationType { get; set; } public bool isOffline { get; set; } + public List Insurees { get; set; } + public List Policies { get; set; } + public List InsureePolicy { get; set; } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs index c85b120c..789f7632 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs @@ -30,5 +30,6 @@ public class Insuree public int CurVillage { get; set; } public bool isOffline { get; set; } public DateTime EffectiveDate { get; set; } + public InsureeImage Picture { get; set; } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Policy.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Policy.cs index 648e2833..c8801d82 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Policy.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Policy.cs @@ -18,5 +18,6 @@ public class Policy public int OfficerId { get; set; } public int PolicyStage { get; set; } public bool isOffline { get; set; } + public Premium Premium { get; set; } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs index ec060c5a..e3a7cbbe 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs @@ -108,9 +108,9 @@ public int Create(EnrollFamilyModel model, int userId, int officerId) var hof = ""; - if (model.Insuree.Any(x => x.isHead == "true" || x.isHead == "1")) + if (enrollFamily.Insurees.Any(x => x.isHead == "true" || x.isHead == "1")) { - hof = model.Insuree.Where(x => x.isHead == "true" || x.isHead == "1").Select(z => z.CHFID).FirstOrDefault(); + hof = enrollFamily.Insurees.Where(x => x.isHead == "true" || x.isHead == "1").Select(z => z.CHFID).FirstOrDefault(); } else hof = "Unknown"; @@ -202,7 +202,7 @@ public int Create(EnrollFamilyModel model, int userId, int officerId) Directory.CreateDirectory(webRootPath + UpdatedFolder); } - foreach (var picture in model.Pictures) + foreach (var picture in model.Family.Select(x => x.Insurees.Select(s => s.Picture)).FirstOrDefault().ToList()) { if (picture != null) { From b53acbef82afc9ccb03aaae30e9f5913391ca74a Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 22 Aug 2019 09:07:17 +0200 Subject: [PATCH 39/86] OS-37: Fixed changes from comments --- .../Models/EnrollFamilyModels/EnrollFamilyModel.cs | 12 ++++++------ .../InsureeModule/Repositories/FamilyRepository.cs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs index 58aebf1c..3df41ded 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/EnrollFamilyModel.cs @@ -9,12 +9,12 @@ public class EnrollFamilyModel { public List Family { get; set; } - public static explicit operator Enrolment(EnrollFamilyModel efm) + public Enrolment GetEnrolmentFromModel() { return new Enrolment() { FileInfo = new FileInfo(), - Families = efm.Family.Select(x => new List() + Families = Family.Select(x => new List() { new Family() { @@ -31,10 +31,10 @@ public static explicit operator Enrolment(EnrollFamilyModel efm) isOffline = x.isOffline } }).FirstOrDefault(), - Insurees = efm.Family.Select(x => x.Insurees).FirstOrDefault().ToList(), - Policies = efm.Family.Select(x => x.Policies).FirstOrDefault().ToList(), - Premiums = efm.Family.Select(x => x.Policies.Select(s => s.Premium)).FirstOrDefault().ToList(), - InsureePolicies = efm.Family.Select(x => x.InsureePolicy).FirstOrDefault().ToList(), + Insurees = Family.Select(x => x.Insurees).FirstOrDefault().ToList(), + Policies = Family.Select(x => x.Policies).FirstOrDefault().ToList(), + Premiums = Family.Select(x => x.Policies.Select(s => s.Premium)).FirstOrDefault().ToList(), + InsureePolicies = Family.Select(x => x.InsureePolicy).FirstOrDefault().ToList(), }; } } diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs index e3a7cbbe..318c5df2 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs @@ -93,7 +93,7 @@ public int Create(EnrollFamilyModel model, int userId, int officerId) { string webRootPath = _hostingEnvironment.WebRootPath; - var enrollFamily = (Enrolment)model; + var enrollFamily = model.GetEnrolmentFromModel(); enrollFamily.FileInfo.UserId = userId; enrollFamily.FileInfo.OfficerId = officerId; @@ -114,7 +114,7 @@ public int Create(EnrollFamilyModel model, int userId, int officerId) } else hof = "Unknown"; - var FileName = string.Format("{0}__{1}_{2}.XML.xml", hof, officerId.ToString(), DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss.XML")); + var FileName = string.Format("{0}__{1}_{2}.xml", hof, officerId.ToString(), DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss.XML")); var JsonFileName = string.Format("{0}_{1}_{2}.json", hof, officerId.ToString(), DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")); From a43383ed270e10ba2978c6a5803b8194521b0505 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 22 Aug 2019 16:05:45 +0200 Subject: [PATCH 40/86] OS-55: Added Master Data --- OpenImis.DB.SqlServer/IMISContext.cs | 8 +- OpenImis.DB.SqlServer/TblIMISDetaulsPhone.cs | 12 + .../Helpers/ConfigImisModules.cs | 25 ++ OpenImis.ModulesV2/IImisModules.cs | 3 + OpenImis.ModulesV2/ImisModules.cs | 39 +- .../MasterDataModule/IMasterDataModule.cs | 10 + .../Logic/IMasterDataLogic.cs | 10 + .../MasterDataModule/Logic/MasterDataLogic.cs | 42 +++ .../MasterDataModule/MasterDataModule.cs | 32 ++ .../Models/ConfirmationTypeModel.cs | 12 + .../MasterDataModule/Models/ControlModel.cs | 12 + .../Models/EducationLevelModel.cs | 12 + .../Models/FamilyTypeModel.cs | 12 + .../Models/GenderTypeModel.cs | 12 + .../Models/GetMasterDataResponse.cs | 17 + .../MasterDataModule/Models/HFModel.cs | 15 + .../Models/IdentificationTypeModel.cs | 12 + .../MasterDataModule/Models/LanguageModel.cs | 13 + .../MasterDataModule/Models/LocationModel.cs | 16 + .../Models/MasterDataModel.cs | 25 ++ .../MasterDataModule/Models/OfficerModel.cs | 18 + .../MasterDataModule/Models/PayerModel.cs | 13 + .../Models/PhoneDefaultModel.cs | 12 + .../MasterDataModule/Models/ProductModel.cs | 40 ++ .../Models/ProfessionTypeModel.cs | 12 + .../Models/RelationTypeModel.cs | 12 + .../Repositories/IMasterDataRepository.cs | 27 ++ .../Repositories/MasterDataRepository.cs | 357 ++++++++++++++++++ .../Controllers/V2/MasterDataController.cs | 51 +++ OpenImis.RestApi/openImisModules.json | 12 + 30 files changed, 881 insertions(+), 12 deletions(-) create mode 100644 OpenImis.DB.SqlServer/TblIMISDetaulsPhone.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/IMasterDataModule.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Logic/IMasterDataLogic.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Logic/MasterDataLogic.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/MasterDataModule.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/ConfirmationTypeModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/ControlModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/EducationLevelModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/FamilyTypeModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/GenderTypeModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/GetMasterDataResponse.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/HFModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/IdentificationTypeModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/LanguageModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/LocationModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/MasterDataModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/OfficerModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/PayerModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/PhoneDefaultModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/ProductModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/ProfessionTypeModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Models/RelationTypeModel.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Repositories/IMasterDataRepository.cs create mode 100644 OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs create mode 100644 OpenImis.RestApi/Controllers/V2/MasterDataController.cs diff --git a/OpenImis.DB.SqlServer/IMISContext.cs b/OpenImis.DB.SqlServer/IMISContext.cs index 3c5fbc50..b9e8de45 100644 --- a/OpenImis.DB.SqlServer/IMISContext.cs +++ b/OpenImis.DB.SqlServer/IMISContext.cs @@ -73,6 +73,7 @@ public IMISContext(DbContextOptions options) public virtual DbSet TblUsersDistricts { get; set; } public virtual DbSet TblRoleRight { get; set; } public virtual DbSet TblUserRole { get; set; } + public virtual DbSet TblIMISDetaulsPhone { get; set; } // Unable to generate entity type for table 'dbo.tblIMISDetaulsPhone'. Please see the warning messages. // Unable to generate entity type for table 'dbo.tblEmailSettings'. Please see the warning messages. @@ -2657,6 +2658,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { entity.HasKey(e => e.UserRoleID); }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.RuleName); + }); } } -} +} \ No newline at end of file diff --git a/OpenImis.DB.SqlServer/TblIMISDetaulsPhone.cs b/OpenImis.DB.SqlServer/TblIMISDetaulsPhone.cs new file mode 100644 index 00000000..ba716c1c --- /dev/null +++ b/OpenImis.DB.SqlServer/TblIMISDetaulsPhone.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.DB.SqlServer +{ + public class TblIMISDetaulsPhone + { + public string RuleName { get; set; } + public bool? RuleValue { get; set; } + } +} diff --git a/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs b/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs index 8355b6d4..bf80f1d7 100644 --- a/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs +++ b/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs @@ -12,6 +12,11 @@ public class ConfigImisModules public CoverageModule CoverageModule { get; set; } public InsureeModule InsureeModule { get; set; } public PaymentModule PaymentModule { get; set; } + + public FeedbackModule FeedbackModule { get; set; } + public PremiumModule PremiumModule { get; set; } + public SystemModule SystemModule { get; set; } + public MasterDataModule MasterDataModule { get; set; } } public class LoginModule @@ -40,4 +45,24 @@ public class PaymentModule { public string PaymentLogic { get; set; } } + + public class FeedbackModule + { + public string FeedbackLogic { get; set; } + } + + public class PremiumModule + { + public string PremiumLogic { get; set; } + } + + public class SystemModule + { + public string SystemLogic { get; set; } + } + + public class MasterDataModule + { + public string MasterDataLogic { get; set; } + } } diff --git a/OpenImis.ModulesV2/IImisModules.cs b/OpenImis.ModulesV2/IImisModules.cs index 80ade352..677b06ce 100644 --- a/OpenImis.ModulesV2/IImisModules.cs +++ b/OpenImis.ModulesV2/IImisModules.cs @@ -3,6 +3,7 @@ using OpenImis.ModulesV2.InsureeModule; using OpenImis.ModulesV2.CoverageModule; using OpenImis.ModulesV2.PaymentModule; +using OpenImis.ModulesV2.MasterDataModule; namespace OpenImis.ModulesV2 { @@ -20,5 +21,7 @@ public interface IImisModules ICoverageModule GetCoverageModule(); IPaymentModule GetPaymentModule(); + + IMasterDataModule GetMasterDataModule(); } } diff --git a/OpenImis.ModulesV2/ImisModules.cs b/OpenImis.ModulesV2/ImisModules.cs index 8b30f724..5a76070a 100644 --- a/OpenImis.ModulesV2/ImisModules.cs +++ b/OpenImis.ModulesV2/ImisModules.cs @@ -1,5 +1,8 @@ -using System.Reflection; -using System; +using System; +using System.Linq; +using System.Reflection; +using OpenImis.ModulesV2.Helpers; +using System.Collections.Generic; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -8,9 +11,9 @@ using OpenImis.ModulesV2.InsureeModule; using OpenImis.ModulesV2.CoverageModule; using OpenImis.ModulesV2.PaymentModule; -using OpenImis.ModulesV2.Helpers; -using System.Collections.Generic; -using System.Linq; +using OpenImis.ModulesV2.MasterDataModule; +using OpenImis.ModulesV2.MasterDataModule.Logic; +using System.Diagnostics; namespace OpenImis.ModulesV2 { @@ -22,6 +25,7 @@ public class ImisModules : IImisModules private IClaimModule claimModule; private ICoverageModule coverageModule; private IPaymentModule paymentModule; + private IMasterDataModule masterDataModule; private readonly IConfiguration _configuration; private readonly ILogger _logger; @@ -130,6 +134,24 @@ public IPaymentModule GetPaymentModule() return paymentModule; } + /// + /// Creates and returns the master data module version 2. + /// + /// + /// The MasterData module V2. + /// + public IMasterDataModule GetMasterDataModule() + { + if (masterDataModule == null) + { + masterDataModule = new MasterDataModule.MasterDataModule(_configuration); + + Type masterDataLogicType = CreateTypeFromConfiguration("MasterDataModule", "MasterDataLogic", "OpenImis.ModulesV2.MasterDataModule.Logic.MasterDataLogic"); + masterDataModule.SetMasterDataLogic((IMasterDataLogic)ActivatorUtilities.CreateInstance(_serviceProvider, masterDataLogicType)); + } + return masterDataModule; + } + /// /// Creates and returns the type based on the string from the configuration /// @@ -142,15 +164,11 @@ private Type CreateTypeFromConfiguration(string moduleName, string sectionName, Type type; Assembly assembly = Assembly.GetCallingAssembly(); - string part = GetSectionName(moduleName, sectionName, "2"); - type = assembly.GetType(part); - if (type == null) { _logger.LogError(moduleName + " " + sectionName + " error: the type " + part + " was not found. Using default " + defaultValue + " configuration."); - type = assembly.GetType(defaultValue); } else @@ -166,14 +184,13 @@ public string GetSectionName(string moduleName, string sectionName, string apiVe string part = ""; var listImisModules = _configuration.GetSection("ImisModules").Get>(); - + var module = listImisModules.Where(m => m.Version == apiVersion).Select(x => GetPropValue(x, moduleName)).FirstOrDefault(); if (GetPropValue(module, sectionName) != null) { part = GetPropValue(module, sectionName).ToString(); } - return part; } diff --git a/OpenImis.ModulesV2/MasterDataModule/IMasterDataModule.cs b/OpenImis.ModulesV2/MasterDataModule/IMasterDataModule.cs new file mode 100644 index 00000000..e93d1a1e --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/IMasterDataModule.cs @@ -0,0 +1,10 @@ +using OpenImis.ModulesV2.MasterDataModule.Logic; + +namespace OpenImis.ModulesV2.MasterDataModule +{ + public interface IMasterDataModule + { + IMasterDataLogic GetMasterDataLogic(); + IMasterDataModule SetMasterDataLogic(IMasterDataLogic masterDataLogic); + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Logic/IMasterDataLogic.cs b/OpenImis.ModulesV2/MasterDataModule/Logic/IMasterDataLogic.cs new file mode 100644 index 00000000..7c8ff569 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Logic/IMasterDataLogic.cs @@ -0,0 +1,10 @@ +using OpenImis.ModulesV2.MasterDataModule.Models; +using System; + +namespace OpenImis.ModulesV2.MasterDataModule.Logic +{ + public interface IMasterDataLogic + { + MasterDataModel GetMasterData(); + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Logic/MasterDataLogic.cs b/OpenImis.ModulesV2/MasterDataModule/Logic/MasterDataLogic.cs new file mode 100644 index 00000000..b38659c5 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Logic/MasterDataLogic.cs @@ -0,0 +1,42 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.MasterDataModule.Models; +using OpenImis.ModulesV2.MasterDataModule.Repositories; + +namespace OpenImis.ModulesV2.MasterDataModule.Logic +{ + public class MasterDataLogic : IMasterDataLogic + { + private IConfiguration _configuration; + protected IMasterDataRepository masterDataRepository; + + public MasterDataLogic(IConfiguration configuration) + { + _configuration = configuration; + masterDataRepository = new MasterDataRepository(_configuration); + } + + public MasterDataModel GetMasterData() + { + MasterDataModel masterdata = new MasterDataModel() + { + ConfirmationTypes = masterDataRepository.GetConfirmationTypes(), + Controls = masterDataRepository.GetControls(), + Education = masterDataRepository.GetEducations(), + FamilyTypes = masterDataRepository.GetFamilyTypes(), + HF = masterDataRepository.GetHFs(), + IdentificationTypes = masterDataRepository.GetIdentificationTypes(), + Languages = masterDataRepository.GetLanguages(), + Locations = masterDataRepository.GetLocations(), + Officers = masterDataRepository.GetOfficers(), + Payers = masterDataRepository.GetPayers(), + Products = masterDataRepository.GetProducts(), + Professions = masterDataRepository.GetProfessions(), + Relations = masterDataRepository.GetRelations(), + PhoneDefaults = masterDataRepository.GetPhoneDefaults(), + Genders = masterDataRepository.GetGenders() + }; + + return masterdata; + } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/MasterDataModule.cs b/OpenImis.ModulesV2/MasterDataModule/MasterDataModule.cs new file mode 100644 index 00000000..d170ef47 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/MasterDataModule.cs @@ -0,0 +1,32 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.MasterDataModule.Logic; + +namespace OpenImis.ModulesV2.MasterDataModule +{ + public class MasterDataModule : IMasterDataModule + { + private IConfiguration _configuration; + + private IMasterDataLogic _masterDataLogic; + + public MasterDataModule(IConfiguration configuration) + { + _configuration = configuration; + } + + public IMasterDataLogic GetMasterDataLogic() + { + if (_masterDataLogic == null) + { + _masterDataLogic = new MasterDataLogic(_configuration); + } + return _masterDataLogic; + } + + public IMasterDataModule SetMasterDataLogic(IMasterDataLogic masterDataLogic) + { + _masterDataLogic = masterDataLogic; + return this; + } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/ConfirmationTypeModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/ConfirmationTypeModel.cs new file mode 100644 index 00000000..5fef8d7f --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/ConfirmationTypeModel.cs @@ -0,0 +1,12 @@ +using OpenImis.DB.SqlServer; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class ConfirmationTypeModel + { + public string ConfirmationTypeCode { get; set; } + public string ConfirmationType { get; set; } + public string SortOrder { get; set; } + public string AltLanguage { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/ControlModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/ControlModel.cs new file mode 100644 index 00000000..b0c8ed5f --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/ControlModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class ControlModel + { + public string FieldName { get; set; } + public string Adjustibility { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/EducationLevelModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/EducationLevelModel.cs new file mode 100644 index 00000000..3d08479d --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/EducationLevelModel.cs @@ -0,0 +1,12 @@ +using OpenImis.DB.SqlServer; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class EducationLevelModel + { + public int EducationId { get; set; } + public string Education { get; set; } + public string SortOrder { get; set; } + public string AltLanguage { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/FamilyTypeModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/FamilyTypeModel.cs new file mode 100644 index 00000000..b9fa3e90 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/FamilyTypeModel.cs @@ -0,0 +1,12 @@ +using OpenImis.DB.SqlServer; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class FamilyTypeModel + { + public string FamilyTypeCode { get; set; } + public string FamilyType { get; set; } + public string SortOrder { get; set; } + public string AltLanguage { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/GenderTypeModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/GenderTypeModel.cs new file mode 100644 index 00000000..e3761425 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/GenderTypeModel.cs @@ -0,0 +1,12 @@ +using OpenImis.DB.SqlServer; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class GenderTypeModel + { + public string Code { get; set; } + public string Gender { get; set; } + public string AltLanguage { get; set; } + public string SortOrder { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/GetMasterDataResponse.cs b/OpenImis.ModulesV2/MasterDataModule/Models/GetMasterDataResponse.cs new file mode 100644 index 00000000..30ffc466 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/GetMasterDataResponse.cs @@ -0,0 +1,17 @@ +using System; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class GetMasterDataResponse + { + public LocationModel[] Locations { get; set; } + public FamilyTypeModel[] FamilyTypes { get; set; } + public ConfirmationTypeModel[] ConfirmationTypes { get; set; } + public EducationLevelModel[] EducationLevels { get; set; } + public GenderTypeModel[] GenderTypes { get; set; } + public RelationTypeModel[] RelationTypes { get; set; } + public ProfessionTypeModel[] ProfessionTypes { get; set; } + public IdentificationTypeModel[] IdentificationTypes { get; set; } + + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/HFModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/HFModel.cs new file mode 100644 index 00000000..647cad7d --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/HFModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class HFModel + { + public int HFID { get; set; } + public string HFCode { get; set; } + public string HFName { get; set; } + public int LocationId { get; set; } + public string HFLevel { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/IdentificationTypeModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/IdentificationTypeModel.cs new file mode 100644 index 00000000..4e29c09d --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/IdentificationTypeModel.cs @@ -0,0 +1,12 @@ +using OpenImis.DB.SqlServer; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class IdentificationTypeModel + { + public string IdentificationCode { get; set; } + public string IdentificationTypes { get; set; } + public string SortOrder { get; set; } + public string AltLanguage { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/LanguageModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/LanguageModel.cs new file mode 100644 index 00000000..d4c9bef0 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/LanguageModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class LanguageModel + { + public string LanguageCode { get; set; } + public string LanguageName { get; set; } + public string SortOrder { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/LocationModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/LocationModel.cs new file mode 100644 index 00000000..38b4ff08 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/LocationModel.cs @@ -0,0 +1,16 @@ +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.Utils; +using System; +using System.Collections.Generic; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class LocationModel + { + public int LocationId { get; set; } + public string LocationCode { get; set; } + public string LocationName { get; set; } + public int? ParentLocationId { get; set; } + public string LocationType { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/MasterDataModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/MasterDataModel.cs new file mode 100644 index 00000000..eae19363 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/MasterDataModel.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class MasterDataModel + { + public List ConfirmationTypes { get; set; } + public List Controls { get; set; } + public List Education { get; set; } + public List FamilyTypes { get; set; } + public List HF { get; set; } + public List IdentificationTypes { get; set; } + public List Languages { get; set; } + public List Locations { get; set; } + public List Officers { get; set; } + public List Payers { get; set; } + public List Products { get; set; } + public List Professions { get; set; } + public List Relations { get; set; } + public List PhoneDefaults { get; set; } + public List Genders { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/OfficerModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/OfficerModel.cs new file mode 100644 index 00000000..6b2a2ca8 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/OfficerModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class OfficerModel + { + public int OfficerId { get; set; } + public string Code { get; set; } + public string LastName { get; set; } + public string OtherNames { get; set; } + public string Phone { get; set; } + public int? LocationId { get; set; } + public string OfficerIDSubst { get; set; } + public string WorksTo { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/PayerModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/PayerModel.cs new file mode 100644 index 00000000..f9197704 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/PayerModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class PayerModel + { + public int PayerId { get; set; } + public string PayerName { get; set; } + public int? LocationId { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/PhoneDefaultModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/PhoneDefaultModel.cs new file mode 100644 index 00000000..67c94a3a --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/PhoneDefaultModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class PhoneDefaultModel + { + public string RuleName { get; set; } + public bool? RuleValue { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/ProductModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/ProductModel.cs new file mode 100644 index 00000000..4ba9c147 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/ProductModel.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class ProductModel + { + public int ProdId { get; set; } + public string ProductCode { get; set; } + public string ProductName { get; set; } + public int? LocationId { get; set; } + public int InsurancePeriod { get; set; } + public string DateFrom { get; set; } + public string DateTo { get; set; } + public int? ConversionProdId { get; set; } + public decimal Lumpsum { get; set; } + public int MemberCount { get; set; } + public decimal? PremiumAdult { get; set; } + public decimal? PremiumChild { get; set; } + public decimal? RegistrationLumpsum { get; set; } + public decimal? RegistrationFee { get; set; } + public decimal? GeneralAssemblyLumpSum { get; set; } + public decimal? GeneralAssemblyFee { get; set; } + public string StartCycle1 { get; set; } + public string StartCycle2 { get; set; } + public string StartCycle3 { get; set; } + public string StartCycle4 { get; set; } + public int? GracePeriodRenewal { get; set; } + public int? MaxInstallments { get; set; } + public int? WaitingPeriod { get; set; } + public int? Threshold { get; set; } + public int? RenewalDiscountPerc { get; set; } + public int? RenewalDiscountPeriod { get; set; } + public int? AdministrationPeriod { get; set; } + public int? EnrolmentDiscountPerc { get; set; } + public int? EnrolmentDiscountPeriod { get; set; } + public int GracePeriod { get; set; } + } +} \ No newline at end of file diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/ProfessionTypeModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/ProfessionTypeModel.cs new file mode 100644 index 00000000..26820062 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/ProfessionTypeModel.cs @@ -0,0 +1,12 @@ +using OpenImis.DB.SqlServer; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class ProfessionTypeModel + { + public int ProfessionId { get; set; } + public string Profession { get; set; } + public string SortOrder { get; set; } + public string AltLanguage { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/RelationTypeModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/RelationTypeModel.cs new file mode 100644 index 00000000..b2e13825 --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Models/RelationTypeModel.cs @@ -0,0 +1,12 @@ +using OpenImis.DB.SqlServer; + +namespace OpenImis.ModulesV2.MasterDataModule.Models +{ + public class RelationTypeModel + { + public int RelationId { get; set; } + public string Relation { get; set; } + public string SortOrder { get; set; } + public string AltLanguage { get; set; } + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Repositories/IMasterDataRepository.cs b/OpenImis.ModulesV2/MasterDataModule/Repositories/IMasterDataRepository.cs new file mode 100644 index 00000000..f3dfa54c --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Repositories/IMasterDataRepository.cs @@ -0,0 +1,27 @@ +using OpenImis.ModulesV2.MasterDataModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.MasterDataModule.Repositories +{ + public interface IMasterDataRepository + { + List GetConfirmationTypes(); + List GetControls(); + List GetEducations(); + List GetFamilyTypes(); + List GetHFs(); + List GetIdentificationTypes(); + List GetLanguages(); + List GetLocations(); + List GetOfficers(); + List GetPayers(); + List GetProducts(); + List GetProfessions(); + List GetRelations(); + List GetPhoneDefaults(); + List GetGenders(); + + } +} diff --git a/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs b/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs new file mode 100644 index 00000000..8f0a38cf --- /dev/null +++ b/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs @@ -0,0 +1,357 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.MasterDataModule.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenImis.ModulesV2.MasterDataModule.Repositories +{ + public class MasterDataRepository : IMasterDataRepository + { + private IConfiguration Configuration; + + public MasterDataRepository(IConfiguration configuration) + { + Configuration = configuration; + } + + public List GetConfirmationTypes() + { + List confirmationTypes; + + using (var imisContext = new ImisDB()) + { + confirmationTypes = imisContext.TblConfirmationTypes + .Select(x => new ConfirmationTypeModel() + { + ConfirmationTypeCode = x.ConfirmationTypeCode, + ConfirmationType = x.ConfirmationType, + SortOrder = x.SortOrder.ToString(), + AltLanguage = x.AltLanguage + }) + .ToList(); + } + + return confirmationTypes; + } + + public List GetControls() + { + List controls; + + using (var imisContext = new ImisDB()) + { + controls = imisContext.TblControls + .Select(x => new ControlModel() + { + FieldName = x.FieldName, + Adjustibility = x.Adjustibility + }) + .ToList(); + } + + return controls; + } + + public List GetEducations() + { + List educations; + + using (var imisContext = new ImisDB()) + { + educations = imisContext.TblEducations + .Select(x => new EducationLevelModel() + { + EducationId = x.EducationId, + Education = x.Education, + SortOrder = x.SortOrder.ToString(), + AltLanguage = x.AltLanguage + }) + .ToList(); + } + + return educations; + } + + public List GetFamilyTypes() + { + List familyTypes; + + using (var imisContext = new ImisDB()) + { + familyTypes = imisContext.TblFamilyTypes + .Select(x => new FamilyTypeModel() + { + FamilyTypeCode = x.FamilyTypeCode, + FamilyType = x.FamilyType, + SortOrder = x.SortOrder.ToString(), + AltLanguage = x.AltLanguage + }) + .ToList(); + } + + return familyTypes; + } + + public List GetHFs() + { + List hfs; + + using (var imisContext = new ImisDB()) + { + hfs = imisContext.TblHf + .Where(h => h.ValidityTo == null) + .Select(x => new HFModel() + { + HFID = x.HfId, + HFCode = x.Hfcode, + HFName = x.Hfname, + LocationId = x.LocationId, + HFLevel = x.Hflevel + }) + .ToList(); + } + + return hfs; + } + + public List GetIdentificationTypes() + { + List identificationTypes; + + using (var imisContext = new ImisDB()) + { + identificationTypes = imisContext.TblIdentificationTypes + .Select(x => new IdentificationTypeModel() + { + IdentificationCode = x.IdentificationCode, + IdentificationTypes = x.IdentificationTypes, + SortOrder = x.SortOrder.ToString(), + AltLanguage = x.AltLanguage + }) + .ToList(); + } + + return identificationTypes; + } + + public List GetLanguages() + { + List languages; + + using (var imisContext = new ImisDB()) + { + languages = imisContext.TblLanguages + .Select(x => new LanguageModel() + { + LanguageCode = x.LanguageCode, + LanguageName = x.LanguageName, + SortOrder = x.SortOrder.ToString() + }) + .ToList(); + } + + return languages; + } + + public List GetLocations() + { + List locations; + + using (var imisContext = new ImisDB()) + { + locations = imisContext.TblLocations + .Where(l => l.ValidityTo == null && + !(l.LocationName == "Funding" + || l.LocationCode == "FR" + || l.LocationCode == "FD" + || l.LocationCode == "FW" + || l.LocationCode == "FV" + )) + .Select(x => new LocationModel() + { + LocationId = x.LocationId, + LocationCode = x.LocationCode, + LocationName = x.LocationName, + ParentLocationId = x.ParentLocationId, + LocationType = x.LocationType + }) + .ToList(); + } + + return locations; + } + + public List GetOfficers() + { + List officers; + + using (var imisContext = new ImisDB()) + { + officers = imisContext.TblOfficer + .Where(o => o.ValidityTo == null) + .Select(x => new OfficerModel() + { + OfficerId = x.OfficerId, + Code = x.Code, + LastName = x.LastName, + OtherNames = x.OtherNames, + Phone = x.Phone, + LocationId = x.LocationId, + OfficerIDSubst = x.OfficerIdsubst.ToString(), + WorksTo = x.WorksTo.GetValueOrDefault().ToString("yyyy-MM-dd") + }) + .ToList(); + } + + return officers; + } + + public List GetPayers() + { + List payers; + + using (var imisContext = new ImisDB()) + { + payers = imisContext.TblPayer + .Where(p => p.ValidityTo == null) + .Select(x => new PayerModel() + { + PayerId = x.PayerId, + PayerName = x.PayerName, + LocationId = x.LocationId + }) + .ToList(); + } + + return payers; + } + + public List GetProducts() + { + List products; + + using (var imisContext = new ImisDB()) + { + products = imisContext.TblProduct + .Where(p => p.ValidityTo == null) + .Select(x => new ProductModel() + { + ProdId = x.ProdId, + ProductCode = x.ProductCode, + ProductName = x.ProductName, + LocationId = x.LocationId, + InsurancePeriod = x.InsurancePeriod, + DateFrom = x.DateFrom.ToString("yyyy-MM-dd"), + DateTo = x.DateTo.ToString("yyyy-MM-dd"), + ConversionProdId = x.ConversionProdId, + Lumpsum = x.LumpSum, + MemberCount = x.MemberCount, + PremiumAdult = x.PremiumAdult, + PremiumChild = x.PremiumChild, + RegistrationLumpsum = x.RegistrationLumpSum, + RegistrationFee = x.RegistrationFee, + GeneralAssemblyLumpSum = x.GeneralAssemblyLumpSum, + GeneralAssemblyFee = x.GeneralAssemblyFee, + StartCycle1 = x.StartCycle1, + StartCycle2 = x.StartCycle2, + StartCycle3 = x.StartCycle3, + StartCycle4 = x.StartCycle4, + GracePeriodRenewal = x.GracePeriodRenewal, + MaxInstallments = x.MaxInstallments, + WaitingPeriod = x.WaitingPeriod, + Threshold = x.Threshold, + RenewalDiscountPerc = x.RenewalDiscountPerc, + RenewalDiscountPeriod = x.RenewalDiscountPeriod, + AdministrationPeriod = x.AdministrationPeriod, + EnrolmentDiscountPerc = x.EnrolmentDiscountPerc, + EnrolmentDiscountPeriod = x.EnrolmentDiscountPeriod, + GracePeriod = x.GracePeriod + }) + .ToList(); + } + + return products; + } + + public List GetProfessions() + { + List professions; + + using (var imisContext = new ImisDB()) + { + professions = imisContext.TblProfessions + .Select(x => new ProfessionTypeModel() + { + ProfessionId = x.ProfessionId, + Profession = x.Profession, + SortOrder = x.SortOrder.ToString(), + AltLanguage = x.AltLanguage + }) + .ToList(); + } + + return professions; + } + + public List GetRelations() + { + List relations; + + using (var imisContext = new ImisDB()) + { + relations = imisContext.TblRelations + .Select(x => new RelationTypeModel() + { + RelationId = x.RelationId, + Relation = x.Relation, + SortOrder = x.SortOrder.ToString(), + AltLanguage = x.AltLanguage + }) + .ToList(); + } + + return relations; + } + + public List GetPhoneDefaults() + { + List phoneDefaults; + + using (var imisContext = new ImisDB()) + { + phoneDefaults = imisContext.TblIMISDetaulsPhone + .Select(x => new PhoneDefaultModel() + { + RuleName = x.RuleName, + RuleValue = x.RuleValue + }) + .ToList(); + } + + return phoneDefaults; + } + + public List GetGenders() + { + List genders; + + using (var imisContext = new ImisDB()) + { + genders = imisContext.TblGender + .Select(x => new GenderTypeModel() + { + Code = x.Code, + Gender = x.Gender, + AltLanguage = x.AltLanguage, + SortOrder = x.SortOrder.ToString() + }) + .ToList(); + } + + return genders; + } + } +} diff --git a/OpenImis.RestApi/Controllers/V2/MasterDataController.cs b/OpenImis.RestApi/Controllers/V2/MasterDataController.cs new file mode 100644 index 00000000..bc765d7c --- /dev/null +++ b/OpenImis.RestApi/Controllers/V2/MasterDataController.cs @@ -0,0 +1,51 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2; +using OpenImis.ModulesV2.MasterDataModule.Models; +using OpenImis.RestApi.Security; + +namespace OpenImis.RestApi.Controllers.V2 +{ + [ApiVersion("2")] + [Authorize] + [Route("api/")] + [ApiController] + public class MasterDataController : Controller + { + private readonly IConfiguration _configuration; + private readonly IImisModules _imisModules; + + public MasterDataController(IConfiguration configuration, IImisModules imisModules) + { + _configuration = configuration; + _imisModules = imisModules; + } + + /// + /// Get the Master Data + /// + /// The Master Data + /// + /// ### REMARKS ### + /// The following codes are returned + /// - 200 - The Master Data + /// - 401 - The token is invalid + /// + /// Returns the list of Locations + /// If the token is missing, is wrong or expired + [HasRights(Rights.ExtractMasterDataDownload)] + [HttpGet] + [Route("master")] + [ProducesResponseType(typeof(GetMasterDataResponse), 200)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public IActionResult GetMasterData() + { + MasterDataModel masterData = _imisModules.GetMasterDataModule().GetMasterDataLogic().GetMasterData(); + + return Ok(masterData); + } + } +} \ No newline at end of file diff --git a/OpenImis.RestApi/openImisModules.json b/OpenImis.RestApi/openImisModules.json index 1dc493ef..17444b67 100644 --- a/OpenImis.RestApi/openImisModules.json +++ b/OpenImis.RestApi/openImisModules.json @@ -38,6 +38,18 @@ }, "PaymentModule": { "PaymentLogic": "OpenImis.ModulesV2.PaymentModule.Logic.PaymentLogic" + }, + "FeedbackModule": { + "FeedbackLogic": "OpenImis.ModulesV2.FeedbackModule.Logic.FeedbackLogic" + }, + "PremiumModule": { + "PremiumLogic": "OpenImis.ModulesV2.PremiumModule.Logic.PremiumLogic" + }, + "SystemModule": { + "SystemLogic": "OpenImis.ModulesV2.SystemModule.Logic.SystemLogic" + }, + "MasterDataModule": { + "MasterDataLogic": "OpenImis.ModulesV2.MasterDataModule.Logic.MasterDataLogic" } } ] From 3989ef50745c47530636e78e0687a77686351531 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Fri, 23 Aug 2019 10:56:33 +0200 Subject: [PATCH 41/86] OS-40: Added Rights to Controller --- OpenImis.RestApi/Controllers/V2/ClaimController.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OpenImis.RestApi/Controllers/V2/ClaimController.cs b/OpenImis.RestApi/Controllers/V2/ClaimController.cs index d7044ddc..4c20303d 100644 --- a/OpenImis.RestApi/Controllers/V2/ClaimController.cs +++ b/OpenImis.RestApi/Controllers/V2/ClaimController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc; using OpenImis.ModulesV2; using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; +using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers.V2 { @@ -19,9 +20,9 @@ public ClaimController(IImisModules imisModules) _imisModules = imisModules; } - //[HasRights(Rights.ClaimAdd)] + [HasRights(Rights.ClaimAdd)] [HttpPost] - public IActionResult Create([FromBody] Claim claim) + public IActionResult Create([FromBody]Claim claim) { int response; From 3605ac4b1a503a8f7b952f337aefd85bc05bdc83 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Mon, 26 Aug 2019 10:33:18 +0200 Subject: [PATCH 42/86] OS-55: Changed first letter in JSON as Capitalize --- OpenImis.RestApi/Startup.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OpenImis.RestApi/Startup.cs b/OpenImis.RestApi/Startup.cs index 62068e53..41e41bc7 100644 --- a/OpenImis.RestApi/Startup.cs +++ b/OpenImis.RestApi/Startup.cs @@ -18,6 +18,7 @@ using System.Collections.Generic; using System.Linq; using System.Diagnostics; +using Newtonsoft.Json.Serialization; namespace OpenImis.RestApi { @@ -68,7 +69,8 @@ public void ConfigureServices(IServiceCollection services) options.AllowCombiningAuthorizeFilters = false; }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) - .AddControllersAsServices(); + .AddControllersAsServices() + .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()); services.AddApiVersioning(o => { From 17868de6af3b14451e541f8de0a3b7e64df39aca Mon Sep 17 00:00:00 2001 From: bkaminski Date: Mon, 26 Aug 2019 14:01:00 +0200 Subject: [PATCH 43/86] OS-55: The first letter change in JSON has been removed --- OpenImis.RestApi/Startup.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/OpenImis.RestApi/Startup.cs b/OpenImis.RestApi/Startup.cs index 41e41bc7..e9834052 100644 --- a/OpenImis.RestApi/Startup.cs +++ b/OpenImis.RestApi/Startup.cs @@ -69,8 +69,7 @@ public void ConfigureServices(IServiceCollection services) options.AllowCombiningAuthorizeFilters = false; }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) - .AddControllersAsServices() - .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()); + .AddControllersAsServices(); services.AddApiVersioning(o => { From 009a73024421bfb0d405a1f805aa3486fdb9b46c Mon Sep 17 00:00:00 2001 From: bkaminski Date: Mon, 26 Aug 2019 16:45:40 +0200 Subject: [PATCH 44/86] OS-55: Changed OfficerId to OfficerUUID --- OpenImis.DB.SqlServer/TblOfficer.cs | 1 + OpenImis.ModulesV2/MasterDataModule/Models/OfficerModel.cs | 2 +- .../MasterDataModule/Repositories/MasterDataRepository.cs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/OpenImis.DB.SqlServer/TblOfficer.cs b/OpenImis.DB.SqlServer/TblOfficer.cs index f9d6d808..7697a181 100644 --- a/OpenImis.DB.SqlServer/TblOfficer.cs +++ b/OpenImis.DB.SqlServer/TblOfficer.cs @@ -14,6 +14,7 @@ public TblOfficer() } public int OfficerId { get; set; } + public Guid OfficerUUID { get; set; } public string Code { get; set; } public string LastName { get; set; } public string OtherNames { get; set; } diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/OfficerModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/OfficerModel.cs index 6b2a2ca8..ba2ec14c 100644 --- a/OpenImis.ModulesV2/MasterDataModule/Models/OfficerModel.cs +++ b/OpenImis.ModulesV2/MasterDataModule/Models/OfficerModel.cs @@ -6,7 +6,7 @@ namespace OpenImis.ModulesV2.MasterDataModule.Models { public class OfficerModel { - public int OfficerId { get; set; } + public Guid OfficerUUID { get; set; } public string Code { get; set; } public string LastName { get; set; } public string OtherNames { get; set; } diff --git a/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs b/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs index 8f0a38cf..573635e6 100644 --- a/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs +++ b/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs @@ -194,7 +194,7 @@ public List GetOfficers() .Where(o => o.ValidityTo == null) .Select(x => new OfficerModel() { - OfficerId = x.OfficerId, + OfficerUUID = x.OfficerUUID, Code = x.Code, LastName = x.LastName, OtherNames = x.OtherNames, From 1818bd077a76def4cf2bb23b76896ca59b44ca0e Mon Sep 17 00:00:00 2001 From: bkaminski Date: Tue, 27 Aug 2019 09:44:26 +0200 Subject: [PATCH 45/86] OS-40: Adding method names according to CRUD --- OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs | 4 ++-- OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs | 2 +- .../ClaimModule/Repositories/ClaimRepository.cs | 2 +- .../ClaimModule/Repositories/IClaimRepository.cs | 2 +- OpenImis.RestApi/Controllers/V2/ClaimController.cs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs b/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs index 5da81a39..21e05ae1 100644 --- a/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs +++ b/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs @@ -15,11 +15,11 @@ public ClaimLogic(IConfiguration configuration) claimRepository = new ClaimRepository(_configuration); } - public int RegisterClaim(Claim claim) + public int Create(Claim claim) { int response; - response = claimRepository.RegisterClaim(claim); + response = claimRepository.Create(claim); return response; } diff --git a/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs b/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs index 455f4951..7a9448b1 100644 --- a/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs +++ b/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs @@ -4,6 +4,6 @@ namespace OpenImis.ModulesV2.ClaimModule.Logic { public interface IClaimLogic { - int RegisterClaim(Claim claim); + int Create(Claim claim); } } diff --git a/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs b/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs index c923da0e..ac101e32 100644 --- a/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs +++ b/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs @@ -19,7 +19,7 @@ public ClaimRepository(IConfiguration configuration) _configuration = configuration; } - public int RegisterClaim(Claim claim) + public int Create(Claim claim) { try { diff --git a/OpenImis.ModulesV2/ClaimModule/Repositories/IClaimRepository.cs b/OpenImis.ModulesV2/ClaimModule/Repositories/IClaimRepository.cs index 71fdc74a..67382b79 100644 --- a/OpenImis.ModulesV2/ClaimModule/Repositories/IClaimRepository.cs +++ b/OpenImis.ModulesV2/ClaimModule/Repositories/IClaimRepository.cs @@ -4,6 +4,6 @@ namespace OpenImis.ModulesV2.ClaimModule.Repositories { public interface IClaimRepository { - int RegisterClaim(Claim claim); + int Create(Claim claim); } } diff --git a/OpenImis.RestApi/Controllers/V2/ClaimController.cs b/OpenImis.RestApi/Controllers/V2/ClaimController.cs index 4c20303d..60b51517 100644 --- a/OpenImis.RestApi/Controllers/V2/ClaimController.cs +++ b/OpenImis.RestApi/Controllers/V2/ClaimController.cs @@ -28,7 +28,7 @@ public IActionResult Create([FromBody]Claim claim) try { - response = _imisModules.GetClaimModule().GetClaimLogic().RegisterClaim(claim); + response = _imisModules.GetClaimModule().GetClaimLogic().Create(claim); } catch (ValidationException e) { From 650ea71555e43dd4eb4dab6bf8f2373be106162b Mon Sep 17 00:00:00 2001 From: bkaminski Date: Tue, 27 Aug 2019 14:46:09 +0200 Subject: [PATCH 46/86] OS-58: Added method for Get Insuree --- .../Helpers/ConfigImisModules.cs | 1 + OpenImis.ModulesV2/ImisModules.cs | 3 + .../InsureeModule/Helpers/Extensions.cs | 23 +++++ .../InsureeModule/IInsureeModule.cs | 2 + .../InsureeModule/InsureeModule.cs | 16 +++ .../InsureeModule/Logic/IInsureeLogic.cs | 9 ++ .../InsureeModule/Logic/InsureeLogic.cs | 28 ++++++ .../InsureeModule/Models/DetailModel.cs | 19 ++++ .../InsureeModule/Models/GetInsureeModel.cs | 16 +++ .../Repositories/IInsureeRepository.cs | 9 ++ .../Repositories/InsureeRepository.cs | 99 +++++++++++++++++++ .../Controllers/V2/InsureeController.cs | 51 ++++++++++ OpenImis.RestApi/openImisModules.json | 3 +- 13 files changed, 278 insertions(+), 1 deletion(-) create mode 100644 OpenImis.ModulesV2/InsureeModule/Helpers/Extensions.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Logic/IInsureeLogic.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Logic/InsureeLogic.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/DetailModel.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/GetInsureeModel.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Repositories/IInsureeRepository.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Repositories/InsureeRepository.cs create mode 100644 OpenImis.RestApi/Controllers/V2/InsureeController.cs diff --git a/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs b/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs index bf80f1d7..4b93dec3 100644 --- a/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs +++ b/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs @@ -39,6 +39,7 @@ public class InsureeModule public string FamilyLogic { get; set; } public string PolicyLogic { get; set; } public string ContributionLogic { get; set; } + public string InsureeLogic { get; set; } } public class PaymentModule diff --git a/OpenImis.ModulesV2/ImisModules.cs b/OpenImis.ModulesV2/ImisModules.cs index 93e1b8f0..d7a0a44b 100644 --- a/OpenImis.ModulesV2/ImisModules.cs +++ b/OpenImis.ModulesV2/ImisModules.cs @@ -101,6 +101,9 @@ public IInsureeModule GetInsureeModule() Type contributionLogicType = CreateTypeFromConfiguration("InsureeModule", "ContributionLogic", "OpenImis.ModulesV2.InsureeModule.Logic.ContributionLogic"); insureeModule.SetContributionLogic((InsureeModule.Logic.IContributionLogic)ActivatorUtilities.CreateInstance(_serviceProvider, contributionLogicType)); + + Type insureeLogicType = CreateTypeFromConfiguration("InsureeModule", "InsureeLogic", "OpenImis.ModulesV2.InsureeModule.Logic.InsureeLogic"); + insureeModule.SetInsureeLogic((InsureeModule.Logic.IInsureeLogic)ActivatorUtilities.CreateInstance(_serviceProvider, insureeLogicType)); } return insureeModule; } diff --git a/OpenImis.ModulesV2/InsureeModule/Helpers/Extensions.cs b/OpenImis.ModulesV2/InsureeModule/Helpers/Extensions.cs new file mode 100644 index 00000000..0a5a6598 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Helpers/Extensions.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Helpers +{ + public static class Extensions + { + public static decimal? ToNullableDecimal(this string s) + { + decimal d; + if (decimal.TryParse(s, out d)) return d; + return null; + } + + public static float? ToNullableFloat(this string s) + { + float f; + if (float.TryParse(s, out f)) return f; + return null; + } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/IInsureeModule.cs b/OpenImis.ModulesV2/InsureeModule/IInsureeModule.cs index e946029e..03a659cc 100644 --- a/OpenImis.ModulesV2/InsureeModule/IInsureeModule.cs +++ b/OpenImis.ModulesV2/InsureeModule/IInsureeModule.cs @@ -8,8 +8,10 @@ public interface IInsureeModule IFamilyLogic GetFamilyLogic(); IContributionLogic GetContributionLogic(); IPolicyLogic GetPolicyLogic(); + IInsureeLogic GetInsureeLogic(); IInsureeModule SetFamilyLogic(IFamilyLogic familyLogic); IInsureeModule SetPolicyLogic(IPolicyLogic policyLogic); IInsureeModule SetContributionLogic(IContributionLogic contributionLogic); + IInsureeModule SetInsureeLogic(IInsureeLogic insureeLogic); } } diff --git a/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs b/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs index 19a0dd77..0a9cf1e5 100644 --- a/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs +++ b/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs @@ -12,6 +12,7 @@ public class InsureeModule : IInsureeModule private IFamilyLogic _familyLogic; private IContributionLogic _contributionLogic; private IPolicyLogic _policyLogic; + private IInsureeLogic _insureeLogic; public InsureeModule(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { @@ -46,6 +47,15 @@ public IPolicyLogic GetPolicyLogic() return _policyLogic; } + public IInsureeLogic GetInsureeLogic() + { + if (_insureeLogic == null) + { + _insureeLogic = new InsureeLogic(_configuration); + } + return _insureeLogic; + } + public IInsureeModule SetFamilyLogic(IFamilyLogic familyLogic) { _familyLogic = familyLogic; @@ -63,5 +73,11 @@ public IInsureeModule SetContributionLogic(IContributionLogic contributionLogic) _contributionLogic = contributionLogic; return this; } + + public IInsureeModule SetInsureeLogic(IInsureeLogic insureeLogic) + { + _insureeLogic = insureeLogic; + return this; + } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/IInsureeLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/IInsureeLogic.cs new file mode 100644 index 00000000..9cca9464 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Logic/IInsureeLogic.cs @@ -0,0 +1,9 @@ +using OpenImis.ModulesV2.InsureeModule.Models; + +namespace OpenImis.ModulesV2.InsureeModule.Logic +{ + public interface IInsureeLogic + { + GetInsureeModel Get(string chfid); + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/InsureeLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/InsureeLogic.cs new file mode 100644 index 00000000..2c557471 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Logic/InsureeLogic.cs @@ -0,0 +1,28 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.InsureeModule.Models; +using OpenImis.ModulesV2.InsureeModule.Repositories; + +namespace OpenImis.ModulesV2.InsureeModule.Logic +{ + public class InsureeLogic : IInsureeLogic + { + private IConfiguration _configuration; + protected IInsureeRepository insureeRepository; + + public InsureeLogic(IConfiguration configuration) + { + _configuration = configuration; + + insureeRepository = new InsureeRepository(_configuration); + } + + public GetInsureeModel Get(string chfid) + { + GetInsureeModel response; + + response = insureeRepository.Get(chfid); + + return response; + } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/DetailModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/DetailModel.cs new file mode 100644 index 00000000..9d999d61 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/DetailModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models +{ + public class DetailModel + { + public string ProductName { get; set; } + public string ExpiryDate { get; set; } + public string Status { get; set; } + public float? DedType { get; set; } + public decimal? Ded1 { get; set; } + public decimal? Ded2 { get; set; } + public decimal? Ceiling1 { get; set; } + public decimal? Ceiling2 { get; set; } + public string ProductCode { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/GetInsureeModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/GetInsureeModel.cs new file mode 100644 index 00000000..bb1c2bff --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/GetInsureeModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models +{ + public class GetInsureeModel + { + public string CHFID { get; set; } + public string PhotoPath { get; set; } + public string InsureeName { get; set; } + public string DOB { get; set; } + public string Gender { get; set; } + public List Details { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/IInsureeRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/IInsureeRepository.cs new file mode 100644 index 00000000..3ba6f12f --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/IInsureeRepository.cs @@ -0,0 +1,9 @@ +using OpenImis.ModulesV2.InsureeModule.Models; + +namespace OpenImis.ModulesV2.InsureeModule.Repositories +{ + public interface IInsureeRepository + { + GetInsureeModel Get(string chfid); + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/InsureeRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/InsureeRepository.cs new file mode 100644 index 00000000..03c61cdd --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/InsureeRepository.cs @@ -0,0 +1,99 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.InsureeModule.Helpers; +using OpenImis.ModulesV2.InsureeModule.Models; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.Data.SqlClient; +using System.Diagnostics; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Repositories +{ + public class InsureeRepository : IInsureeRepository + { + private IConfiguration _configuration; + + public InsureeRepository(IConfiguration configuration) + { + _configuration = configuration; + } + + public GetInsureeModel Get(string chfid) + { + GetInsureeModel response = new GetInsureeModel(); + List details = new List(); + + try + { + using (var imisContext = new ImisDB()) + { + var chfidParameter = new SqlParameter("@CHFID", chfid) { SqlDbType = SqlDbType.VarChar, Size = 12 }; + + var sql = "exec uspPolicyInquiry @CHFID"; + + DbConnection connection = imisContext.Database.GetDbConnection(); + + using (DbCommand cmd = connection.CreateCommand()) + { + + cmd.CommandText = sql; + + cmd.Parameters.AddRange(new[] { chfidParameter }); + + if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); + + using (var reader = cmd.ExecuteReader()) + { + do + { + bool firstValue = true; + while (reader.Read()) + { + if (firstValue) + { + response.CHFID = reader["CHFID"].ToString(); + response.PhotoPath = reader["PhotoPath"].ToString(); + response.InsureeName = reader["InsureeName"].ToString(); + response.DOB = reader["DOB"].ToString(); + response.Gender = reader["Gender"].ToString(); + + firstValue = false; + } + + details.Add(new DetailModel + { + ProductName = reader["ProductName"].ToString(), + ExpiryDate = reader["ExpiryDate"].ToString(), + Status = reader["Status"].ToString(), + DedType = reader["DedType"].ToString().ToNullableFloat(), + Ded1 = reader["Ded1"].ToString().ToNullableDecimal(), + Ded2 = reader["Ded2"].ToString().ToNullableDecimal(), + Ceiling1 = reader["Ceiling1"].ToString().ToNullableDecimal(), + Ceiling2 = reader["Ceiling2"].ToString().ToNullableDecimal(), + ProductCode = reader["ProductCode"].ToString() + }); + } + } while (reader.NextResult()); + } + } + } + + response.Details = details; + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + } +} diff --git a/OpenImis.RestApi/Controllers/V2/InsureeController.cs b/OpenImis.RestApi/Controllers/V2/InsureeController.cs new file mode 100644 index 00000000..a4925e7d --- /dev/null +++ b/OpenImis.RestApi/Controllers/V2/InsureeController.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using OpenImis.ModulesV2; +using OpenImis.ModulesV2.InsureeModule.Models; +using OpenImis.RestApi.Security; + +namespace OpenImis.RestApi.Controllers.V2 +{ + [ApiVersion("2")] + [Authorize] + [Route("api/insuree/")] + [ApiController] + public class InsureeController : Controller + { + private readonly IImisModules _imisModules; + + public InsureeController(IImisModules imisModules) + { + _imisModules = imisModules; + } + + [HasRights(Rights.InsureeEnquire)] + [HttpGet] + [Route("{chfid}")] + public IActionResult Get(string chfid) + { + GetInsureeModel getInsureeModel; + + try + { + getInsureeModel = _imisModules.GetInsureeModule().GetInsureeLogic().Get(chfid); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + if (getInsureeModel == null) + { + return NotFound(); + } + + return Ok(getInsureeModel); + } + } +} \ No newline at end of file diff --git a/OpenImis.RestApi/openImisModules.json b/OpenImis.RestApi/openImisModules.json index 17444b67..42fd74e2 100644 --- a/OpenImis.RestApi/openImisModules.json +++ b/OpenImis.RestApi/openImisModules.json @@ -34,7 +34,8 @@ "InsureeModule": { "FamilyLogic": "OpenImis.ModulesV2.InsureeModule.Logic.FamilyLogic", "PolicyLogic": "OpenImis.ModulesV2.InsureeModule.Logic.PolicyLogic", - "ContributionLogic": "OpenImis.ModulesV2.InsureeModule.Logic.ContributionLogic" + "ContributionLogic": "OpenImis.ModulesV2.InsureeModule.Logic.ContributionLogic", + "InsureeLogic": "OpenImis.ModulesV2.InsureeModule.Logic.InsureeLogic" }, "PaymentModule": { "PaymentLogic": "OpenImis.ModulesV2.PaymentModule.Logic.PaymentLogic" From c545961ab51a64c8327ad62dc928f4506b0fc5d6 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Fri, 30 Aug 2019 09:27:32 +0200 Subject: [PATCH 47/86] OS-58: Added method for Get Enquire --- .../InsureeModule/Logic/IInsureeLogic.cs | 1 + .../InsureeModule/Logic/InsureeLogic.cs | 9 +++++++ .../InsureeModule/Models/GetEnquireModel.cs | 15 ++++++++++++ .../InsureeModule/Models/GetInsureeModel.cs | 19 ++++++++++----- .../Controllers/V2/InsureeController.cs | 24 +++++++++++++++++++ 5 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/GetEnquireModel.cs diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/IInsureeLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/IInsureeLogic.cs index 9cca9464..488a5695 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/IInsureeLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/IInsureeLogic.cs @@ -5,5 +5,6 @@ namespace OpenImis.ModulesV2.InsureeModule.Logic public interface IInsureeLogic { GetInsureeModel Get(string chfid); + GetEnquireModel GetEnquire(string chfid); } } diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/InsureeLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/InsureeLogic.cs index 2c557471..565b7eb6 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/InsureeLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/InsureeLogic.cs @@ -24,5 +24,14 @@ public GetInsureeModel Get(string chfid) return response; } + + public GetEnquireModel GetEnquire(string chfid) + { + GetInsureeModel insuree = insureeRepository.Get(chfid); + + GetEnquireModel response = insuree.GetEnquire(); + + return response; + } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/GetEnquireModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/GetEnquireModel.cs new file mode 100644 index 00000000..2a8d2470 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/GetEnquireModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models +{ + public class GetEnquireModel + { + public string CHFID { get; set; } + public string PhotoPath { get; set; } + public string InsureeName { get; set; } + public string DOB { get; set; } + public string Gender { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/GetInsureeModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/GetInsureeModel.cs index bb1c2bff..24a55638 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/GetInsureeModel.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/GetInsureeModel.cs @@ -4,13 +4,20 @@ namespace OpenImis.ModulesV2.InsureeModule.Models { - public class GetInsureeModel + public class GetInsureeModel : GetEnquireModel { - public string CHFID { get; set; } - public string PhotoPath { get; set; } - public string InsureeName { get; set; } - public string DOB { get; set; } - public string Gender { get; set; } public List Details { get; set; } + + public GetEnquireModel GetEnquire() + { + return new GetEnquireModel() + { + CHFID = CHFID, + DOB = DOB, + Gender = Gender, + InsureeName = InsureeName, + PhotoPath = PhotoPath + }; + } } } diff --git a/OpenImis.RestApi/Controllers/V2/InsureeController.cs b/OpenImis.RestApi/Controllers/V2/InsureeController.cs index a4925e7d..6fd4d53f 100644 --- a/OpenImis.RestApi/Controllers/V2/InsureeController.cs +++ b/OpenImis.RestApi/Controllers/V2/InsureeController.cs @@ -47,5 +47,29 @@ public IActionResult Get(string chfid) return Ok(getInsureeModel); } + + [HasRights(Rights.InsureeEnquire)] + [HttpGet] + [Route("{chfid}/enquire")] + public IActionResult GetEnquire(string chfid) + { + GetEnquireModel getEnquireModel; + + try + { + getEnquireModel = _imisModules.GetInsureeModule().GetInsureeLogic().GetEnquire(chfid); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + if (getEnquireModel == null) + { + return NotFound(); + } + + return Ok(getEnquireModel); + } } } \ No newline at end of file From 0b92717bf91a44ea6909729b599b0a8b91cc1cc1 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Fri, 30 Aug 2019 16:44:36 +0200 Subject: [PATCH 48/86] OS-58: Change of code structure --- .../InsureeModule/Logic/InsureeLogic.cs | 12 +++--- .../InsureeModule/Models/GetEnquireModel.cs | 20 ++++++--- .../InsureeModule/Models/GetInsureeModel.cs | 20 +++------ .../Repositories/IInsureeRepository.cs | 1 + .../Repositories/InsureeRepository.cs | 43 ++++++++++++++++++- 5 files changed, 68 insertions(+), 28 deletions(-) diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/InsureeLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/InsureeLogic.cs index 565b7eb6..b8892701 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/InsureeLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/InsureeLogic.cs @@ -16,20 +16,20 @@ public InsureeLogic(IConfiguration configuration) insureeRepository = new InsureeRepository(_configuration); } - public GetInsureeModel Get(string chfid) + public GetEnquireModel GetEnquire(string chfid) { - GetInsureeModel response; + GetEnquireModel response; - response = insureeRepository.Get(chfid); + response = insureeRepository.GetEnquire(chfid); return response; } - public GetEnquireModel GetEnquire(string chfid) + public GetInsureeModel Get(string chfid) { - GetInsureeModel insuree = insureeRepository.Get(chfid); + GetInsureeModel response; - GetEnquireModel response = insuree.GetEnquire(); + response = insureeRepository.Get(chfid); return response; } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/GetEnquireModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/GetEnquireModel.cs index 2a8d2470..40ab82b8 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/GetEnquireModel.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/GetEnquireModel.cs @@ -4,12 +4,20 @@ namespace OpenImis.ModulesV2.InsureeModule.Models { - public class GetEnquireModel + public class GetEnquireModel : GetInsureeModel { - public string CHFID { get; set; } - public string PhotoPath { get; set; } - public string InsureeName { get; set; } - public string DOB { get; set; } - public string Gender { get; set; } + public List Details { get; set; } + + public GetInsureeModel GetInsuree() + { + return new GetInsureeModel() + { + CHFID = CHFID, + DOB = DOB, + Gender = Gender, + InsureeName = InsureeName, + PhotoPath = PhotoPath + }; + } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/GetInsureeModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/GetInsureeModel.cs index 24a55638..0c8ef583 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/GetInsureeModel.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/GetInsureeModel.cs @@ -4,20 +4,12 @@ namespace OpenImis.ModulesV2.InsureeModule.Models { - public class GetInsureeModel : GetEnquireModel + public class GetInsureeModel { - public List Details { get; set; } - - public GetEnquireModel GetEnquire() - { - return new GetEnquireModel() - { - CHFID = CHFID, - DOB = DOB, - Gender = Gender, - InsureeName = InsureeName, - PhotoPath = PhotoPath - }; - } + public string CHFID { get; set; } + public string PhotoPath { get; set; } + public string InsureeName { get; set; } + public string DOB { get; set; } + public string Gender { get; set; } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/IInsureeRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/IInsureeRepository.cs index 3ba6f12f..4086ada3 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/IInsureeRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/IInsureeRepository.cs @@ -4,6 +4,7 @@ namespace OpenImis.ModulesV2.InsureeModule.Repositories { public interface IInsureeRepository { + GetEnquireModel GetEnquire(string chfid); GetInsureeModel Get(string chfid); } } diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/InsureeRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/InsureeRepository.cs index 03c61cdd..f352868e 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/InsureeRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/InsureeRepository.cs @@ -8,8 +8,10 @@ using System.Data; using System.Data.Common; using System.Data.SqlClient; +using System.Linq; using System.Diagnostics; using System.Text; +using System.Globalization; namespace OpenImis.ModulesV2.InsureeModule.Repositories { @@ -22,9 +24,9 @@ public InsureeRepository(IConfiguration configuration) _configuration = configuration; } - public GetInsureeModel Get(string chfid) + public GetEnquireModel GetEnquire(string chfid) { - GetInsureeModel response = new GetInsureeModel(); + GetEnquireModel response = new GetEnquireModel(); List details = new List(); try @@ -95,5 +97,42 @@ public GetInsureeModel Get(string chfid) throw e; } } + + public GetInsureeModel Get(string chfid) + { + GetInsureeModel response = new GetInsureeModel(); + + try + { + using (var imisContext = new ImisDB()) + { + response = (from I in imisContext.TblInsuree + join P in imisContext.TblPhotos on I.Chfid equals P.Chfid + join G in imisContext.TblGender on I.Gender equals G.Code + where I.Chfid == chfid + && I.ValidityTo == null + && P.ValidityTo == null + select new GetInsureeModel() + { + CHFID = I.Chfid, + DOB = I.Dob.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture), + Gender = G.Gender, + InsureeName = I.LastName + " " + I.OtherNames, + PhotoPath = P.PhotoFolder + P.PhotoFileName + }) + .FirstOrDefault(); + } + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } } } From b544558ec8f6f6a77e7c89a71bb63b3cd65bd77e Mon Sep 17 00:00:00 2001 From: bkaminski Date: Tue, 3 Sep 2019 15:36:01 +0200 Subject: [PATCH 49/86] OS-38: Added first version of module --- OpenImis.DB.SqlServer/TblPolicyRenewals.cs | 1 + .../InsureeModule/Logic/IPolicyLogic.cs | 7 +- .../InsureeModule/Logic/PolicyLogic.cs | 35 ++++ .../InsureeModule/Models/GetPolicyModel.cs | 22 +++ .../InsureeModule/Models/Policy.cs | 11 ++ .../Models/PolicyRenewalModel.cs | 34 ++++ .../Repositories/IPolicyRepository.cs | 13 ++ .../Repositories/PolicyRepository.cs | 177 ++++++++++++++++++ .../Controllers/V2/PolicyController.cs | 84 +++++++++ 9 files changed, 382 insertions(+), 2 deletions(-) create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/GetPolicyModel.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/Policy.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Models/PolicyRenewalModel.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Repositories/IPolicyRepository.cs create mode 100644 OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs create mode 100644 OpenImis.RestApi/Controllers/V2/PolicyController.cs diff --git a/OpenImis.DB.SqlServer/TblPolicyRenewals.cs b/OpenImis.DB.SqlServer/TblPolicyRenewals.cs index bd01b404..311ab5b2 100644 --- a/OpenImis.DB.SqlServer/TblPolicyRenewals.cs +++ b/OpenImis.DB.SqlServer/TblPolicyRenewals.cs @@ -11,6 +11,7 @@ public TblPolicyRenewals() } public int RenewalId { get; set; } + public Guid RenewalUUID { get; set; } public DateTime RenewalPromptDate { get; set; } public DateTime RenewalDate { get; set; } public int? NewOfficerId { get; set; } diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs index d0200b2c..cef661fb 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs @@ -1,4 +1,5 @@ -using System; +using OpenImis.ModulesV2.InsureeModule.Models; +using System; using System.Collections.Generic; using System.Text; @@ -6,6 +7,8 @@ namespace OpenImis.ModulesV2.InsureeModule.Logic { public interface IPolicyLogic { - + List Get(string officerCode); + int Post(PolicyRenewalModel policy); + int Delete(Guid uuid); } } diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs index ac2072b2..2c1048fc 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs @@ -1,4 +1,8 @@ using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.InsureeModule.Models; +using OpenImis.ModulesV2.InsureeModule.Repositories; +using System; +using System.Collections.Generic; namespace OpenImis.ModulesV2.InsureeModule.Logic { @@ -6,9 +10,40 @@ public class PolicyLogic : IPolicyLogic { private IConfiguration _configuration; + protected IPolicyRepository policyRepository; + public PolicyLogic(IConfiguration configuration) { _configuration = configuration; + + policyRepository = new PolicyRepository(_configuration); + } + + public List Get(string officerCode) + { + List response; + + response = policyRepository.Get(officerCode); + + return response; + + } + public int Post(PolicyRenewalModel policy) + { + int response; + + response = policyRepository.Post(policy); + + return response; + } + + public int Delete(Guid uuid) + { + int response; + + response = policyRepository.Delete(uuid); + + return response; } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/GetPolicyModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/GetPolicyModel.cs new file mode 100644 index 00000000..bcf67743 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/GetPolicyModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models +{ + public class GetPolicyModel + { + public int RenewalId { get; set; } + public int PolicyId { get; set; } + public int OfficerId { get; set; } + public string OfficerCode { get; set; } + public string CHFID { get; set; } + public string LastName { get; set; } + public string OtherNames { get; set; } + public string ProductCode { get; set; } + public string ProductName { get; set; } + public string VillageName { get; set; } + public string RenewalPromptDate { get; set; } + public string Phone { get; set; } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/Policy.cs b/OpenImis.ModulesV2/InsureeModule/Models/Policy.cs new file mode 100644 index 00000000..db045230 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/Policy.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.InsureeModule.Models +{ + public class Policy : PolicyRenewalModel + { + + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/PolicyRenewalModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/PolicyRenewalModel.cs new file mode 100644 index 00000000..0eac3f91 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Models/PolicyRenewalModel.cs @@ -0,0 +1,34 @@ +using System; + +namespace OpenImis.ModulesV2.InsureeModule.Models +{ + public class PolicyRenewalModel + { + public int RenewalId { get; set; } + public string Officer { get; set; } + public string CHFID { get; set; } + public string ReceiptNo { get; set; } + public string ProductCode { get; set; } + public float Amount { get; set; } + public string Date { get; set; } + public bool Discontinue { get; set; } + public int PayerId { get; set; } + + + public Policy GetPolicy() + { + return new Policy() + { + RenewalId = RenewalId, + Officer = Officer, + CHFID = CHFID, + ReceiptNo = ReceiptNo, + ProductCode = ProductCode, + Amount = Amount, + Date = Date, + Discontinue = Discontinue, + PayerId = PayerId + }; + } + } +} \ No newline at end of file diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/IPolicyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/IPolicyRepository.cs new file mode 100644 index 00000000..80992875 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/IPolicyRepository.cs @@ -0,0 +1,13 @@ +using OpenImis.ModulesV2.InsureeModule.Models; +using System; +using System.Collections.Generic; + +namespace OpenImis.ModulesV2.InsureeModule.Repositories +{ + public interface IPolicyRepository + { + List Get(string officerCode); + int Post(PolicyRenewalModel policy); + int Delete(Guid uuid); + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs new file mode 100644 index 00000000..e505f4d5 --- /dev/null +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs @@ -0,0 +1,177 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.Helpers; +using OpenImis.ModulesV2.InsureeModule.Helpers; +using OpenImis.ModulesV2.InsureeModule.Models; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.Data.SqlClient; +using System.Diagnostics; +using System.Linq; + +namespace OpenImis.ModulesV2.InsureeModule.Repositories +{ + public class PolicyRepository : IPolicyRepository + { + private IConfiguration _configuration; + + public PolicyRepository(IConfiguration configuration) + { + _configuration = configuration; + } + + public List Get(string officerCode) + { + List response = new List(); + + try + { + using (var imisContext = new ImisDB()) + { + var officerCodeParameter = new SqlParameter("@OfficerCode", SqlDbType.NVarChar, 8); + officerCodeParameter.Value = officerCode; + + var sql = "exec uspGetPolicyRenewals @OfficerCode"; + + DbConnection connection = imisContext.Database.GetDbConnection(); + + using (DbCommand cmd = connection.CreateCommand()) + { + cmd.CommandText = sql; + + cmd.Parameters.AddRange(new[] { officerCodeParameter }); + + if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); + + using (var reader = cmd.ExecuteReader()) + { + do + { + while (reader.Read()) + { + response.Add(new GetPolicyModel() + { + RenewalId = int.Parse(reader["RenewalId"].ToString()), + PolicyId = int.Parse(reader["PolicyId"].ToString()), + OfficerId = int.Parse(reader["OfficerId"].ToString()), + OfficerCode = reader["OfficerCode"].ToString(), + CHFID = reader["CHFID"].ToString(), + LastName = reader["LastName"].ToString(), + OtherNames = reader["OtherNames"].ToString(), + ProductCode = reader["ProductCode"].ToString(), + ProductName = reader["ProductName"].ToString(), + VillageName = reader["VillageName"].ToString(), + RenewalPromptDate = reader["RenewalPromptDate"].ToString(), + Phone = reader["Phone"].ToString() + }); + } + } while (reader.NextResult()); + } + } + } + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + + public int Post(PolicyRenewalModel policy) + { + int RV = -99; + + try + { + var policyRenew = policy.GetPolicy(); + var XML = policyRenew.XMLSerialize(); + + Debug.WriteLine(XML); + + string fileName = "test"; + + using (var imisContext = new ImisDB()) + { + var xmlParameter = new SqlParameter("@XML", XML) { DbType = DbType.Xml }; + var returnParameter = OutputParameter.CreateOutputParameter("@RV", SqlDbType.Int); + var fileNameParameter = new SqlParameter("@FileName", SqlDbType.NVarChar, 200); + fileNameParameter.Value = fileName; + + var sql = "exec @RV = uspIsValidRenewal @FileName, @XML"; + + DbConnection connection = imisContext.Database.GetDbConnection(); + + using (DbCommand cmd = connection.CreateCommand()) + { + cmd.CommandText = sql; + + cmd.Parameters.AddRange(new[] { fileNameParameter, xmlParameter, returnParameter }); + + if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); + + using (var reader = cmd.ExecuteReader()) + { + // Displaying errors in the Stored Procedure in Debug mode + //do + //{ + // while (reader.Read()) + // { + // Debug.WriteLine("Error/Warning: " + reader.GetValue(0)); + // } + //} while (reader.NextResult()); + } + } + + RV = (int)returnParameter.Value; + } + + return RV; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + + public int Delete(Guid uuid) + { + int response = 0; + + try + { + using (var imisContext = new ImisDB()) + { + var renewal = imisContext.TblPolicyRenewals.SingleOrDefault(pr => pr.RenewalUUID == uuid); + + if (renewal == null) return -1; + + renewal.ResponseStatus = 2; + renewal.ResponseDate = DateTime.Now; + imisContext.SaveChanges(); + } + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + } +} diff --git a/OpenImis.RestApi/Controllers/V2/PolicyController.cs b/OpenImis.RestApi/Controllers/V2/PolicyController.cs new file mode 100644 index 00000000..d0b0070e --- /dev/null +++ b/OpenImis.RestApi/Controllers/V2/PolicyController.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using OpenImis.ModulesV2; +using OpenImis.ModulesV2.InsureeModule.Models; +using OpenImis.RestApi.Security; + +namespace OpenImis.RestApi.Controllers.V2 +{ + [ApiVersion("2")] + [Authorize] + [Route("api/policy/")] + [ApiController] + public class PolicyController : Controller + { + private readonly IImisModules _imisModules; + + public PolicyController(IImisModules imisModules) + { + _imisModules = imisModules; + } + + //[HasRights(Rights.PolicySearch)] + [HttpGet] + [Route("officer/{officerCode}")] + public IActionResult Get(string officerCode) + { + List response; + + try + { + response = _imisModules.GetInsureeModule().GetPolicyLogic().Get(officerCode); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + return Ok(response); + } + + //[HasRights(Rights.PolicyRenew)] + [HttpPost] + [Route("renew")] + public IActionResult Post([FromBody]PolicyRenewalModel model) + { + int response; + + try + { + response = _imisModules.GetInsureeModule().GetPolicyLogic().Post(model); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + return Ok(response); + } + + //[HasRights(Rights.PolicyDelete)] + [HttpDelete] + [Route("renew/{uuid}")] + public IActionResult Delete(Guid uuid) + { + int response; + + try + { + response = _imisModules.GetInsureeModule().GetPolicyLogic().Delete(uuid); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + return Ok(response); + } + } +} \ No newline at end of file From 71bb9cebd67d41c4b623a8d9310da2faf8496c54 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Tue, 3 Sep 2019 17:30:19 +0200 Subject: [PATCH 50/86] OS-59: Added first endpoint (Get Feedbacks) --- OpenImis.DB.SqlServer/TblClaim.cs | 1 + .../FeedbackModule/Logic/FeedbackLogic.cs | 26 ++++++ .../FeedbackModule/Logic/IFeedbackLogic.cs | 6 +- .../FeedbackModule/Models/FeedbackModel.cs | 23 +++++ .../Repositories/FeedbackRepository.cs | 92 +++++++++++++++++++ .../Repositories/IFeedbackRepository.cs | 13 +++ OpenImis.ModulesV2/IImisModules.cs | 3 + .../Controllers/V2/FeedbackController.cs | 50 ++++++++++ 8 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 OpenImis.ModulesV2/FeedbackModule/Models/FeedbackModel.cs create mode 100644 OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs create mode 100644 OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs create mode 100644 OpenImis.RestApi/Controllers/V2/FeedbackController.cs diff --git a/OpenImis.DB.SqlServer/TblClaim.cs b/OpenImis.DB.SqlServer/TblClaim.cs index eec36ffd..a2250c85 100644 --- a/OpenImis.DB.SqlServer/TblClaim.cs +++ b/OpenImis.DB.SqlServer/TblClaim.cs @@ -13,6 +13,7 @@ public TblClaim() } public int ClaimId { get; set; } + public Guid ClaimUUID { get; set; } public int InsureeId { get; set; } public string ClaimCode { get; set; } public DateTime DateFrom { get; set; } diff --git a/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs b/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs index 23f180fc..4aae1581 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs @@ -1,4 +1,8 @@ using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.FeedbackModule.Models; +using OpenImis.ModulesV2.FeedbackModule.Repositories; +using System; +using System.Collections.Generic; namespace OpenImis.ModulesV2.FeedbackModule.Logic { @@ -6,9 +10,31 @@ public class FeedbackLogic: IFeedbackLogic { private IConfiguration _configuration; + protected IFeedbackRepository feedbackRepository; + public FeedbackLogic(IConfiguration configuration) { _configuration = configuration; + + feedbackRepository = new FeedbackRepository(_configuration); + } + + public List Get(string officerCode) + { + List response; + + response = feedbackRepository.Get(officerCode); + + return response; + } + + public string GetLoginNameByUserUUID(Guid userUUID) + { + string response; + + response = feedbackRepository.GetLoginNameByUserUUID(userUUID); + + return response; } } } diff --git a/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs b/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs index 59f047b4..9a722d79 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs @@ -1,8 +1,12 @@ -using System; +using OpenImis.ModulesV2.FeedbackModule.Models; +using System; +using System.Collections.Generic; namespace OpenImis.ModulesV2.FeedbackModule.Logic { public interface IFeedbackLogic { + List Get(string officerCode); + string GetLoginNameByUserUUID(Guid userUUID); } } diff --git a/OpenImis.ModulesV2/FeedbackModule/Models/FeedbackModel.cs b/OpenImis.ModulesV2/FeedbackModule/Models/FeedbackModel.cs new file mode 100644 index 00000000..fa1d65c5 --- /dev/null +++ b/OpenImis.ModulesV2/FeedbackModule/Models/FeedbackModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.FeedbackModule.Models +{ + public class FeedbackModel + { + public Guid ClaimUUID { get; set; } + public int? OfficerId { get; set; } + public string OfficerCode { get; set; } + public string CHFID { get; set; } + public string LastName { get; set; } + public string OtherNames { get; set; } + public string HFCode { get; set; } + public string HFName { get; set; } + public string ClaimCode { get; set; } + public string DateFrom { get; set; } + public string DateTo { get; set; } + public string Phone { get; set; } + public string FeedbackPromptDate { get; set; } + } +} diff --git a/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs new file mode 100644 index 00000000..d29adfe8 --- /dev/null +++ b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs @@ -0,0 +1,92 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.FeedbackModule.Models; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Globalization; +using System.Linq; +using System.Text; + +namespace OpenImis.ModulesV2.FeedbackModule.Repositories +{ + public class FeedbackRepository : IFeedbackRepository + { + private IConfiguration _configuration; + + public FeedbackRepository(IConfiguration configuration) + { + _configuration = configuration; + } + + public List Get(string officerCode) + { + List response = new List(); + + try + { + using (var imisContext = new ImisDB()) + { + response = (from F in imisContext.TblFeedbackPrompt + join O in imisContext.TblOfficer on F.OfficerId equals O.OfficerId + join C in imisContext.TblClaim on F.ClaimId equals C.ClaimId + join I in imisContext.TblInsuree on C.InsureeId equals I.InsureeId + join HF in imisContext.TblHf on C.Hfid equals HF.HfId + where F.ValidityTo == null + && O.ValidityTo == null + && O.Code == officerCode + && C.FeedbackStatus == 4 + select new FeedbackModel() + { + ClaimUUID = C.ClaimUUID, + OfficerId = F.OfficerId, + OfficerCode = O.Code, + CHFID = I.Chfid, + LastName = I.LastName, + OtherNames = I.OtherNames, + HFCode = HF.Hfcode, + HFName = HF.Hfname, + ClaimCode = C.ClaimCode, + DateFrom = C.DateFrom.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture), + DateTo = C.DateTo.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture), + Phone = O.Phone, + FeedbackPromptDate = F.FeedbackPromptDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + }) + .ToList(); + } + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + + public string GetLoginNameByUserUUID(Guid userUUID) + { + string response; + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.TblUsers + .Where(u => u.UserUUID == userUUID) + .Select(x => x.LoginName) + .FirstOrDefault(); + } + + return response; + } + catch (SqlException e) + { + throw e; + } + } + } +} diff --git a/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs b/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs new file mode 100644 index 00000000..16f97777 --- /dev/null +++ b/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs @@ -0,0 +1,13 @@ +using OpenImis.ModulesV2.FeedbackModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.FeedbackModule.Repositories +{ + public interface IFeedbackRepository + { + List Get(string officerCode); + string GetLoginNameByUserUUID(Guid userUUID); + } +} diff --git a/OpenImis.ModulesV2/IImisModules.cs b/OpenImis.ModulesV2/IImisModules.cs index 677b06ce..3833ebc1 100644 --- a/OpenImis.ModulesV2/IImisModules.cs +++ b/OpenImis.ModulesV2/IImisModules.cs @@ -4,6 +4,7 @@ using OpenImis.ModulesV2.CoverageModule; using OpenImis.ModulesV2.PaymentModule; using OpenImis.ModulesV2.MasterDataModule; +using OpenImis.ModulesV2.FeedbackModule; namespace OpenImis.ModulesV2 { @@ -23,5 +24,7 @@ public interface IImisModules IPaymentModule GetPaymentModule(); IMasterDataModule GetMasterDataModule(); + + IFeedbackModule GetFeedbackModule(); } } diff --git a/OpenImis.RestApi/Controllers/V2/FeedbackController.cs b/OpenImis.RestApi/Controllers/V2/FeedbackController.cs new file mode 100644 index 00000000..af7bca8c --- /dev/null +++ b/OpenImis.RestApi/Controllers/V2/FeedbackController.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using OpenImis.ModulesV2; +using OpenImis.ModulesV2.FeedbackModule.Models; +using OpenImis.RestApi.Security; + +namespace OpenImis.RestApi.Controllers.V2 +{ + [ApiVersion("2")] + [Authorize] + [Route("api/feedback/")] + [ApiController] + public class FeedbackController : Controller + { + private readonly IImisModules _imisModules; + + public FeedbackController(IImisModules imisModules) + { + _imisModules = imisModules; + } + + //[HasRights(Rights.ClaimFeedback)] + [HttpGet] + public IActionResult Get() + { + List response; + + try + { + Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); + + string officerCode = _imisModules.GetFeedbackModule().GetFeedbackLogic().GetLoginNameByUserUUID(userUUID); + + response = _imisModules.GetFeedbackModule().GetFeedbackLogic().Get(officerCode); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + return Ok(response); + } + } +} \ No newline at end of file From 75e3af997c2f45811e73e748020487f45039a6b0 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 5 Sep 2019 11:46:13 +0200 Subject: [PATCH 51/86] OS-57: Added endpoint similar to from WS --- OpenImis.ModulesV2/IImisModules.cs | 3 ++ .../SystemModule/Logic/ISystemLogic.cs | 1 + .../SystemModule/Logic/SystemLogic.cs | 14 +++++++ .../Repositories/ISystemRepository.cs | 11 +++++ .../Repositories/SystemRepository.cs | 40 +++++++++++++++++++ .../Controllers/V2/SystemController.cs | 40 +++++++++++++++++++ 6 files changed, 109 insertions(+) create mode 100644 OpenImis.ModulesV2/SystemModule/Repositories/ISystemRepository.cs create mode 100644 OpenImis.ModulesV2/SystemModule/Repositories/SystemRepository.cs create mode 100644 OpenImis.RestApi/Controllers/V2/SystemController.cs diff --git a/OpenImis.ModulesV2/IImisModules.cs b/OpenImis.ModulesV2/IImisModules.cs index 677b06ce..6135f3ee 100644 --- a/OpenImis.ModulesV2/IImisModules.cs +++ b/OpenImis.ModulesV2/IImisModules.cs @@ -4,6 +4,7 @@ using OpenImis.ModulesV2.CoverageModule; using OpenImis.ModulesV2.PaymentModule; using OpenImis.ModulesV2.MasterDataModule; +using OpenImis.ModulesV2.SystemModule; namespace OpenImis.ModulesV2 { @@ -23,5 +24,7 @@ public interface IImisModules IPaymentModule GetPaymentModule(); IMasterDataModule GetMasterDataModule(); + + ISystemModule GetSystemModule(); } } diff --git a/OpenImis.ModulesV2/SystemModule/Logic/ISystemLogic.cs b/OpenImis.ModulesV2/SystemModule/Logic/ISystemLogic.cs index aa7670cd..caf56950 100644 --- a/OpenImis.ModulesV2/SystemModule/Logic/ISystemLogic.cs +++ b/OpenImis.ModulesV2/SystemModule/Logic/ISystemLogic.cs @@ -4,5 +4,6 @@ namespace OpenImis.ModulesV2.SystemModule.Logic { public interface ISystemLogic { + string Get(string name); } } diff --git a/OpenImis.ModulesV2/SystemModule/Logic/SystemLogic.cs b/OpenImis.ModulesV2/SystemModule/Logic/SystemLogic.cs index 1502327a..191f3411 100644 --- a/OpenImis.ModulesV2/SystemModule/Logic/SystemLogic.cs +++ b/OpenImis.ModulesV2/SystemModule/Logic/SystemLogic.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.SystemModule.Repositories; namespace OpenImis.ModulesV2.SystemModule.Logic { @@ -6,9 +7,22 @@ public class SystemLogic : ISystemLogic { private IConfiguration _configuration; + protected ISystemRepository systemRepository; + public SystemLogic(IConfiguration configuration) { _configuration = configuration; + + systemRepository = new SystemRepository(_configuration); + } + + public string Get(string name) + { + string response; + + response = systemRepository.Get(name); + + return response; } } } diff --git a/OpenImis.ModulesV2/SystemModule/Repositories/ISystemRepository.cs b/OpenImis.ModulesV2/SystemModule/Repositories/ISystemRepository.cs new file mode 100644 index 00000000..57ac3c59 --- /dev/null +++ b/OpenImis.ModulesV2/SystemModule/Repositories/ISystemRepository.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.SystemModule.Repositories +{ + public interface ISystemRepository + { + string Get(string name); + } +} diff --git a/OpenImis.ModulesV2/SystemModule/Repositories/SystemRepository.cs b/OpenImis.ModulesV2/SystemModule/Repositories/SystemRepository.cs new file mode 100644 index 00000000..9cb73b27 --- /dev/null +++ b/OpenImis.ModulesV2/SystemModule/Repositories/SystemRepository.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; + +namespace OpenImis.ModulesV2.SystemModule.Repositories +{ + public class SystemRepository : ISystemRepository + { + private IConfiguration _configuration; + + public SystemRepository(IConfiguration configuration) + { + _configuration = configuration; + } + + public string Get(string name) + { + string response; + + try + { + using (var imisContext = new ImisDB()) + { + var row = imisContext.TblImisdefaults.FirstOrDefault(); + response = row.GetType().GetProperty(name).GetValue(row, null).ToString(); + } + + return response; + } + catch { } + + return null; + } + } +} \ No newline at end of file diff --git a/OpenImis.RestApi/Controllers/V2/SystemController.cs b/OpenImis.RestApi/Controllers/V2/SystemController.cs new file mode 100644 index 00000000..fa230043 --- /dev/null +++ b/OpenImis.RestApi/Controllers/V2/SystemController.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using OpenImis.ModulesV2; + +namespace OpenImis.RestApi.Controllers.V2 +{ + [ApiVersion("2")] + [Authorize] + [Route("api/system/")] + [ApiController] + public class SystemController : Controller + { + private readonly IImisModules _imisModules; + + public SystemController(IImisModules imisModules) + { + _imisModules = imisModules; + } + + [AllowAnonymous] + [HttpGet] + [Route("apkversion/{APK_Name}")] + public IActionResult Get(string APK_Name) + { + string response = _imisModules.GetSystemModule().GetSystemLogic().Get(APK_Name); + + if (response == null) + { + return BadRequest(); + } + + return Ok(response); + } + } +} \ No newline at end of file From 3cf5f5743bb7640fbf900f3f2e6a9357d347e6ab Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 12 Sep 2019 11:40:17 +0200 Subject: [PATCH 52/86] OS-39: Added Report Module --- .../Helpers/ConfigImisModules.cs | 6 + OpenImis.ModulesV2/IImisModules.cs | 3 + OpenImis.ModulesV2/ImisModules.cs | 22 +++ .../ReportModule/IReportModule.cs | 13 ++ .../ReportModule/Logic/IReportLogic.cs | 11 ++ .../ReportModule/Logic/ReportLogic.cs | 45 ++++++ .../ReportModule/Models/EnrolmentModel.cs | 12 ++ .../ReportModule/Models/FeedbackModel.cs | 12 ++ .../ReportModule/Models/RenewalModel.cs | 10 ++ .../ReportModule/Models/ReportRequestModel.cs | 11 ++ .../ReportModule/ReportModule.cs | 31 ++++ .../Repositories/IReportRepository.cs | 11 ++ .../Repositories/ReportRepository.cs | 149 ++++++++++++++++++ .../Controllers/V2/ReportController.cs | 96 +++++++++++ OpenImis.RestApi/openImisModules.json | 3 + 15 files changed, 435 insertions(+) create mode 100644 OpenImis.ModulesV2/ReportModule/IReportModule.cs create mode 100644 OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs create mode 100644 OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs create mode 100644 OpenImis.ModulesV2/ReportModule/Models/EnrolmentModel.cs create mode 100644 OpenImis.ModulesV2/ReportModule/Models/FeedbackModel.cs create mode 100644 OpenImis.ModulesV2/ReportModule/Models/RenewalModel.cs create mode 100644 OpenImis.ModulesV2/ReportModule/Models/ReportRequestModel.cs create mode 100644 OpenImis.ModulesV2/ReportModule/ReportModule.cs create mode 100644 OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs create mode 100644 OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs create mode 100644 OpenImis.RestApi/Controllers/V2/ReportController.cs diff --git a/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs b/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs index bf80f1d7..94b478da 100644 --- a/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs +++ b/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs @@ -17,6 +17,7 @@ public class ConfigImisModules public PremiumModule PremiumModule { get; set; } public SystemModule SystemModule { get; set; } public MasterDataModule MasterDataModule { get; set; } + public ReportModule ReportModule { get; set; } } public class LoginModule @@ -65,4 +66,9 @@ public class MasterDataModule { public string MasterDataLogic { get; set; } } + + public class ReportModule + { + public string ReportLogic { get; set; } + } } diff --git a/OpenImis.ModulesV2/IImisModules.cs b/OpenImis.ModulesV2/IImisModules.cs index 677b06ce..c6b6e1ea 100644 --- a/OpenImis.ModulesV2/IImisModules.cs +++ b/OpenImis.ModulesV2/IImisModules.cs @@ -4,6 +4,7 @@ using OpenImis.ModulesV2.CoverageModule; using OpenImis.ModulesV2.PaymentModule; using OpenImis.ModulesV2.MasterDataModule; +using OpenImis.ModulesV2.ReportModule; namespace OpenImis.ModulesV2 { @@ -23,5 +24,7 @@ public interface IImisModules IPaymentModule GetPaymentModule(); IMasterDataModule GetMasterDataModule(); + + IReportModule GetReportModule(); } } diff --git a/OpenImis.ModulesV2/ImisModules.cs b/OpenImis.ModulesV2/ImisModules.cs index 93e1b8f0..a116cfac 100644 --- a/OpenImis.ModulesV2/ImisModules.cs +++ b/OpenImis.ModulesV2/ImisModules.cs @@ -17,6 +17,9 @@ using Microsoft.AspNetCore.Hosting; using OpenImis.ModulesV2.PremiumModule; using OpenImis.ModulesV2.SystemModule; +using OpenImis.ModulesV2.ReportModule; +using OpenImis.ModulesV2.ReportModule.Logic; + namespace OpenImis.ModulesV2 { public class ImisModules : IImisModules @@ -31,6 +34,7 @@ public class ImisModules : IImisModules private IFeedbackModule feedbackModule; private IPremiumModule premiumModule; private ISystemModule systemModule; + private IReportModule reportModule; private readonly IConfiguration _configuration; private readonly IHostingEnvironment _hostingEnvironment; @@ -213,6 +217,24 @@ public IMasterDataModule GetMasterDataModule() return masterDataModule; } + /// + /// Creates and returns the report module version 2. + /// + /// + /// The Report module V2. + /// + public IReportModule GetReportModule() + { + if (reportModule == null) + { + reportModule = new ReportModule.ReportModule(_configuration); + + Type reportLogicType = CreateTypeFromConfiguration("ReportModule", "ReportLogic", "OpenImis.ModulesV2.ReportModule.Logic.ReportLogic"); + reportModule.SetReportLogic((IReportLogic)ActivatorUtilities.CreateInstance(_serviceProvider, reportLogicType)); + } + return reportModule; + } + /// /// Creates and returns the type based on the string from the configuration /// diff --git a/OpenImis.ModulesV2/ReportModule/IReportModule.cs b/OpenImis.ModulesV2/ReportModule/IReportModule.cs new file mode 100644 index 00000000..e9b03e7e --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/IReportModule.cs @@ -0,0 +1,13 @@ +using OpenImis.ModulesV2.ReportModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.ReportModule +{ + public interface IReportModule + { + IReportLogic GetReportLogic(); + IReportModule SetReportLogic(IReportLogic reportLogic); + } +} diff --git a/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs b/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs new file mode 100644 index 00000000..f510b27a --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs @@ -0,0 +1,11 @@ +using OpenImis.ModulesV2.ReportModule.Models; + +namespace OpenImis.ModulesV2.ReportModule.Logic +{ + public interface IReportLogic + { + FeedbackModel GetFeedbackStats(ReportRequestModel feedbackRequestModel); + RenewalModel GetRenewalStats(ReportRequestModel renewalRequestModel); + EnrolmentModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel); + } +} diff --git a/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs b/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs new file mode 100644 index 00000000..ea94057b --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs @@ -0,0 +1,45 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.ReportModule.Models; +using OpenImis.ModulesV2.ReportModule.Repositories; + +namespace OpenImis.ModulesV2.ReportModule.Logic +{ + public class ReportLogic : IReportLogic + { + private IConfiguration _configuration; + protected IReportRepository reportRepository; + + public ReportLogic(IConfiguration configuration) + { + _configuration = configuration; + reportRepository = new ReportRepository(_configuration); + } + + public FeedbackModel GetFeedbackStats(ReportRequestModel feedbackRequestModel) + { + FeedbackModel response; + + response = reportRepository.GetFeedbackStats(feedbackRequestModel); + + return response; + } + + public RenewalModel GetRenewalStats(ReportRequestModel renewalRequestModel) + { + RenewalModel response; + + response = reportRepository.GetRenewalStats(renewalRequestModel); + + return response; + } + + public EnrolmentModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel) + { + EnrolmentModel response; + + response = reportRepository.GetEnrolmentStats(enrolmentRequestModel); + + return response; + } + } +} diff --git a/OpenImis.ModulesV2/ReportModule/Models/EnrolmentModel.cs b/OpenImis.ModulesV2/ReportModule/Models/EnrolmentModel.cs new file mode 100644 index 00000000..cc7519a5 --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/Models/EnrolmentModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.ReportModule.Models +{ + public class EnrolmentModel + { + public int TotalSubmitted { get; set; } + public int TotalAssigned { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ReportModule/Models/FeedbackModel.cs b/OpenImis.ModulesV2/ReportModule/Models/FeedbackModel.cs new file mode 100644 index 00000000..44f77951 --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/Models/FeedbackModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.ReportModule.Models +{ + public class FeedbackModel + { + public int FeedbackSent { get; set; } + public int FeedbackAccepted { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ReportModule/Models/RenewalModel.cs b/OpenImis.ModulesV2/ReportModule/Models/RenewalModel.cs new file mode 100644 index 00000000..e301da86 --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/Models/RenewalModel.cs @@ -0,0 +1,10 @@ +using System; + +namespace OpenImis.ModulesV2.ReportModule.Models +{ + public class RenewalModel + { + public int RenewalSent { get; set; } + public int RenewalAccepted { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ReportModule/Models/ReportRequestModel.cs b/OpenImis.ModulesV2/ReportModule/Models/ReportRequestModel.cs new file mode 100644 index 00000000..85952a2e --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/Models/ReportRequestModel.cs @@ -0,0 +1,11 @@ +using System; + +namespace OpenImis.ModulesV2.ReportModule.Models +{ + public class ReportRequestModel + { + public string OfficerCode { get; set; } + public string FromDate { get; set; } + public string ToDate { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ReportModule/ReportModule.cs b/OpenImis.ModulesV2/ReportModule/ReportModule.cs new file mode 100644 index 00000000..9bbd318c --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/ReportModule.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.ReportModule.Logic; + +namespace OpenImis.ModulesV2.ReportModule +{ + public class ReportModule : IReportModule + { + private IConfiguration _configuration; + private IReportLogic _reportLogic; + + public ReportModule(IConfiguration configuration) + { + _configuration = configuration; + } + + public IReportLogic GetReportLogic() + { + if (_reportLogic == null) + { + _reportLogic = new ReportLogic(_configuration); + } + return _reportLogic; + } + + public IReportModule SetReportLogic(IReportLogic reportLogic) + { + _reportLogic = reportLogic; + return this; + } + } +} diff --git a/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs b/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs new file mode 100644 index 00000000..af9fdc7a --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs @@ -0,0 +1,11 @@ +using OpenImis.ModulesV2.ReportModule.Models; + +namespace OpenImis.ModulesV2.ReportModule.Repositories +{ + public interface IReportRepository + { + FeedbackModel GetFeedbackStats(ReportRequestModel feedbackRequestModel); + RenewalModel GetRenewalStats(ReportRequestModel renewalRequestModel); + EnrolmentModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel); + } +} diff --git a/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs b/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs new file mode 100644 index 00000000..cad991b6 --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs @@ -0,0 +1,149 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.ReportModule.Models; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Diagnostics; +using System.Linq; + +namespace OpenImis.ModulesV2.ReportModule.Repositories +{ + public class ReportRepository : IReportRepository + { + private IConfiguration _configuration; + + public ReportRepository(IConfiguration configuration) + { + _configuration = configuration; + } + + public EnrolmentModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel) + { + EnrolmentModel response = new EnrolmentModel(); + + try + { + using (var imisContext = new ImisDB()) + { + var submitted = (from FP in imisContext.TblFromPhone + join O in imisContext.TblOfficer on FP.OfficerCode equals O.Code + where FP.DocType == "E" + && FP.LandedDate >= DateTime.Parse(enrolmentRequestModel.FromDate) + && FP.LandedDate <= DateTime.Parse(enrolmentRequestModel.ToDate) + && O.ValidityTo == null + && FP.OfficerCode == enrolmentRequestModel.OfficerCode + select new { FromPhone = FP, Officer = O }) + .ToList(); + + var assigned = (from S in submitted + from P in imisContext.TblPhotos + where P.ValidityTo == null + && P.PhotoFileName == S.FromPhone.DocName + && P.OfficerId == S.Officer.OfficerId + select S) + .ToList(); + + response = new EnrolmentModel() + { + TotalSubmitted = submitted.Select(x => x.FromPhone).Count(), + TotalAssigned = assigned.Count(), + }; + } + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + + public FeedbackModel GetFeedbackStats(ReportRequestModel feedbackRequestModel) + { + FeedbackModel response = new FeedbackModel(); + + try + { + using (var imisContext = new ImisDB()) + { + var feedbackSent = (from FP in imisContext.TblFromPhone + where FP.DocType == "F" + && FP.LandedDate >= DateTime.Parse(feedbackRequestModel.FromDate) + && FP.LandedDate <= DateTime.Parse(feedbackRequestModel.ToDate) + && FP.OfficerCode == feedbackRequestModel.OfficerCode + select FP) + .ToList(); + + var feedbackAccepted = feedbackSent + .Where(f => f.DocStatus == "A") + .Count(); + + response = new FeedbackModel() + { + FeedbackSent = feedbackSent.Count(), + FeedbackAccepted = feedbackAccepted + }; + } + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + + public RenewalModel GetRenewalStats(ReportRequestModel renewalRequestModel) + { + RenewalModel response = new RenewalModel(); + + try + { + using (var imisContext = new ImisDB()) + { + var renewalSent = (from FP in imisContext.TblFromPhone + where FP.DocType == "R" + && FP.LandedDate >= DateTime.Parse(renewalRequestModel.FromDate) + && FP.LandedDate <= DateTime.Parse(renewalRequestModel.ToDate) + && FP.OfficerCode == renewalRequestModel.OfficerCode + select FP) + .ToList(); + + foreach (var item in renewalSent) + { + Debug.WriteLine(item.FromPhoneId); + } + + var renewalAccepted = renewalSent + .Where(f => f.DocStatus == "A") + .Count(); + + response = new RenewalModel() + { + RenewalSent = renewalSent.Count(), + RenewalAccepted = renewalAccepted + }; + } + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + } +} \ No newline at end of file diff --git a/OpenImis.RestApi/Controllers/V2/ReportController.cs b/OpenImis.RestApi/Controllers/V2/ReportController.cs new file mode 100644 index 00000000..857e16e0 --- /dev/null +++ b/OpenImis.RestApi/Controllers/V2/ReportController.cs @@ -0,0 +1,96 @@ +using System; +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using OpenImis.ModulesV2; +using OpenImis.ModulesV2.ReportModule.Models; +using OpenImis.RestApi.Security; + +namespace OpenImis.RestApi.Controllers.V2 +{ + [ApiVersion("2")] + [Authorize] + [Route("api/report/")] + [ApiController] + public class ReportController : Controller + { + private readonly IImisModules _imisModules; + + public ReportController(IImisModules imisModules) + { + _imisModules = imisModules; + } + + [HasRights(Rights.ReportsEnrolmentPerformanceIndicators)] + [HttpPost] + [Route("enrolment")] + public IActionResult GetEnrolmentStats([FromBody]ReportRequestModel enrolmentRequestModel) + { + EnrolmentModel enrolmentModel; + + try + { + enrolmentModel = _imisModules.GetReportModule().GetReportLogic().GetEnrolmentStats(enrolmentRequestModel); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + if (enrolmentModel == null) + { + return NotFound(); + } + + return Ok(enrolmentModel); + } + + [HasRights(Rights.ClaimFeedback)] + [HttpPost] + [Route("feedback")] + public IActionResult GetFeedbackStats([FromBody]ReportRequestModel feedbackRequestModel) + { + FeedbackModel feedbackModel; + + try + { + feedbackModel = _imisModules.GetReportModule().GetReportLogic().GetFeedbackStats(feedbackRequestModel); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + if (feedbackModel == null) + { + return NotFound(); + } + + return Ok(feedbackModel); + } + + [HasRights(Rights.ReportsRenewals)] + [HttpPost] + [Route("renewal")] + public IActionResult GetRenewalStats([FromBody]ReportRequestModel renewalRequestModel) + { + RenewalModel renewalModel; + + try + { + renewalModel = _imisModules.GetReportModule().GetReportLogic().GetRenewalStats(renewalRequestModel); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + if (renewalModel == null) + { + return NotFound(); + } + + return Ok(renewalModel); + } + } +} \ No newline at end of file diff --git a/OpenImis.RestApi/openImisModules.json b/OpenImis.RestApi/openImisModules.json index 17444b67..5d887db5 100644 --- a/OpenImis.RestApi/openImisModules.json +++ b/OpenImis.RestApi/openImisModules.json @@ -50,6 +50,9 @@ }, "MasterDataModule": { "MasterDataLogic": "OpenImis.ModulesV2.MasterDataModule.Logic.MasterDataLogic" + }, + "ReportModule": { + "ReportLogic": "OpenImis.ModulesV2.ReportModule.Logic.ReportLogic" } } ] From f685100c786a786935e2432ef654cc80ca698ae9 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 18 Sep 2019 14:58:23 +0200 Subject: [PATCH 53/86] OS-38: Added new version --- .../InsureeModule/InsureeModule.cs | 2 +- .../InsureeModule/Logic/PolicyLogic.cs | 11 ++++--- .../InsureeModule/Models/Policy.cs | 1 - .../Repositories/PolicyRepository.cs | 30 +++++++++++++++---- .../Controllers/V2/PolicyController.cs | 8 ++--- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs b/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs index 19a0dd77..b8728af7 100644 --- a/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs +++ b/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs @@ -41,7 +41,7 @@ public IPolicyLogic GetPolicyLogic() { if (_policyLogic == null) { - _policyLogic = new PolicyLogic(_configuration); + _policyLogic = new PolicyLogic(_configuration, _hostingEnvironment); } return _policyLogic; } diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs index 2c1048fc..e76ca49f 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using OpenImis.ModulesV2.InsureeModule.Models; using OpenImis.ModulesV2.InsureeModule.Repositories; using System; @@ -9,14 +10,16 @@ namespace OpenImis.ModulesV2.InsureeModule.Logic public class PolicyLogic : IPolicyLogic { private IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; protected IPolicyRepository policyRepository; - public PolicyLogic(IConfiguration configuration) + public PolicyLogic(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { _configuration = configuration; + _hostingEnvironment = hostingEnvironment; - policyRepository = new PolicyRepository(_configuration); + policyRepository = new PolicyRepository(_configuration, _hostingEnvironment); } public List Get(string officerCode) @@ -26,8 +29,8 @@ public List Get(string officerCode) response = policyRepository.Get(officerCode); return response; - } + public int Post(PolicyRenewalModel policy) { int response; diff --git a/OpenImis.ModulesV2/InsureeModule/Models/Policy.cs b/OpenImis.ModulesV2/InsureeModule/Models/Policy.cs index db045230..b9e85242 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/Policy.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/Policy.cs @@ -6,6 +6,5 @@ namespace OpenImis.ModulesV2.InsureeModule.Models { public class Policy : PolicyRenewalModel { - } } diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs index e505f4d5..0f9c2562 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using OpenImis.DB.SqlServer; using OpenImis.ModulesV2.Helpers; @@ -9,18 +10,21 @@ using System.Data; using System.Data.Common; using System.Data.SqlClient; -using System.Diagnostics; +using System.IO; using System.Linq; +using System.Xml; namespace OpenImis.ModulesV2.InsureeModule.Repositories { public class PolicyRepository : IPolicyRepository { private IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; - public PolicyRepository(IConfiguration configuration) + public PolicyRepository(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { _configuration = configuration; + _hostingEnvironment = hostingEnvironment; } public List Get(string officerCode) @@ -91,12 +95,28 @@ public int Post(PolicyRenewalModel policy) try { + string webRootPath = _hostingEnvironment.WebRootPath; + var policyRenew = policy.GetPolicy(); var XML = policyRenew.XMLSerialize(); - Debug.WriteLine(XML); + var fromPhoneRenewalDir = _configuration["AppSettings:FromPhone_Renewal"]; + + var fileName = "RenPol_" + policy.Date + "_" + policy.CHFID + "_" + policy.ReceiptNo + ".xml"; + + var xmldoc = new XmlDocument(); + xmldoc.InnerXml = XML; + + try + { + if (!Directory.Exists(webRootPath + fromPhoneRenewalDir)) Directory.CreateDirectory(webRootPath + fromPhoneRenewalDir); - string fileName = "test"; + xmldoc.Save(webRootPath + fromPhoneRenewalDir + fileName); + } + catch (Exception e) + { + throw e; + } using (var imisContext = new ImisDB()) { diff --git a/OpenImis.RestApi/Controllers/V2/PolicyController.cs b/OpenImis.RestApi/Controllers/V2/PolicyController.cs index d0b0070e..9dfd3114 100644 --- a/OpenImis.RestApi/Controllers/V2/PolicyController.cs +++ b/OpenImis.RestApi/Controllers/V2/PolicyController.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using OpenImis.ModulesV2; @@ -24,7 +22,7 @@ public PolicyController(IImisModules imisModules) _imisModules = imisModules; } - //[HasRights(Rights.PolicySearch)] + [HasRights(Rights.PolicySearch)] [HttpGet] [Route("officer/{officerCode}")] public IActionResult Get(string officerCode) @@ -43,7 +41,7 @@ public IActionResult Get(string officerCode) return Ok(response); } - //[HasRights(Rights.PolicyRenew)] + [HasRights(Rights.PolicyRenew)] [HttpPost] [Route("renew")] public IActionResult Post([FromBody]PolicyRenewalModel model) @@ -62,7 +60,7 @@ public IActionResult Post([FromBody]PolicyRenewalModel model) return Ok(response); } - //[HasRights(Rights.PolicyDelete)] + [HasRights(Rights.PolicyDelete)] [HttpDelete] [Route("renew/{uuid}")] public IActionResult Delete(Guid uuid) From dd42dfcbef12a9c963d721e2f93b05aa21212fde Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 18 Sep 2019 15:14:47 +0200 Subject: [PATCH 54/86] OS-59: Added new version --- .../FeedbackModule/FeedbackModule.cs | 10 +- .../FeedbackModule/Logic/FeedbackLogic.cs | 18 ++- .../FeedbackModule/Logic/IFeedbackLogic.cs | 1 + .../FeedbackModule/Models/Feedback.cs | 15 +++ .../Repositories/FeedbackRepository.cs | 105 +++++++++++++++++- .../Repositories/IFeedbackRepository.cs | 1 + OpenImis.ModulesV2/ImisModules.cs | 2 +- .../Controllers/V2/FeedbackController.cs | 20 +++- 8 files changed, 161 insertions(+), 11 deletions(-) create mode 100644 OpenImis.ModulesV2/FeedbackModule/Models/Feedback.cs diff --git a/OpenImis.ModulesV2/FeedbackModule/FeedbackModule.cs b/OpenImis.ModulesV2/FeedbackModule/FeedbackModule.cs index 3c0a022d..ffefe5da 100644 --- a/OpenImis.ModulesV2/FeedbackModule/FeedbackModule.cs +++ b/OpenImis.ModulesV2/FeedbackModule/FeedbackModule.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using OpenImis.ModulesV2.FeedbackModule.Logic; namespace OpenImis.ModulesV2.FeedbackModule @@ -6,18 +7,21 @@ namespace OpenImis.ModulesV2.FeedbackModule public class FeedbackModule : IFeedbackModule { private IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; + private IFeedbackLogic _feedbackLogic; - public FeedbackModule(IConfiguration configuration) + public FeedbackModule(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { _configuration = configuration; + _hostingEnvironment = hostingEnvironment; } public IFeedbackLogic GetFeedbackLogic() { if (_feedbackLogic == null) { - _feedbackLogic = new FeedbackLogic(_configuration); + _feedbackLogic = new FeedbackLogic(_configuration, _hostingEnvironment); } return _feedbackLogic; } diff --git a/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs b/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs index 4aae1581..f6e2a176 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using OpenImis.ModulesV2.FeedbackModule.Models; using OpenImis.ModulesV2.FeedbackModule.Repositories; using System; @@ -9,14 +10,25 @@ namespace OpenImis.ModulesV2.FeedbackModule.Logic public class FeedbackLogic: IFeedbackLogic { private IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; protected IFeedbackRepository feedbackRepository; - public FeedbackLogic(IConfiguration configuration) + public FeedbackLogic(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { _configuration = configuration; + _hostingEnvironment = hostingEnvironment; - feedbackRepository = new FeedbackRepository(_configuration); + feedbackRepository = new FeedbackRepository(_configuration, _hostingEnvironment); + } + + public int Post(Feedback feedbackClaim) + { + int response; + + response = feedbackRepository.Post(feedbackClaim); + + return response; } public List Get(string officerCode) diff --git a/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs b/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs index 9a722d79..b57c89bb 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs @@ -8,5 +8,6 @@ public interface IFeedbackLogic { List Get(string officerCode); string GetLoginNameByUserUUID(Guid userUUID); + int Post(Feedback feedbackClaim); } } diff --git a/OpenImis.ModulesV2/FeedbackModule/Models/Feedback.cs b/OpenImis.ModulesV2/FeedbackModule/Models/Feedback.cs new file mode 100644 index 00000000..ddf9ec04 --- /dev/null +++ b/OpenImis.ModulesV2/FeedbackModule/Models/Feedback.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.FeedbackModule.Models +{ + public class Feedback + { + public string Officer { get; set; } + public int ClaimID { get; set; } + public string CHFID { get; set; } + public string Answers { get; set; } + public string Date { get; set; } + } +} diff --git a/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs index d29adfe8..80d48274 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs @@ -1,22 +1,121 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Hosting; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using OpenImis.DB.SqlServer; using OpenImis.ModulesV2.FeedbackModule.Models; +using OpenImis.ModulesV2.Helpers; +using OpenImis.ModulesV2.InsureeModule.Helpers; using System; using System.Collections.Generic; +using System.Data; +using System.Data.Common; using System.Data.SqlClient; +using System.Diagnostics; using System.Globalization; +using System.IO; using System.Linq; -using System.Text; +using System.Xml; namespace OpenImis.ModulesV2.FeedbackModule.Repositories { public class FeedbackRepository : IFeedbackRepository { private IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; - public FeedbackRepository(IConfiguration configuration) + public FeedbackRepository(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { _configuration = configuration; + _hostingEnvironment = hostingEnvironment; + } + + public int Post(Feedback feedbackClaim) + { + int RV = -99; + + try + { + string webRootPath = _hostingEnvironment.WebRootPath; + + var XML = feedbackClaim.XMLSerialize(); + + var tempDoc = new XmlDocument(); + tempDoc.LoadXml(XML); + tempDoc.InnerXml = tempDoc.InnerXml.Replace("Feedback>", "feedback>"); + + XML = tempDoc.OuterXml; + + var fromPhoneFeedbackDir = _configuration["AppSettings:FromPhone_Feedback"]; + + var claimCode = ""; + + using (var imisContext = new ImisDB()) + { + claimCode = imisContext.TblClaim + .Where(u => u.ClaimId == feedbackClaim.ClaimID) + .Select(x => x.ClaimCode) + .FirstOrDefault(); + } + + var fileName = "feedback_" + feedbackClaim.Date + "_" + claimCode + ".xml"; + + var xmldoc = new XmlDocument(); + xmldoc.InnerXml = XML; + + try + { + if (!Directory.Exists(webRootPath + fromPhoneFeedbackDir)) Directory.CreateDirectory(webRootPath + fromPhoneFeedbackDir); + + xmldoc.Save(webRootPath + fromPhoneFeedbackDir + fileName); + } + catch (Exception e) + { + throw e; + } + + using (var imisContext = new ImisDB()) + { + var xmlParameter = new SqlParameter("@XML", XML) { DbType = DbType.Xml }; + var returnParameter = OutputParameter.CreateOutputParameter("@RV", SqlDbType.Int); + + var sql = "exec @RV = uspInsertFeedback @XML"; + + DbConnection connection = imisContext.Database.GetDbConnection(); + + using (DbCommand cmd = connection.CreateCommand()) + { + cmd.CommandText = sql; + + cmd.Parameters.AddRange(new[] { xmlParameter, returnParameter }); + + if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); + + using (var reader = cmd.ExecuteReader()) + { + // Displaying errors in the Stored Procedure in Debug mode + //do + //{ + // while (reader.Read()) + // { + // Debug.WriteLine("Error/Warning: " + reader.GetValue(0)); + // } + //} while (reader.NextResult()); + } + } + + RV = (int)returnParameter.Value; + } + + return RV; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } } public List Get(string officerCode) diff --git a/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs b/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs index 16f97777..344e39a9 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs @@ -9,5 +9,6 @@ public interface IFeedbackRepository { List Get(string officerCode); string GetLoginNameByUserUUID(Guid userUUID); + int Post(Feedback feedbackClaim); } } diff --git a/OpenImis.ModulesV2/ImisModules.cs b/OpenImis.ModulesV2/ImisModules.cs index 93e1b8f0..66f8e91d 100644 --- a/OpenImis.ModulesV2/ImisModules.cs +++ b/OpenImis.ModulesV2/ImisModules.cs @@ -151,7 +151,7 @@ public IFeedbackModule GetFeedbackModule() { if (feedbackModule == null) { - feedbackModule = new FeedbackModule.FeedbackModule(_configuration); + feedbackModule = new FeedbackModule.FeedbackModule(_configuration, _hostingEnvironment); Type feedbackLogicType = CreateTypeFromConfiguration("FeedbackModule", "FeedbackLogic", "OpenImis.ModulesV2.FeedbackModule.Logic.FeedbackLogic"); feedbackModule.SetFeedbackLogic((FeedbackModule.Logic.IFeedbackLogic)ActivatorUtilities.CreateInstance(_serviceProvider, feedbackLogicType)); diff --git a/OpenImis.RestApi/Controllers/V2/FeedbackController.cs b/OpenImis.RestApi/Controllers/V2/FeedbackController.cs index af7bca8c..1594db88 100644 --- a/OpenImis.RestApi/Controllers/V2/FeedbackController.cs +++ b/OpenImis.RestApi/Controllers/V2/FeedbackController.cs @@ -25,7 +25,25 @@ public FeedbackController(IImisModules imisModules) _imisModules = imisModules; } - //[HasRights(Rights.ClaimFeedback)] + [HasRights(Rights.ClaimFeedback)] + [HttpPost] + public IActionResult Post([FromBody]Feedback model) + { + int response; + + try + { + response = _imisModules.GetFeedbackModule().GetFeedbackLogic().Post(model); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + return Ok(response); + } + + [HasRights(Rights.ClaimFeedback)] [HttpGet] public IActionResult Get() { From 50f81d27eafa58c37b88e12bbe49156e381b7e84 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 18 Sep 2019 15:30:43 +0200 Subject: [PATCH 55/86] OS-59: Fixed fileName --- .../FeedbackModule/Repositories/FeedbackRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs index 80d48274..712a557d 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs @@ -57,7 +57,7 @@ public int Post(Feedback feedbackClaim) .FirstOrDefault(); } - var fileName = "feedback_" + feedbackClaim.Date + "_" + claimCode + ".xml"; + var fileName = "feedback_" + claimCode + ".xml"; var xmldoc = new XmlDocument(); xmldoc.InnerXml = XML; From 65981e0aea89f3054a997cb6f43a7c0ce1693a25 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 18 Sep 2019 16:59:49 +0200 Subject: [PATCH 56/86] OS-39: Fixed comments from GitHub --- .../ReportModule/Logic/IReportLogic.cs | 8 ++- .../ReportModule/Logic/ReportLogic.cs | 28 ++++++--- ...olmentModel.cs => EnrolmentReportModel.cs} | 2 +- ...eedbackModel.cs => FeedbackReportModel.cs} | 2 +- ...{RenewalModel.cs => RenewalReportModel.cs} | 2 +- .../ReportModule/Models/ReportRequestModel.cs | 6 +- .../Repositories/IReportRepository.cs | 8 ++- .../Repositories/ReportRepository.cs | 58 +++++++++++++------ .../Controllers/V2/ReportController.cs | 37 ++++++++++-- 9 files changed, 106 insertions(+), 45 deletions(-) rename OpenImis.ModulesV2/ReportModule/Models/{EnrolmentModel.cs => EnrolmentReportModel.cs} (85%) rename OpenImis.ModulesV2/ReportModule/Models/{FeedbackModel.cs => FeedbackReportModel.cs} (86%) rename OpenImis.ModulesV2/ReportModule/Models/{RenewalModel.cs => RenewalReportModel.cs} (83%) diff --git a/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs b/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs index f510b27a..5dadecf7 100644 --- a/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs +++ b/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs @@ -1,11 +1,13 @@ using OpenImis.ModulesV2.ReportModule.Models; +using System; namespace OpenImis.ModulesV2.ReportModule.Logic { public interface IReportLogic { - FeedbackModel GetFeedbackStats(ReportRequestModel feedbackRequestModel); - RenewalModel GetRenewalStats(ReportRequestModel renewalRequestModel); - EnrolmentModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel); + FeedbackReportModel GetFeedbackStats(ReportRequestModel feedbackRequestModel, string officerCode); + RenewalReportModel GetRenewalStats(ReportRequestModel renewalRequestModel, string officerCode); + EnrolmentReportModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel, string officerCode); + string GetLoginNameByUserUUID(Guid userUUID); } } diff --git a/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs b/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs index ea94057b..cd209e9b 100644 --- a/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs +++ b/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Configuration; using OpenImis.ModulesV2.ReportModule.Models; using OpenImis.ModulesV2.ReportModule.Repositories; +using System; namespace OpenImis.ModulesV2.ReportModule.Logic { @@ -15,29 +16,38 @@ public ReportLogic(IConfiguration configuration) reportRepository = new ReportRepository(_configuration); } - public FeedbackModel GetFeedbackStats(ReportRequestModel feedbackRequestModel) + public FeedbackReportModel GetFeedbackStats(ReportRequestModel feedbackRequestModel, string officerCode) { - FeedbackModel response; + FeedbackReportModel response; - response = reportRepository.GetFeedbackStats(feedbackRequestModel); + response = reportRepository.GetFeedbackStats(feedbackRequestModel, officerCode); return response; } - public RenewalModel GetRenewalStats(ReportRequestModel renewalRequestModel) + public RenewalReportModel GetRenewalStats(ReportRequestModel renewalRequestModel, string officerCode) { - RenewalModel response; + RenewalReportModel response; - response = reportRepository.GetRenewalStats(renewalRequestModel); + response = reportRepository.GetRenewalStats(renewalRequestModel, officerCode); return response; } - public EnrolmentModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel) + public EnrolmentReportModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel, string officerCode) { - EnrolmentModel response; + EnrolmentReportModel response; - response = reportRepository.GetEnrolmentStats(enrolmentRequestModel); + response = reportRepository.GetEnrolmentStats(enrolmentRequestModel, officerCode); + + return response; + } + + public string GetLoginNameByUserUUID(Guid userUUID) + { + string response; + + response = reportRepository.GetLoginNameByUserUUID(userUUID); return response; } diff --git a/OpenImis.ModulesV2/ReportModule/Models/EnrolmentModel.cs b/OpenImis.ModulesV2/ReportModule/Models/EnrolmentReportModel.cs similarity index 85% rename from OpenImis.ModulesV2/ReportModule/Models/EnrolmentModel.cs rename to OpenImis.ModulesV2/ReportModule/Models/EnrolmentReportModel.cs index cc7519a5..40a4a9ef 100644 --- a/OpenImis.ModulesV2/ReportModule/Models/EnrolmentModel.cs +++ b/OpenImis.ModulesV2/ReportModule/Models/EnrolmentReportModel.cs @@ -4,7 +4,7 @@ namespace OpenImis.ModulesV2.ReportModule.Models { - public class EnrolmentModel + public class EnrolmentReportModel { public int TotalSubmitted { get; set; } public int TotalAssigned { get; set; } diff --git a/OpenImis.ModulesV2/ReportModule/Models/FeedbackModel.cs b/OpenImis.ModulesV2/ReportModule/Models/FeedbackReportModel.cs similarity index 86% rename from OpenImis.ModulesV2/ReportModule/Models/FeedbackModel.cs rename to OpenImis.ModulesV2/ReportModule/Models/FeedbackReportModel.cs index 44f77951..e829daed 100644 --- a/OpenImis.ModulesV2/ReportModule/Models/FeedbackModel.cs +++ b/OpenImis.ModulesV2/ReportModule/Models/FeedbackReportModel.cs @@ -4,7 +4,7 @@ namespace OpenImis.ModulesV2.ReportModule.Models { - public class FeedbackModel + public class FeedbackReportModel { public int FeedbackSent { get; set; } public int FeedbackAccepted { get; set; } diff --git a/OpenImis.ModulesV2/ReportModule/Models/RenewalModel.cs b/OpenImis.ModulesV2/ReportModule/Models/RenewalReportModel.cs similarity index 83% rename from OpenImis.ModulesV2/ReportModule/Models/RenewalModel.cs rename to OpenImis.ModulesV2/ReportModule/Models/RenewalReportModel.cs index e301da86..90e8901f 100644 --- a/OpenImis.ModulesV2/ReportModule/Models/RenewalModel.cs +++ b/OpenImis.ModulesV2/ReportModule/Models/RenewalReportModel.cs @@ -2,7 +2,7 @@ namespace OpenImis.ModulesV2.ReportModule.Models { - public class RenewalModel + public class RenewalReportModel { public int RenewalSent { get; set; } public int RenewalAccepted { get; set; } diff --git a/OpenImis.ModulesV2/ReportModule/Models/ReportRequestModel.cs b/OpenImis.ModulesV2/ReportModule/Models/ReportRequestModel.cs index 85952a2e..7439fa0f 100644 --- a/OpenImis.ModulesV2/ReportModule/Models/ReportRequestModel.cs +++ b/OpenImis.ModulesV2/ReportModule/Models/ReportRequestModel.cs @@ -1,11 +1,11 @@ using System; +using System.ComponentModel.DataAnnotations; namespace OpenImis.ModulesV2.ReportModule.Models { public class ReportRequestModel { - public string OfficerCode { get; set; } - public string FromDate { get; set; } - public string ToDate { get; set; } + public DateTime FromDate { get; set; } + public DateTime ToDate { get; set; } } } diff --git a/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs b/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs index af9fdc7a..31c97063 100644 --- a/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs +++ b/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs @@ -1,11 +1,13 @@ using OpenImis.ModulesV2.ReportModule.Models; +using System; namespace OpenImis.ModulesV2.ReportModule.Repositories { public interface IReportRepository { - FeedbackModel GetFeedbackStats(ReportRequestModel feedbackRequestModel); - RenewalModel GetRenewalStats(ReportRequestModel renewalRequestModel); - EnrolmentModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel); + FeedbackReportModel GetFeedbackStats(ReportRequestModel feedbackRequestModel, string officerCode); + RenewalReportModel GetRenewalStats(ReportRequestModel renewalRequestModel, string officerCode); + EnrolmentReportModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel, string officerCode); + string GetLoginNameByUserUUID(Guid userUUID); } } diff --git a/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs b/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs index cad991b6..2e3fedf4 100644 --- a/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs +++ b/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs @@ -18,9 +18,9 @@ public ReportRepository(IConfiguration configuration) _configuration = configuration; } - public EnrolmentModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel) + public EnrolmentReportModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel, string officerCode) { - EnrolmentModel response = new EnrolmentModel(); + EnrolmentReportModel response = new EnrolmentReportModel(); try { @@ -29,10 +29,10 @@ public EnrolmentModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel var submitted = (from FP in imisContext.TblFromPhone join O in imisContext.TblOfficer on FP.OfficerCode equals O.Code where FP.DocType == "E" - && FP.LandedDate >= DateTime.Parse(enrolmentRequestModel.FromDate) - && FP.LandedDate <= DateTime.Parse(enrolmentRequestModel.ToDate) + && FP.LandedDate >= enrolmentRequestModel.FromDate + && FP.LandedDate <= enrolmentRequestModel.ToDate && O.ValidityTo == null - && FP.OfficerCode == enrolmentRequestModel.OfficerCode + && FP.OfficerCode == officerCode select new { FromPhone = FP, Officer = O }) .ToList(); @@ -44,7 +44,7 @@ from P in imisContext.TblPhotos select S) .ToList(); - response = new EnrolmentModel() + response = new EnrolmentReportModel() { TotalSubmitted = submitted.Select(x => x.FromPhone).Count(), TotalAssigned = assigned.Count(), @@ -63,9 +63,9 @@ from P in imisContext.TblPhotos } } - public FeedbackModel GetFeedbackStats(ReportRequestModel feedbackRequestModel) + public FeedbackReportModel GetFeedbackStats(ReportRequestModel feedbackRequestModel, string officerCode) { - FeedbackModel response = new FeedbackModel(); + FeedbackReportModel response = new FeedbackReportModel(); try { @@ -73,9 +73,9 @@ public FeedbackModel GetFeedbackStats(ReportRequestModel feedbackRequestModel) { var feedbackSent = (from FP in imisContext.TblFromPhone where FP.DocType == "F" - && FP.LandedDate >= DateTime.Parse(feedbackRequestModel.FromDate) - && FP.LandedDate <= DateTime.Parse(feedbackRequestModel.ToDate) - && FP.OfficerCode == feedbackRequestModel.OfficerCode + && FP.LandedDate >= feedbackRequestModel.FromDate + && FP.LandedDate <= feedbackRequestModel.ToDate + && FP.OfficerCode == officerCode select FP) .ToList(); @@ -83,7 +83,7 @@ public FeedbackModel GetFeedbackStats(ReportRequestModel feedbackRequestModel) .Where(f => f.DocStatus == "A") .Count(); - response = new FeedbackModel() + response = new FeedbackReportModel() { FeedbackSent = feedbackSent.Count(), FeedbackAccepted = feedbackAccepted @@ -102,9 +102,9 @@ public FeedbackModel GetFeedbackStats(ReportRequestModel feedbackRequestModel) } } - public RenewalModel GetRenewalStats(ReportRequestModel renewalRequestModel) + public RenewalReportModel GetRenewalStats(ReportRequestModel renewalRequestModel, string officerCode) { - RenewalModel response = new RenewalModel(); + RenewalReportModel response = new RenewalReportModel(); try { @@ -112,9 +112,9 @@ public RenewalModel GetRenewalStats(ReportRequestModel renewalRequestModel) { var renewalSent = (from FP in imisContext.TblFromPhone where FP.DocType == "R" - && FP.LandedDate >= DateTime.Parse(renewalRequestModel.FromDate) - && FP.LandedDate <= DateTime.Parse(renewalRequestModel.ToDate) - && FP.OfficerCode == renewalRequestModel.OfficerCode + && FP.LandedDate >= renewalRequestModel.FromDate + && FP.LandedDate <= renewalRequestModel.ToDate + && FP.OfficerCode == officerCode select FP) .ToList(); @@ -127,7 +127,7 @@ public RenewalModel GetRenewalStats(ReportRequestModel renewalRequestModel) .Where(f => f.DocStatus == "A") .Count(); - response = new RenewalModel() + response = new RenewalReportModel() { RenewalSent = renewalSent.Count(), RenewalAccepted = renewalAccepted @@ -145,5 +145,27 @@ public RenewalModel GetRenewalStats(ReportRequestModel renewalRequestModel) throw e; } } + + public string GetLoginNameByUserUUID(Guid userUUID) + { + string response; + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.TblUsers + .Where(u => u.UserUUID == userUUID) + .Select(x => x.LoginName) + .FirstOrDefault(); + } + + return response; + } + catch (SqlException e) + { + throw e; + } + } } } \ No newline at end of file diff --git a/OpenImis.RestApi/Controllers/V2/ReportController.cs b/OpenImis.RestApi/Controllers/V2/ReportController.cs index 857e16e0..d6814b5c 100644 --- a/OpenImis.RestApi/Controllers/V2/ReportController.cs +++ b/OpenImis.RestApi/Controllers/V2/ReportController.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel.DataAnnotations; +using System.Linq; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using OpenImis.ModulesV2; @@ -26,11 +27,19 @@ public ReportController(IImisModules imisModules) [Route("enrolment")] public IActionResult GetEnrolmentStats([FromBody]ReportRequestModel enrolmentRequestModel) { - EnrolmentModel enrolmentModel; + if (!ModelState.IsValid) + { + return BadRequest(); + } + + EnrolmentReportModel enrolmentModel; try { - enrolmentModel = _imisModules.GetReportModule().GetReportLogic().GetEnrolmentStats(enrolmentRequestModel); + Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); + string officerCode = _imisModules.GetReportModule().GetReportLogic().GetLoginNameByUserUUID(userUUID); + + enrolmentModel = _imisModules.GetReportModule().GetReportLogic().GetEnrolmentStats(enrolmentRequestModel, officerCode); } catch (ValidationException e) { @@ -50,11 +59,19 @@ public IActionResult GetEnrolmentStats([FromBody]ReportRequestModel enrolmentReq [Route("feedback")] public IActionResult GetFeedbackStats([FromBody]ReportRequestModel feedbackRequestModel) { - FeedbackModel feedbackModel; + if (!ModelState.IsValid) + { + return BadRequest(); + } + + FeedbackReportModel feedbackModel; try { - feedbackModel = _imisModules.GetReportModule().GetReportLogic().GetFeedbackStats(feedbackRequestModel); + Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); + string officerCode = _imisModules.GetReportModule().GetReportLogic().GetLoginNameByUserUUID(userUUID); + + feedbackModel = _imisModules.GetReportModule().GetReportLogic().GetFeedbackStats(feedbackRequestModel, officerCode); } catch (ValidationException e) { @@ -74,11 +91,19 @@ public IActionResult GetFeedbackStats([FromBody]ReportRequestModel feedbackReque [Route("renewal")] public IActionResult GetRenewalStats([FromBody]ReportRequestModel renewalRequestModel) { - RenewalModel renewalModel; + if (!ModelState.IsValid) + { + return BadRequest(); + } + + RenewalReportModel renewalModel; try { - renewalModel = _imisModules.GetReportModule().GetReportLogic().GetRenewalStats(renewalRequestModel); + Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); + string officerCode = _imisModules.GetReportModule().GetReportLogic().GetLoginNameByUserUUID(userUUID); + + renewalModel = _imisModules.GetReportModule().GetReportLogic().GetRenewalStats(renewalRequestModel, officerCode); } catch (ValidationException e) { From 283bcbbdf7c3614f0ed383229dc5e52ac618f06c Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 2 Oct 2019 14:57:57 +0200 Subject: [PATCH 57/86] OS-38: Changed in Post Renewal --- .../Repositories/PolicyRepository.cs | 77 +++++++++++++------ .../Controllers/V2/LoginController.cs | 1 + 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs index 0f9c2562..e2379798 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs @@ -91,7 +91,7 @@ public List Get(string officerCode) public int Post(PolicyRenewalModel policy) { - int RV = -99; + int RV = 2; try { @@ -101,56 +101,85 @@ public int Post(PolicyRenewalModel policy) var XML = policyRenew.XMLSerialize(); var fromPhoneRenewalDir = _configuration["AppSettings:FromPhone_Renewal"]; + var fromPhoneRenewalRejectedDir = _configuration["AppSettings:FromPhone_Renewal_Rejected"]; var fileName = "RenPol_" + policy.Date + "_" + policy.CHFID + "_" + policy.ReceiptNo + ".xml"; var xmldoc = new XmlDocument(); xmldoc.InnerXml = XML; + bool ifSaved = false; + try { if (!Directory.Exists(webRootPath + fromPhoneRenewalDir)) Directory.CreateDirectory(webRootPath + fromPhoneRenewalDir); xmldoc.Save(webRootPath + fromPhoneRenewalDir + fileName); + ifSaved = true; } catch (Exception e) { throw e; + return RV; } - using (var imisContext = new ImisDB()) + if (ifSaved) { - var xmlParameter = new SqlParameter("@XML", XML) { DbType = DbType.Xml }; - var returnParameter = OutputParameter.CreateOutputParameter("@RV", SqlDbType.Int); - var fileNameParameter = new SqlParameter("@FileName", SqlDbType.NVarChar, 200); - fileNameParameter.Value = fileName; + using (var imisContext = new ImisDB()) + { + var xmlParameter = new SqlParameter("@XML", XML) { DbType = DbType.Xml }; + var returnParameter = OutputParameter.CreateOutputParameter("@RV", SqlDbType.Int); + var fileNameParameter = new SqlParameter("@FileName", SqlDbType.NVarChar, 200); + fileNameParameter.Value = fileName; - var sql = "exec @RV = uspIsValidRenewal @FileName, @XML"; + var sql = "exec @RV = uspIsValidRenewal @FileName, @XML"; - DbConnection connection = imisContext.Database.GetDbConnection(); + DbConnection connection = imisContext.Database.GetDbConnection(); - using (DbCommand cmd = connection.CreateCommand()) - { - cmd.CommandText = sql; + using (DbCommand cmd = connection.CreateCommand()) + { + cmd.CommandText = sql; - cmd.Parameters.AddRange(new[] { fileNameParameter, xmlParameter, returnParameter }); + cmd.Parameters.AddRange(new[] { fileNameParameter, xmlParameter, returnParameter }); - if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); + if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); - using (var reader = cmd.ExecuteReader()) + using (var reader = cmd.ExecuteReader()) + { + // Displaying errors in the Stored Procedure in Debug mode + //do + //{ + // while (reader.Read()) + // { + // Debug.WriteLine("Error/Warning: " + reader.GetValue(0)); + // } + //} while (reader.NextResult()); + } + } + + int tempRV = (int)returnParameter.Value; + + if (tempRV == 0 || tempRV == -4) + { + RV = 1; + } + else if (tempRV == -1 || tempRV == -2 || tempRV == -3) { - // Displaying errors in the Stored Procedure in Debug mode - //do - //{ - // while (reader.Read()) - // { - // Debug.WriteLine("Error/Warning: " + reader.GetValue(0)); - // } - //} while (reader.NextResult()); + if (File.Exists(webRootPath + fromPhoneRenewalDir + fileName)) + { + File.Move(webRootPath + fromPhoneRenewalDir + fileName, webRootPath + fromPhoneRenewalRejectedDir); + } + RV = 0; + } + else + { + if (File.Exists(webRootPath + fromPhoneRenewalDir + fileName)) + { + File.Move(webRootPath + fromPhoneRenewalDir + fileName, webRootPath + fromPhoneRenewalRejectedDir); + } + RV = 2; } } - - RV = (int)returnParameter.Value; } return RV; diff --git a/OpenImis.RestApi/Controllers/V2/LoginController.cs b/OpenImis.RestApi/Controllers/V2/LoginController.cs index 666de0e1..b0107434 100644 --- a/OpenImis.RestApi/Controllers/V2/LoginController.cs +++ b/OpenImis.RestApi/Controllers/V2/LoginController.cs @@ -17,6 +17,7 @@ namespace OpenImis.RestApi.Controllers.V2 { [ApiVersion("2")] [Authorize] + [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] public class LoginController : Controller From c5ff1d514a994ec2d95c156a065365ea45062cf1 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 2 Oct 2019 15:03:51 +0200 Subject: [PATCH 58/86] OS-38: Changed in Login --- OpenImis.RestApi/Controllers/V2/LoginController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenImis.RestApi/Controllers/V2/LoginController.cs b/OpenImis.RestApi/Controllers/V2/LoginController.cs index b0107434..fb23e214 100644 --- a/OpenImis.RestApi/Controllers/V2/LoginController.cs +++ b/OpenImis.RestApi/Controllers/V2/LoginController.cs @@ -69,7 +69,7 @@ public IActionResult Index([FromBody]LoginModel model) [AllowAnonymous] [HttpPost] - [Route("api/Validate/Credentials")] + [Route("validate/credentials")] public virtual IActionResult Validate_Credentials([FromBody]UserLogin userlogin) { if (!ModelState.IsValid) From c076e1ff98690c92d38ec8769ad32f0789e8f0c0 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 2 Oct 2019 15:10:12 +0200 Subject: [PATCH 59/86] OS-38: Changed in Post Renewal for value 2 --- .../InsureeModule/Repositories/PolicyRepository.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs index e2379798..fd0a4afa 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs @@ -173,10 +173,6 @@ public int Post(PolicyRenewalModel policy) } else { - if (File.Exists(webRootPath + fromPhoneRenewalDir + fileName)) - { - File.Move(webRootPath + fromPhoneRenewalDir + fileName, webRootPath + fromPhoneRenewalRejectedDir); - } RV = 2; } } From b55e69d5216b33f39f1a513574267bfe192fd3a4 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 2 Oct 2019 15:28:51 +0200 Subject: [PATCH 60/86] OS-59: Changed in Feedback and Login --- .../Repositories/FeedbackRepository.cs | 72 ++++++++++++------- .../Controllers/V2/LoginController.cs | 3 +- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs index 712a557d..0a63c680 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs @@ -31,7 +31,7 @@ public FeedbackRepository(IConfiguration configuration, IHostingEnvironment host public int Post(Feedback feedbackClaim) { - int RV = -99; + int RV = 2; try { @@ -46,6 +46,7 @@ public int Post(Feedback feedbackClaim) XML = tempDoc.OuterXml; var fromPhoneFeedbackDir = _configuration["AppSettings:FromPhone_Feedback"]; + var fromPhoneFeedbackRejectedDir = _configuration["AppSettings:FromPhone_Feedback_Rejected"]; var claimCode = ""; @@ -62,48 +63,71 @@ public int Post(Feedback feedbackClaim) var xmldoc = new XmlDocument(); xmldoc.InnerXml = XML; + bool ifSaved = false; + try { if (!Directory.Exists(webRootPath + fromPhoneFeedbackDir)) Directory.CreateDirectory(webRootPath + fromPhoneFeedbackDir); xmldoc.Save(webRootPath + fromPhoneFeedbackDir + fileName); + ifSaved = true; } catch (Exception e) { - throw e; + return RV; } - using (var imisContext = new ImisDB()) + if (ifSaved) { - var xmlParameter = new SqlParameter("@XML", XML) { DbType = DbType.Xml }; - var returnParameter = OutputParameter.CreateOutputParameter("@RV", SqlDbType.Int); - - var sql = "exec @RV = uspInsertFeedback @XML"; + using (var imisContext = new ImisDB()) + { + var xmlParameter = new SqlParameter("@XML", XML) { DbType = DbType.Xml }; + var returnParameter = OutputParameter.CreateOutputParameter("@RV", SqlDbType.Int); - DbConnection connection = imisContext.Database.GetDbConnection(); + var sql = "exec @RV = uspInsertFeedback @XML"; - using (DbCommand cmd = connection.CreateCommand()) - { - cmd.CommandText = sql; + DbConnection connection = imisContext.Database.GetDbConnection(); - cmd.Parameters.AddRange(new[] { xmlParameter, returnParameter }); + using (DbCommand cmd = connection.CreateCommand()) + { + cmd.CommandText = sql; + + cmd.Parameters.AddRange(new[] { xmlParameter, returnParameter }); + + if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); + + using (var reader = cmd.ExecuteReader()) + { + // Displaying errors in the Stored Procedure in Debug mode + //do + //{ + // while (reader.Read()) + // { + // Debug.WriteLine("Error/Warning: " + reader.GetValue(0)); + // } + //} while (reader.NextResult()); + } + } - if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); + int tempRV = (int)returnParameter.Value; - using (var reader = cmd.ExecuteReader()) + if (tempRV == 0 || tempRV == 4) + { + RV = 1; + } + else if (tempRV == 1 || tempRV == 2 || tempRV == 3) { - // Displaying errors in the Stored Procedure in Debug mode - //do - //{ - // while (reader.Read()) - // { - // Debug.WriteLine("Error/Warning: " + reader.GetValue(0)); - // } - //} while (reader.NextResult()); + if (File.Exists(webRootPath + fromPhoneFeedbackDir + fileName)) + { + File.Move(webRootPath + fromPhoneFeedbackDir + fileName, webRootPath + fromPhoneFeedbackRejectedDir); + } + RV = 0; + } + else + { + RV = 2; } } - - RV = (int)returnParameter.Value; } return RV; diff --git a/OpenImis.RestApi/Controllers/V2/LoginController.cs b/OpenImis.RestApi/Controllers/V2/LoginController.cs index 666de0e1..fb23e214 100644 --- a/OpenImis.RestApi/Controllers/V2/LoginController.cs +++ b/OpenImis.RestApi/Controllers/V2/LoginController.cs @@ -17,6 +17,7 @@ namespace OpenImis.RestApi.Controllers.V2 { [ApiVersion("2")] [Authorize] + [Route("api/")] [ApiController] [EnableCors("AllowSpecificOrigin")] public class LoginController : Controller @@ -68,7 +69,7 @@ public IActionResult Index([FromBody]LoginModel model) [AllowAnonymous] [HttpPost] - [Route("api/Validate/Credentials")] + [Route("validate/credentials")] public virtual IActionResult Validate_Credentials([FromBody]UserLogin userlogin) { if (!ModelState.IsValid) From 146cb80c1ddc92d389b40f9e90b0a4b233669a30 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Mon, 7 Oct 2019 13:21:26 +0200 Subject: [PATCH 61/86] OS-38: Updated Get Renewals --- .../InsureeModule/Logic/IPolicyLogic.cs | 1 + .../InsureeModule/Logic/PolicyLogic.cs | 9 ++++ .../InsureeModule/Models/GetPolicyModel.cs | 1 + .../Repositories/IPolicyRepository.cs | 1 + .../Repositories/PolicyRepository.cs | 50 ++++++++++++++++++- .../Controllers/V2/PolicyController.cs | 9 +++- 6 files changed, 67 insertions(+), 4 deletions(-) diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs index cef661fb..af69301e 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs @@ -10,5 +10,6 @@ public interface IPolicyLogic List Get(string officerCode); int Post(PolicyRenewalModel policy); int Delete(Guid uuid); + string GetLoginNameByUserUUID(Guid userUUID); } } diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs index e76ca49f..a1713d7a 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs +++ b/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs @@ -48,5 +48,14 @@ public int Delete(Guid uuid) return response; } + + public string GetLoginNameByUserUUID(Guid userUUID) + { + string response; + + response = policyRepository.GetLoginNameByUserUUID(userUUID); + + return response; + } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/GetPolicyModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/GetPolicyModel.cs index bcf67743..7c3d3fed 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/GetPolicyModel.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/GetPolicyModel.cs @@ -18,5 +18,6 @@ public class GetPolicyModel public string VillageName { get; set; } public string RenewalPromptDate { get; set; } public string Phone { get; set; } + public Guid RenewalUUID { get; set; } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/IPolicyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/IPolicyRepository.cs index 80992875..4c72b92a 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/IPolicyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/IPolicyRepository.cs @@ -9,5 +9,6 @@ public interface IPolicyRepository List Get(string officerCode); int Post(PolicyRenewalModel policy); int Delete(Guid uuid); + string GetLoginNameByUserUUID(Guid userUUID); } } diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs index fd0a4afa..9a555464 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs @@ -27,6 +27,7 @@ public PolicyRepository(IConfiguration configuration, IHostingEnvironment hostin _hostingEnvironment = hostingEnvironment; } + // TODO: Receiving RenewalUUID directly from SP public List Get(string officerCode) { List response = new List(); @@ -69,7 +70,8 @@ public List Get(string officerCode) ProductName = reader["ProductName"].ToString(), VillageName = reader["VillageName"].ToString(), RenewalPromptDate = reader["RenewalPromptDate"].ToString(), - Phone = reader["Phone"].ToString() + Phone = reader["Phone"].ToString(), + RenewalUUID = GetRenewalUUIDById(int.Parse(reader["RenewalId"].ToString())) }); } } while (reader.NextResult()); @@ -119,7 +121,6 @@ public int Post(PolicyRenewalModel policy) } catch (Exception e) { - throw e; return RV; } @@ -205,6 +206,7 @@ public int Delete(Guid uuid) renewal.ResponseStatus = 2; renewal.ResponseDate = DateTime.Now; imisContext.SaveChanges(); + response = 1; } return response; @@ -218,5 +220,49 @@ public int Delete(Guid uuid) throw e; } } + + private Guid GetRenewalUUIDById(int id) + { + Guid response; + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.TblPolicyRenewals + .Where(o => o.RenewalId == id) + .Select(x => x.RenewalUUID) + .FirstOrDefault(); + } + + return response; + } + catch (SqlException e) + { + throw e; + } + } + + public string GetLoginNameByUserUUID(Guid userUUID) + { + string response; + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.TblUsers + .Where(u => u.UserUUID == userUUID) + .Select(x => x.LoginName) + .FirstOrDefault(); + } + + return response; + } + catch (SqlException e) + { + throw e; + } + } } } diff --git a/OpenImis.RestApi/Controllers/V2/PolicyController.cs b/OpenImis.RestApi/Controllers/V2/PolicyController.cs index 9dfd3114..af81a98c 100644 --- a/OpenImis.RestApi/Controllers/V2/PolicyController.cs +++ b/OpenImis.RestApi/Controllers/V2/PolicyController.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Diagnostics; +using System.Linq; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using OpenImis.ModulesV2; @@ -24,13 +26,16 @@ public PolicyController(IImisModules imisModules) [HasRights(Rights.PolicySearch)] [HttpGet] - [Route("officer/{officerCode}")] - public IActionResult Get(string officerCode) + public IActionResult Get() { List response; try { + Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); + + string officerCode = _imisModules.GetInsureeModule().GetPolicyLogic().GetLoginNameByUserUUID(userUUID); + response = _imisModules.GetInsureeModule().GetPolicyLogic().Get(officerCode); } catch (ValidationException e) From 825a2762d15dee9cf889be6f0f38fd54f8df7653 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 9 Oct 2019 11:26:19 +0200 Subject: [PATCH 62/86] OS-40: Changed in Create Claim --- OpenImis.ModulesV2/ClaimModule/ClaimModule.cs | 9 +- .../ClaimModule/Logic/ClaimLogic.cs | 10 +- .../ClaimModule/Models/RegisterClaim/Claim.cs | 12 +-- .../Repositories/ClaimRepository.cs | 101 ++++++++++++++---- OpenImis.ModulesV2/ImisModules.cs | 2 +- 5 files changed, 99 insertions(+), 35 deletions(-) diff --git a/OpenImis.ModulesV2/ClaimModule/ClaimModule.cs b/OpenImis.ModulesV2/ClaimModule/ClaimModule.cs index d16d0388..7b3f56fb 100644 --- a/OpenImis.ModulesV2/ClaimModule/ClaimModule.cs +++ b/OpenImis.ModulesV2/ClaimModule/ClaimModule.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using OpenImis.ModulesV2.ClaimModule.Logic; namespace OpenImis.ModulesV2.ClaimModule @@ -6,19 +7,21 @@ namespace OpenImis.ModulesV2.ClaimModule public class ClaimModule : IClaimModule { private IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; private IClaimLogic _claimLogic; - public ClaimModule(IConfiguration configuration) + public ClaimModule(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { _configuration = configuration; + _hostingEnvironment = hostingEnvironment; } public IClaimLogic GetClaimLogic() { if (_claimLogic == null) { - _claimLogic = new ClaimLogic(_configuration); + _claimLogic = new ClaimLogic(_configuration, _hostingEnvironment); } return _claimLogic; } diff --git a/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs b/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs index 21e05ae1..a1d0d4e3 100644 --- a/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs +++ b/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; using OpenImis.ModulesV2.ClaimModule.Repositories; @@ -7,12 +8,15 @@ namespace OpenImis.ModulesV2.ClaimModule.Logic public class ClaimLogic : IClaimLogic { private IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; protected IClaimRepository claimRepository; - public ClaimLogic(IConfiguration configuration) + public ClaimLogic(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { _configuration = configuration; - claimRepository = new ClaimRepository(_configuration); + _hostingEnvironment = hostingEnvironment; + + claimRepository = new ClaimRepository(_configuration, _hostingEnvironment); } public int Create(Claim claim) diff --git a/OpenImis.ModulesV2/ClaimModule/Models/RegisterClaim/Claim.cs b/OpenImis.ModulesV2/ClaimModule/Models/RegisterClaim/Claim.cs index 17645adc..0921a556 100644 --- a/OpenImis.ModulesV2/ClaimModule/Models/RegisterClaim/Claim.cs +++ b/OpenImis.ModulesV2/ClaimModule/Models/RegisterClaim/Claim.cs @@ -20,25 +20,25 @@ public class Details public string EndDate { get; set; } public string ICDCode { get; set; } public string Comment { get; set; } - public float Total { get; set; } + public string Total { get; set; } public string ICDCode1 { get; set; } public string ICDCode2 { get; set; } public string ICDCode3 { get; set; } public string ICDCode4 { get; set; } - public int VisitType { get; set; } + public string VisitType { get; set; } } public class Item { public string ItemCode { get; set; } - public float ItemPrice { get; set; } - public int ItemQuantity { get; set; } + public string ItemPrice { get; set; } + public string ItemQuantity { get; set; } } public class Service { public string ServiceCode { get; set; } - public float ServicePrice { get; set; } - public int ServiceQuantity { get; set; } + public string ServicePrice { get; set; } + public string ServiceQuantity { get; set; } } } diff --git a/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs b/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs index ac101e32..9faaa2c5 100644 --- a/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs +++ b/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs @@ -2,6 +2,10 @@ using System.Data; using System.Data.Common; using System.Data.SqlClient; +using System.Diagnostics; +using System.IO; +using System.Xml; +using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using OpenImis.DB.SqlServer; @@ -13,10 +17,12 @@ namespace OpenImis.ModulesV2.ClaimModule.Repositories public class ClaimRepository : IClaimRepository { private IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; - public ClaimRepository(IConfiguration configuration) + public ClaimRepository(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { _configuration = configuration; + _hostingEnvironment = hostingEnvironment; } public int Create(Claim claim) @@ -24,39 +30,90 @@ public int Create(Claim claim) try { var XML = claim.XMLSerialize(); - var RV = -99; + var RV = 2; - using (var imisContext = new ImisDB()) + bool ifSaved = false; + + string webRootPath = _hostingEnvironment.WebRootPath; + + var fromPhoneClaimDir = _configuration["AppSettings:FromPhone_Claim"]; + var fromPhoneClaimRejectedDir = _configuration["AppSettings:FromPhone_Claim_Rejected"]; + + var fileName = "Claim_" + claim.Details.HFCode + "_" + claim.Details.CHFID + "_" + claim.Details.ClaimCode + ".xml"; + + var xmldoc = new XmlDocument(); + xmldoc.InnerXml = XML; + + try { - var xmlParameter = new SqlParameter("@XML", XML) { DbType = DbType.Xml }; - var returnParameter = new SqlParameter("@RV", SqlDbType.Int) { Direction = ParameterDirection.Output }; - var sql = "exec @RV = uspUpdateClaimFromPhone @XML"; + if (!Directory.Exists(webRootPath + fromPhoneClaimDir)) Directory.CreateDirectory(webRootPath + fromPhoneClaimDir); + if (!Directory.Exists(webRootPath + fromPhoneClaimRejectedDir)) Directory.CreateDirectory(webRootPath + fromPhoneClaimRejectedDir); - DbConnection connection = imisContext.Database.GetDbConnection(); + if (!File.Exists(webRootPath + fromPhoneClaimDir + fileName)) + { + xmldoc.Save(webRootPath + fromPhoneClaimDir + fileName); + } - using (DbCommand cmd = connection.CreateCommand()) + ifSaved = true; + } + catch (Exception e) + { + return 2; + } + + if (ifSaved) + { + using (var imisContext = new ImisDB()) { - cmd.CommandText = sql; + var xmlParameter = new SqlParameter("@XML", XML) { DbType = DbType.Xml }; + var returnParameter = new SqlParameter("@RV", SqlDbType.Int) { Direction = ParameterDirection.Output }; - cmd.Parameters.AddRange(new[] { xmlParameter, returnParameter }); + var sql = "exec @RV = uspUpdateClaimFromPhone @XML"; - if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); + DbConnection connection = imisContext.Database.GetDbConnection(); - using (var reader = cmd.ExecuteReader()) + using (DbCommand cmd = connection.CreateCommand()) { - // Displaying errors in the Stored Procedure in Debug mode - //do - //{ - // while (reader.Read()) - // { - // Debug.WriteLine("Error/Warning: " + reader.GetValue(0)); - // } - //} while (reader.NextResult()); + cmd.CommandText = sql; + + cmd.Parameters.AddRange(new[] { xmlParameter, returnParameter }); + + if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); + + using (var reader = cmd.ExecuteReader()) + { + // Displaying errors in the Stored Procedure in Debug mode + //do + //{ + // while (reader.Read()) + // { + // Debug.WriteLine("Error/Warning: " + reader.GetValue(0)); + // } + //} while (reader.NextResult()); + } } - } - RV = (int)returnParameter.Value; + int tempRV = (int)returnParameter.Value; + + if (tempRV == 0) + { + RV = 1; + } + else if (tempRV == -1) + { + RV = 2; + } + else + { + if (File.Exists(webRootPath + fromPhoneClaimDir + fileName) && !File.Exists(webRootPath + fromPhoneClaimRejectedDir + fileName)) + { + File.Move(webRootPath + fromPhoneClaimDir + fileName, webRootPath + fromPhoneClaimRejectedDir + fileName); + } + + RV = 0; + } + } } return RV; diff --git a/OpenImis.ModulesV2/ImisModules.cs b/OpenImis.ModulesV2/ImisModules.cs index 11eb958f..ebdff9e1 100644 --- a/OpenImis.ModulesV2/ImisModules.cs +++ b/OpenImis.ModulesV2/ImisModules.cs @@ -73,7 +73,7 @@ public IClaimModule GetClaimModule() { if (claimModule == null) { - claimModule = new ClaimModule.ClaimModule(_configuration); + claimModule = new ClaimModule.ClaimModule(_configuration, _hostingEnvironment); Type claimLogicType = CreateTypeFromConfiguration("ClaimModule", "ClaimLogic", "OpenImis.ModulesV2.ClaimModule.Logic.ClaimLogic"); claimModule.SetClaimLogic((ClaimModule.Logic.IClaimLogic)ActivatorUtilities.CreateInstance(_serviceProvider, claimLogicType)); From 972ee21f20ae88fc090d8f2c3fd32b3722f46fb9 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 9 Oct 2019 11:34:16 +0200 Subject: [PATCH 63/86] OS-38: Changed in Post Policy - moving files --- .../InsureeModule/Repositories/PolicyRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs index 9a555464..195b7797 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs @@ -168,7 +168,7 @@ public int Post(PolicyRenewalModel policy) { if (File.Exists(webRootPath + fromPhoneRenewalDir + fileName)) { - File.Move(webRootPath + fromPhoneRenewalDir + fileName, webRootPath + fromPhoneRenewalRejectedDir); + File.Move(webRootPath + fromPhoneRenewalDir + fileName, webRootPath + fromPhoneRenewalRejectedDir + fileName); } RV = 0; } From 31a15890c50c1f04ec4119b670ff8c24e9df4e02 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 9 Oct 2019 11:42:06 +0200 Subject: [PATCH 64/86] OS-59: Changed in Post Feedback - moving files --- .../FeedbackModule/Repositories/FeedbackRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs index 0a63c680..7f85be88 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs @@ -119,7 +119,7 @@ public int Post(Feedback feedbackClaim) { if (File.Exists(webRootPath + fromPhoneFeedbackDir + fileName)) { - File.Move(webRootPath + fromPhoneFeedbackDir + fileName, webRootPath + fromPhoneFeedbackRejectedDir); + File.Move(webRootPath + fromPhoneFeedbackDir + fileName, webRootPath + fromPhoneFeedbackRejectedDir + fileName); } RV = 0; } From a1749d4be4121400e1795de244a12d783fa2c761 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 9 Oct 2019 14:15:28 +0200 Subject: [PATCH 65/86] OS-38: Moved policy to new Policy Module --- .../Helpers/ConfigImisModules.cs | 7 ++- OpenImis.ModulesV2/IImisModules.cs | 3 + OpenImis.ModulesV2/ImisModules.cs | 25 +++++++- .../InsureeModule/IInsureeModule.cs | 3 - .../InsureeModule/InsureeModule.cs | 16 ----- .../InsureeModule/Logic/PolicyLogic.cs | 61 ------------------- .../Repositories/IPolicyRepository.cs | 14 ----- .../PolicyModule/Helpers/OutputParameter.cs | 16 +++++ .../PolicyModule/IPolicyModule.cs | 13 ++++ .../Logic/IPolicyRenewalLogic.cs} | 8 +-- .../PolicyModule/Logic/PolicyRenewalLogic.cs | 61 +++++++++++++++++++ .../Models/GetPolicyRenewalModel.cs} | 4 +- .../Models/Policy.cs | 2 +- .../Models/PolicyRenewalModel.cs | 6 +- .../PolicyModule/PolicyModule.cs | 38 ++++++++++++ .../Repositories/IPolicyRenewalRepository.cs | 14 +++++ .../Repositories/PolicyRenewalRepository.cs} | 18 +++--- ...ntroller.cs => PolicyRenewalController.cs} | 17 +++--- OpenImis.RestApi/openImisModules.json | 4 +- 19 files changed, 204 insertions(+), 126 deletions(-) delete mode 100644 OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs delete mode 100644 OpenImis.ModulesV2/InsureeModule/Repositories/IPolicyRepository.cs create mode 100644 OpenImis.ModulesV2/PolicyModule/Helpers/OutputParameter.cs create mode 100644 OpenImis.ModulesV2/PolicyModule/IPolicyModule.cs rename OpenImis.ModulesV2/{InsureeModule/Logic/IPolicyLogic.cs => PolicyModule/Logic/IPolicyRenewalLogic.cs} (51%) create mode 100644 OpenImis.ModulesV2/PolicyModule/Logic/PolicyRenewalLogic.cs rename OpenImis.ModulesV2/{InsureeModule/Models/GetPolicyModel.cs => PolicyModule/Models/GetPolicyRenewalModel.cs} (88%) rename OpenImis.ModulesV2/{InsureeModule => PolicyModule}/Models/Policy.cs (72%) rename OpenImis.ModulesV2/{InsureeModule => PolicyModule}/Models/PolicyRenewalModel.cs (89%) create mode 100644 OpenImis.ModulesV2/PolicyModule/PolicyModule.cs create mode 100644 OpenImis.ModulesV2/PolicyModule/Repositories/IPolicyRenewalRepository.cs rename OpenImis.ModulesV2/{InsureeModule/Repositories/PolicyRepository.cs => PolicyModule/Repositories/PolicyRenewalRepository.cs} (94%) rename OpenImis.RestApi/Controllers/V2/{PolicyController.cs => PolicyRenewalController.cs} (74%) diff --git a/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs b/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs index bf80f1d7..5e134e8c 100644 --- a/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs +++ b/OpenImis.ModulesV2/Helpers/ConfigImisModules.cs @@ -17,6 +17,7 @@ public class ConfigImisModules public PremiumModule PremiumModule { get; set; } public SystemModule SystemModule { get; set; } public MasterDataModule MasterDataModule { get; set; } + public PolicyModule PolicyModule { get; set; } } public class LoginModule @@ -37,7 +38,6 @@ public class CoverageModule public class InsureeModule { public string FamilyLogic { get; set; } - public string PolicyLogic { get; set; } public string ContributionLogic { get; set; } } @@ -65,4 +65,9 @@ public class MasterDataModule { public string MasterDataLogic { get; set; } } + + public class PolicyModule + { + public string PolicyRenewalLogic { get; set; } + } } diff --git a/OpenImis.ModulesV2/IImisModules.cs b/OpenImis.ModulesV2/IImisModules.cs index 677b06ce..80bccfc2 100644 --- a/OpenImis.ModulesV2/IImisModules.cs +++ b/OpenImis.ModulesV2/IImisModules.cs @@ -4,6 +4,7 @@ using OpenImis.ModulesV2.CoverageModule; using OpenImis.ModulesV2.PaymentModule; using OpenImis.ModulesV2.MasterDataModule; +using OpenImis.ModulesV2.PolicyModule; namespace OpenImis.ModulesV2 { @@ -23,5 +24,7 @@ public interface IImisModules IPaymentModule GetPaymentModule(); IMasterDataModule GetMasterDataModule(); + + IPolicyModule GetPolicyModule(); } } diff --git a/OpenImis.ModulesV2/ImisModules.cs b/OpenImis.ModulesV2/ImisModules.cs index 93e1b8f0..50e707ea 100644 --- a/OpenImis.ModulesV2/ImisModules.cs +++ b/OpenImis.ModulesV2/ImisModules.cs @@ -17,6 +17,9 @@ using Microsoft.AspNetCore.Hosting; using OpenImis.ModulesV2.PremiumModule; using OpenImis.ModulesV2.SystemModule; +using OpenImis.ModulesV2.PolicyModule; +using OpenImis.ModulesV2.PolicyModule.Logic; + namespace OpenImis.ModulesV2 { public class ImisModules : IImisModules @@ -31,6 +34,7 @@ public class ImisModules : IImisModules private IFeedbackModule feedbackModule; private IPremiumModule premiumModule; private ISystemModule systemModule; + private IPolicyModule policyModule; private readonly IConfiguration _configuration; private readonly IHostingEnvironment _hostingEnvironment; @@ -96,9 +100,6 @@ public IInsureeModule GetInsureeModule() Type familyLogicType = CreateTypeFromConfiguration("InsureeModule", "FamilyLogic", "OpenImis.ModulesV2.InsureeModule.Logic.FamilyLogic"); insureeModule.SetFamilyLogic((InsureeModule.Logic.IFamilyLogic)ActivatorUtilities.CreateInstance(_serviceProvider, familyLogicType)); - Type policyLogicType = CreateTypeFromConfiguration("InsureeModule", "PolicyLogic", "OpenImis.ModulesV2.InsureeModule.Logic.PolicyLogic"); - insureeModule.SetPolicyLogic((InsureeModule.Logic.IPolicyLogic)ActivatorUtilities.CreateInstance(_serviceProvider, policyLogicType)); - Type contributionLogicType = CreateTypeFromConfiguration("InsureeModule", "ContributionLogic", "OpenImis.ModulesV2.InsureeModule.Logic.ContributionLogic"); insureeModule.SetContributionLogic((InsureeModule.Logic.IContributionLogic)ActivatorUtilities.CreateInstance(_serviceProvider, contributionLogicType)); } @@ -213,6 +214,24 @@ public IMasterDataModule GetMasterDataModule() return masterDataModule; } + /// + /// Creates and returns the policy module version 2. + /// + /// + /// The Policy module V2. + /// + public IPolicyModule GetPolicyModule() + { + if (policyModule == null) + { + policyModule = new PolicyModule.PolicyModule(_configuration, _hostingEnvironment); + + Type policyLogicType = CreateTypeFromConfiguration("PolicyModule", "PolicyRenewalLogic", "OpenImis.ModulesV2.PolicyModule.Logic.PolicyRenewalLogic"); + policyModule.SetPolicyLogic((IPolicyRenewalLogic)ActivatorUtilities.CreateInstance(_serviceProvider, policyLogicType)); + } + return policyModule; + } + /// /// Creates and returns the type based on the string from the configuration /// diff --git a/OpenImis.ModulesV2/InsureeModule/IInsureeModule.cs b/OpenImis.ModulesV2/InsureeModule/IInsureeModule.cs index e946029e..0059404c 100644 --- a/OpenImis.ModulesV2/InsureeModule/IInsureeModule.cs +++ b/OpenImis.ModulesV2/InsureeModule/IInsureeModule.cs @@ -1,5 +1,4 @@ using OpenImis.ModulesV2.InsureeModule.Logic; -using System; namespace OpenImis.ModulesV2.InsureeModule { @@ -7,9 +6,7 @@ public interface IInsureeModule { IFamilyLogic GetFamilyLogic(); IContributionLogic GetContributionLogic(); - IPolicyLogic GetPolicyLogic(); IInsureeModule SetFamilyLogic(IFamilyLogic familyLogic); - IInsureeModule SetPolicyLogic(IPolicyLogic policyLogic); IInsureeModule SetContributionLogic(IContributionLogic contributionLogic); } } diff --git a/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs b/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs index b8728af7..6cf026c7 100644 --- a/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs +++ b/OpenImis.ModulesV2/InsureeModule/InsureeModule.cs @@ -11,7 +11,6 @@ public class InsureeModule : IInsureeModule private IFamilyLogic _familyLogic; private IContributionLogic _contributionLogic; - private IPolicyLogic _policyLogic; public InsureeModule(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { @@ -37,27 +36,12 @@ public IContributionLogic GetContributionLogic() return _contributionLogic; } - public IPolicyLogic GetPolicyLogic() - { - if (_policyLogic == null) - { - _policyLogic = new PolicyLogic(_configuration, _hostingEnvironment); - } - return _policyLogic; - } - public IInsureeModule SetFamilyLogic(IFamilyLogic familyLogic) { _familyLogic = familyLogic; return this; } - public IInsureeModule SetPolicyLogic(IPolicyLogic policyLogic) - { - _policyLogic = policyLogic; - return this; - } - public IInsureeModule SetContributionLogic(IContributionLogic contributionLogic) { _contributionLogic = contributionLogic; diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs b/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs deleted file mode 100644 index a1713d7a..00000000 --- a/OpenImis.ModulesV2/InsureeModule/Logic/PolicyLogic.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using OpenImis.ModulesV2.InsureeModule.Models; -using OpenImis.ModulesV2.InsureeModule.Repositories; -using System; -using System.Collections.Generic; - -namespace OpenImis.ModulesV2.InsureeModule.Logic -{ - public class PolicyLogic : IPolicyLogic - { - private IConfiguration _configuration; - private readonly IHostingEnvironment _hostingEnvironment; - - protected IPolicyRepository policyRepository; - - public PolicyLogic(IConfiguration configuration, IHostingEnvironment hostingEnvironment) - { - _configuration = configuration; - _hostingEnvironment = hostingEnvironment; - - policyRepository = new PolicyRepository(_configuration, _hostingEnvironment); - } - - public List Get(string officerCode) - { - List response; - - response = policyRepository.Get(officerCode); - - return response; - } - - public int Post(PolicyRenewalModel policy) - { - int response; - - response = policyRepository.Post(policy); - - return response; - } - - public int Delete(Guid uuid) - { - int response; - - response = policyRepository.Delete(uuid); - - return response; - } - - public string GetLoginNameByUserUUID(Guid userUUID) - { - string response; - - response = policyRepository.GetLoginNameByUserUUID(userUUID); - - return response; - } - } -} diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/IPolicyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/IPolicyRepository.cs deleted file mode 100644 index 4c72b92a..00000000 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/IPolicyRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -using OpenImis.ModulesV2.InsureeModule.Models; -using System; -using System.Collections.Generic; - -namespace OpenImis.ModulesV2.InsureeModule.Repositories -{ - public interface IPolicyRepository - { - List Get(string officerCode); - int Post(PolicyRenewalModel policy); - int Delete(Guid uuid); - string GetLoginNameByUserUUID(Guid userUUID); - } -} diff --git a/OpenImis.ModulesV2/PolicyModule/Helpers/OutputParameter.cs b/OpenImis.ModulesV2/PolicyModule/Helpers/OutputParameter.cs new file mode 100644 index 00000000..72c40edd --- /dev/null +++ b/OpenImis.ModulesV2/PolicyModule/Helpers/OutputParameter.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Text; + +namespace OpenImis.ModulesV2.PolicyModule.Helpers +{ + public static class OutputParameter + { + public static SqlParameter CreateOutputParameter(string parameterName, SqlDbType sqlDbType) + { + return new SqlParameter(parameterName, sqlDbType) { Direction = ParameterDirection.Output }; + } + } +} diff --git a/OpenImis.ModulesV2/PolicyModule/IPolicyModule.cs b/OpenImis.ModulesV2/PolicyModule/IPolicyModule.cs new file mode 100644 index 00000000..92980f0a --- /dev/null +++ b/OpenImis.ModulesV2/PolicyModule/IPolicyModule.cs @@ -0,0 +1,13 @@ +using OpenImis.ModulesV2.PolicyModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.PolicyModule +{ + public interface IPolicyModule + { + IPolicyRenewalLogic GetPolicyRenewalLogic(); + IPolicyModule SetPolicyLogic(IPolicyRenewalLogic policyRenewalLogic); + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs b/OpenImis.ModulesV2/PolicyModule/Logic/IPolicyRenewalLogic.cs similarity index 51% rename from OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs rename to OpenImis.ModulesV2/PolicyModule/Logic/IPolicyRenewalLogic.cs index af69301e..45263624 100644 --- a/OpenImis.ModulesV2/InsureeModule/Logic/IPolicyLogic.cs +++ b/OpenImis.ModulesV2/PolicyModule/Logic/IPolicyRenewalLogic.cs @@ -1,13 +1,13 @@ -using OpenImis.ModulesV2.InsureeModule.Models; +using OpenImis.ModulesV2.PolicyModule.Models; using System; using System.Collections.Generic; using System.Text; -namespace OpenImis.ModulesV2.InsureeModule.Logic +namespace OpenImis.ModulesV2.PolicyModule.Logic { - public interface IPolicyLogic + public interface IPolicyRenewalLogic { - List Get(string officerCode); + List Get(string officerCode); int Post(PolicyRenewalModel policy); int Delete(Guid uuid); string GetLoginNameByUserUUID(Guid userUUID); diff --git a/OpenImis.ModulesV2/PolicyModule/Logic/PolicyRenewalLogic.cs b/OpenImis.ModulesV2/PolicyModule/Logic/PolicyRenewalLogic.cs new file mode 100644 index 00000000..e2248b5f --- /dev/null +++ b/OpenImis.ModulesV2/PolicyModule/Logic/PolicyRenewalLogic.cs @@ -0,0 +1,61 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.PolicyModule.Models; +using OpenImis.ModulesV2.PolicyModule.Repositories; +using System; +using System.Collections.Generic; + +namespace OpenImis.ModulesV2.PolicyModule.Logic +{ + public class PolicyRenewalLogic : IPolicyRenewalLogic + { + private IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; + + protected IPolicyRenewalRepository policyRenewalRepository; + + public PolicyRenewalLogic(IConfiguration configuration, IHostingEnvironment hostingEnvironment) + { + _configuration = configuration; + _hostingEnvironment = hostingEnvironment; + + policyRenewalRepository = new PolicyRenewalRepository(_configuration, _hostingEnvironment); + } + + public List Get(string officerCode) + { + List response; + + response = policyRenewalRepository.Get(officerCode); + + return response; + } + + public int Post(PolicyRenewalModel policy) + { + int response; + + response = policyRenewalRepository.Post(policy); + + return response; + } + + public int Delete(Guid uuid) + { + int response; + + response = policyRenewalRepository.Delete(uuid); + + return response; + } + + public string GetLoginNameByUserUUID(Guid userUUID) + { + string response; + + response = policyRenewalRepository.GetLoginNameByUserUUID(userUUID); + + return response; + } + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/GetPolicyModel.cs b/OpenImis.ModulesV2/PolicyModule/Models/GetPolicyRenewalModel.cs similarity index 88% rename from OpenImis.ModulesV2/InsureeModule/Models/GetPolicyModel.cs rename to OpenImis.ModulesV2/PolicyModule/Models/GetPolicyRenewalModel.cs index 7c3d3fed..fedb9330 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/GetPolicyModel.cs +++ b/OpenImis.ModulesV2/PolicyModule/Models/GetPolicyRenewalModel.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.ModulesV2.InsureeModule.Models +namespace OpenImis.ModulesV2.PolicyModule.Models { - public class GetPolicyModel + public class GetPolicyRenewalModel { public int RenewalId { get; set; } public int PolicyId { get; set; } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/Policy.cs b/OpenImis.ModulesV2/PolicyModule/Models/Policy.cs similarity index 72% rename from OpenImis.ModulesV2/InsureeModule/Models/Policy.cs rename to OpenImis.ModulesV2/PolicyModule/Models/Policy.cs index b9e85242..b6f7bb94 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/Policy.cs +++ b/OpenImis.ModulesV2/PolicyModule/Models/Policy.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace OpenImis.ModulesV2.InsureeModule.Models +namespace OpenImis.ModulesV2.PolicyModule.Models { public class Policy : PolicyRenewalModel { diff --git a/OpenImis.ModulesV2/InsureeModule/Models/PolicyRenewalModel.cs b/OpenImis.ModulesV2/PolicyModule/Models/PolicyRenewalModel.cs similarity index 89% rename from OpenImis.ModulesV2/InsureeModule/Models/PolicyRenewalModel.cs rename to OpenImis.ModulesV2/PolicyModule/Models/PolicyRenewalModel.cs index 0eac3f91..c8b051a8 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/PolicyRenewalModel.cs +++ b/OpenImis.ModulesV2/PolicyModule/Models/PolicyRenewalModel.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; +using System.Text; -namespace OpenImis.ModulesV2.InsureeModule.Models +namespace OpenImis.ModulesV2.PolicyModule.Models { public class PolicyRenewalModel { @@ -31,4 +33,4 @@ public Policy GetPolicy() }; } } -} \ No newline at end of file +} diff --git a/OpenImis.ModulesV2/PolicyModule/PolicyModule.cs b/OpenImis.ModulesV2/PolicyModule/PolicyModule.cs new file mode 100644 index 00000000..6b6b3278 --- /dev/null +++ b/OpenImis.ModulesV2/PolicyModule/PolicyModule.cs @@ -0,0 +1,38 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.PolicyModule.Logic; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.PolicyModule +{ + public class PolicyModule : IPolicyModule + { + private IConfiguration _configuration; + private readonly IHostingEnvironment _hostingEnvironment; + + private IPolicyRenewalLogic _policyRenewalLogic; + + public PolicyModule(IConfiguration configuration, IHostingEnvironment hostingEnvironment) + { + _configuration = configuration; + _hostingEnvironment = hostingEnvironment; + } + + public IPolicyRenewalLogic GetPolicyRenewalLogic() + { + if (_policyRenewalLogic == null) + { + _policyRenewalLogic = new PolicyRenewalLogic(_configuration, _hostingEnvironment); + } + return _policyRenewalLogic; + } + + public IPolicyModule SetPolicyLogic(IPolicyRenewalLogic policyRenewalLogic) + { + _policyRenewalLogic = policyRenewalLogic; + return this; + } + } +} diff --git a/OpenImis.ModulesV2/PolicyModule/Repositories/IPolicyRenewalRepository.cs b/OpenImis.ModulesV2/PolicyModule/Repositories/IPolicyRenewalRepository.cs new file mode 100644 index 00000000..ac78f8e6 --- /dev/null +++ b/OpenImis.ModulesV2/PolicyModule/Repositories/IPolicyRenewalRepository.cs @@ -0,0 +1,14 @@ +using OpenImis.ModulesV2.PolicyModule.Models; +using System; +using System.Collections.Generic; + +namespace OpenImis.ModulesV2.PolicyModule.Repositories +{ + public interface IPolicyRenewalRepository + { + List Get(string officerCode); + int Post(PolicyRenewalModel policy); + int Delete(Guid uuid); + string GetLoginNameByUserUUID(Guid userUUID); + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs b/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs similarity index 94% rename from OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs rename to OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs index 195b7797..a25aeea6 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/PolicyRepository.cs +++ b/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs @@ -3,9 +3,8 @@ using Microsoft.Extensions.Configuration; using OpenImis.DB.SqlServer; using OpenImis.ModulesV2.Helpers; -using OpenImis.ModulesV2.InsureeModule.Helpers; -using OpenImis.ModulesV2.InsureeModule.Models; -using System; +using OpenImis.ModulesV2.PolicyModule.Helpers; +using OpenImis.ModulesV2.PolicyModule.Models; using System.Collections.Generic; using System.Data; using System.Data.Common; @@ -13,24 +12,25 @@ using System.IO; using System.Linq; using System.Xml; +using System; -namespace OpenImis.ModulesV2.InsureeModule.Repositories +namespace OpenImis.ModulesV2.PolicyModule.Repositories { - public class PolicyRepository : IPolicyRepository + public class PolicyRenewalRepository : IPolicyRenewalRepository { private IConfiguration _configuration; private readonly IHostingEnvironment _hostingEnvironment; - public PolicyRepository(IConfiguration configuration, IHostingEnvironment hostingEnvironment) + public PolicyRenewalRepository(IConfiguration configuration, IHostingEnvironment hostingEnvironment) { _configuration = configuration; _hostingEnvironment = hostingEnvironment; } // TODO: Receiving RenewalUUID directly from SP - public List Get(string officerCode) + public List Get(string officerCode) { - List response = new List(); + List response = new List(); try { @@ -57,7 +57,7 @@ public List Get(string officerCode) { while (reader.Read()) { - response.Add(new GetPolicyModel() + response.Add(new GetPolicyRenewalModel() { RenewalId = int.Parse(reader["RenewalId"].ToString()), PolicyId = int.Parse(reader["PolicyId"].ToString()), diff --git a/OpenImis.RestApi/Controllers/V2/PolicyController.cs b/OpenImis.RestApi/Controllers/V2/PolicyRenewalController.cs similarity index 74% rename from OpenImis.RestApi/Controllers/V2/PolicyController.cs rename to OpenImis.RestApi/Controllers/V2/PolicyRenewalController.cs index af81a98c..214c6970 100644 --- a/OpenImis.RestApi/Controllers/V2/PolicyController.cs +++ b/OpenImis.RestApi/Controllers/V2/PolicyRenewalController.cs @@ -1,12 +1,11 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Diagnostics; using System.Linq; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using OpenImis.ModulesV2; -using OpenImis.ModulesV2.InsureeModule.Models; +using OpenImis.ModulesV2.PolicyModule.Models; using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers.V2 @@ -15,11 +14,11 @@ namespace OpenImis.RestApi.Controllers.V2 [Authorize] [Route("api/policy/")] [ApiController] - public class PolicyController : Controller + public class PolicyRenewalController : Controller { private readonly IImisModules _imisModules; - public PolicyController(IImisModules imisModules) + public PolicyRenewalController(IImisModules imisModules) { _imisModules = imisModules; } @@ -28,15 +27,15 @@ public PolicyController(IImisModules imisModules) [HttpGet] public IActionResult Get() { - List response; + List response; try { Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); - string officerCode = _imisModules.GetInsureeModule().GetPolicyLogic().GetLoginNameByUserUUID(userUUID); + string officerCode = _imisModules.GetPolicyModule().GetPolicyRenewalLogic().GetLoginNameByUserUUID(userUUID); - response = _imisModules.GetInsureeModule().GetPolicyLogic().Get(officerCode); + response = _imisModules.GetPolicyModule().GetPolicyRenewalLogic().Get(officerCode); } catch (ValidationException e) { @@ -55,7 +54,7 @@ public IActionResult Post([FromBody]PolicyRenewalModel model) try { - response = _imisModules.GetInsureeModule().GetPolicyLogic().Post(model); + response = _imisModules.GetPolicyModule().GetPolicyRenewalLogic().Post(model); } catch (ValidationException e) { @@ -74,7 +73,7 @@ public IActionResult Delete(Guid uuid) try { - response = _imisModules.GetInsureeModule().GetPolicyLogic().Delete(uuid); + response = _imisModules.GetPolicyModule().GetPolicyRenewalLogic().Delete(uuid); } catch (ValidationException e) { diff --git a/OpenImis.RestApi/openImisModules.json b/OpenImis.RestApi/openImisModules.json index 17444b67..b7f6ec9e 100644 --- a/OpenImis.RestApi/openImisModules.json +++ b/OpenImis.RestApi/openImisModules.json @@ -33,7 +33,6 @@ }, "InsureeModule": { "FamilyLogic": "OpenImis.ModulesV2.InsureeModule.Logic.FamilyLogic", - "PolicyLogic": "OpenImis.ModulesV2.InsureeModule.Logic.PolicyLogic", "ContributionLogic": "OpenImis.ModulesV2.InsureeModule.Logic.ContributionLogic" }, "PaymentModule": { @@ -50,6 +49,9 @@ }, "MasterDataModule": { "MasterDataLogic": "OpenImis.ModulesV2.MasterDataModule.Logic.MasterDataLogic" + }, + "PolicyModule": { + "PolicyRenewalLogic": "OpenImis.ModulesV2.PolicyModule.Logic.PolicyRenewalLogic" } } ] From 4802ef7c918a15dea1bf374a8c6da4f3bf11214e Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 9 Oct 2019 18:01:55 +0200 Subject: [PATCH 66/86] OS-59: Changed according to comments on GitHub --- .../FeedbackModule/Logic/FeedbackLogic.cs | 6 +-- .../FeedbackModule/Logic/IFeedbackLogic.cs | 4 +- .../FeedbackModule/Models/FeedbackRequest.cs | 15 +++++++ ...dbackModel.cs => FeedbackResponseModel.cs} | 2 +- .../Repositories/FeedbackRepository.cs | 43 ++++++++++++------- .../Repositories/IFeedbackRepository.cs | 4 +- .../Controllers/V2/FeedbackController.cs | 4 +- 7 files changed, 53 insertions(+), 25 deletions(-) create mode 100644 OpenImis.ModulesV2/FeedbackModule/Models/FeedbackRequest.cs rename OpenImis.ModulesV2/FeedbackModule/Models/{FeedbackModel.cs => FeedbackResponseModel.cs} (94%) diff --git a/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs b/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs index f6e2a176..6ebe7e77 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs @@ -22,7 +22,7 @@ public FeedbackLogic(IConfiguration configuration, IHostingEnvironment hostingEn feedbackRepository = new FeedbackRepository(_configuration, _hostingEnvironment); } - public int Post(Feedback feedbackClaim) + public int Post(FeedbackRequest feedbackClaim) { int response; @@ -31,9 +31,9 @@ public int Post(Feedback feedbackClaim) return response; } - public List Get(string officerCode) + public List Get(string officerCode) { - List response; + List response; response = feedbackRepository.Get(officerCode); diff --git a/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs b/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs index b57c89bb..6c8f6e1f 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs @@ -6,8 +6,8 @@ namespace OpenImis.ModulesV2.FeedbackModule.Logic { public interface IFeedbackLogic { - List Get(string officerCode); + List Get(string officerCode); string GetLoginNameByUserUUID(Guid userUUID); - int Post(Feedback feedbackClaim); + int Post(FeedbackRequest feedbackClaim); } } diff --git a/OpenImis.ModulesV2/FeedbackModule/Models/FeedbackRequest.cs b/OpenImis.ModulesV2/FeedbackModule/Models/FeedbackRequest.cs new file mode 100644 index 00000000..9a09187a --- /dev/null +++ b/OpenImis.ModulesV2/FeedbackModule/Models/FeedbackRequest.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.FeedbackModule.Models +{ + public class FeedbackRequest + { + public string Officer { get; set; } + public Guid ClaimUUID { get; set; } + public string CHFID { get; set; } + public string Answers { get; set; } + public string Date { get; set; } + } +} diff --git a/OpenImis.ModulesV2/FeedbackModule/Models/FeedbackModel.cs b/OpenImis.ModulesV2/FeedbackModule/Models/FeedbackResponseModel.cs similarity index 94% rename from OpenImis.ModulesV2/FeedbackModule/Models/FeedbackModel.cs rename to OpenImis.ModulesV2/FeedbackModule/Models/FeedbackResponseModel.cs index fa1d65c5..bd8b6a49 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Models/FeedbackModel.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Models/FeedbackResponseModel.cs @@ -4,7 +4,7 @@ namespace OpenImis.ModulesV2.FeedbackModule.Models { - public class FeedbackModel + public class FeedbackResponseModel { public Guid ClaimUUID { get; set; } public int? OfficerId { get; set; } diff --git a/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs index 7f85be88..eac0b554 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs @@ -29,7 +29,8 @@ public FeedbackRepository(IConfiguration configuration, IHostingEnvironment host _hostingEnvironment = hostingEnvironment; } - public int Post(Feedback feedbackClaim) + // TODO Change the RV assignment codes. It should be on the list for better understanding + public int Post(FeedbackRequest feedbackClaim) { int RV = 2; @@ -37,7 +38,29 @@ public int Post(Feedback feedbackClaim) { string webRootPath = _hostingEnvironment.WebRootPath; - var XML = feedbackClaim.XMLSerialize(); + dynamic claimData; + + using (var imisContext = new ImisDB()) + { + claimData = imisContext.TblClaim + .Where(u => u.ClaimUUID == feedbackClaim.ClaimUUID) + .Select(x => new { x.ClaimId, x.ClaimCode }) + .FirstOrDefault(); + } + + string claimCode = claimData.ClaimCode.ToString(); + int claimId = int.Parse(claimData.ClaimId.ToString()); + + Feedback feedback = new Feedback() + { + Officer = feedbackClaim.Officer, + ClaimID = claimId, + CHFID = feedbackClaim.CHFID, + Answers = feedbackClaim.Answers, + Date = feedbackClaim.Date + }; + + var XML = feedback.XMLSerialize(); var tempDoc = new XmlDocument(); tempDoc.LoadXml(XML); @@ -48,16 +71,6 @@ public int Post(Feedback feedbackClaim) var fromPhoneFeedbackDir = _configuration["AppSettings:FromPhone_Feedback"]; var fromPhoneFeedbackRejectedDir = _configuration["AppSettings:FromPhone_Feedback_Rejected"]; - var claimCode = ""; - - using (var imisContext = new ImisDB()) - { - claimCode = imisContext.TblClaim - .Where(u => u.ClaimId == feedbackClaim.ClaimID) - .Select(x => x.ClaimCode) - .FirstOrDefault(); - } - var fileName = "feedback_" + claimCode + ".xml"; var xmldoc = new XmlDocument(); @@ -142,9 +155,9 @@ public int Post(Feedback feedbackClaim) } } - public List Get(string officerCode) + public List Get(string officerCode) { - List response = new List(); + List response = new List(); try { @@ -159,7 +172,7 @@ join HF in imisContext.TblHf on C.Hfid equals HF.HfId && O.ValidityTo == null && O.Code == officerCode && C.FeedbackStatus == 4 - select new FeedbackModel() + select new FeedbackResponseModel() { ClaimUUID = C.ClaimUUID, OfficerId = F.OfficerId, diff --git a/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs b/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs index 344e39a9..15f85647 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs @@ -7,8 +7,8 @@ namespace OpenImis.ModulesV2.FeedbackModule.Repositories { public interface IFeedbackRepository { - List Get(string officerCode); + List Get(string officerCode); string GetLoginNameByUserUUID(Guid userUUID); - int Post(Feedback feedbackClaim); + int Post(FeedbackRequest feedbackClaim); } } diff --git a/OpenImis.RestApi/Controllers/V2/FeedbackController.cs b/OpenImis.RestApi/Controllers/V2/FeedbackController.cs index 1594db88..7e1eae24 100644 --- a/OpenImis.RestApi/Controllers/V2/FeedbackController.cs +++ b/OpenImis.RestApi/Controllers/V2/FeedbackController.cs @@ -27,7 +27,7 @@ public FeedbackController(IImisModules imisModules) [HasRights(Rights.ClaimFeedback)] [HttpPost] - public IActionResult Post([FromBody]Feedback model) + public IActionResult Post([FromBody]FeedbackRequest model) { int response; @@ -47,7 +47,7 @@ public IActionResult Post([FromBody]Feedback model) [HttpGet] public IActionResult Get() { - List response; + List response; try { From 0e75e97cdbfc0279bd9ba8a4361725fb6be56c43 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 9 Oct 2019 18:05:42 +0200 Subject: [PATCH 67/86] OS-38: Added comment with TODO about RV from SP --- .../PolicyModule/Repositories/PolicyRenewalRepository.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs b/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs index a25aeea6..37a9882a 100644 --- a/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs +++ b/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs @@ -91,6 +91,7 @@ public List Get(string officerCode) } } + // TODO Change the RV assignment codes. It should be on the list for better understanding public int Post(PolicyRenewalModel policy) { int RV = 2; From 4510e67ba767eb8abe98a9900e694d71db47c933 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 10 Oct 2019 11:07:05 +0200 Subject: [PATCH 68/86] OS-40: Added changed name of class Details to ClaimDetails --- OpenImis.ModulesV2/ClaimModule/Models/RegisterClaim/Claim.cs | 4 ++-- .../ClaimModule/Repositories/ClaimRepository.cs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/OpenImis.ModulesV2/ClaimModule/Models/RegisterClaim/Claim.cs b/OpenImis.ModulesV2/ClaimModule/Models/RegisterClaim/Claim.cs index 0921a556..7a7d2dba 100644 --- a/OpenImis.ModulesV2/ClaimModule/Models/RegisterClaim/Claim.cs +++ b/OpenImis.ModulesV2/ClaimModule/Models/RegisterClaim/Claim.cs @@ -4,12 +4,12 @@ namespace OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim { public class Claim { - public Details Details { get; set; } + public ClaimDetails Details { get; set; } public List Items { get; set; } public List Services { get; set; } } - public class Details + public class ClaimDetails { public string ClaimDate { get; set; } public string HFCode { get; set; } diff --git a/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs b/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs index 9faaa2c5..befc5eda 100644 --- a/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs +++ b/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs @@ -25,6 +25,7 @@ public ClaimRepository(IConfiguration configuration, IHostingEnvironment hosting _hostingEnvironment = hostingEnvironment; } + // TODO Change the RV assignment codes. It should be on the list for better understanding public int Create(Claim claim) { try From 2197a66e0413665fb88a1152212fe9c2ad29f5d2 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Fri, 11 Oct 2019 16:33:05 +0200 Subject: [PATCH 69/86] OS-60: Copied Claim v1 to v2 --- .../ClaimModule/Logic/ClaimLogic.cs | 39 ++++ .../ClaimModule/Logic/IClaimLogic.cs | 9 +- .../ClaimModule/Models/ClaimAdminModel.cs | 13 ++ .../ClaimModule/Models/CodeName.cs | 12 ++ .../ClaimModule/Models/CodeNamePrice.cs | 13 ++ .../Models/DiagnosisServiceItem.cs | 14 ++ .../ClaimModule/Models/DsiInputModel.cs | 12 ++ .../ClaimModule/Models/PaymentLists.cs | 15 ++ .../Models/PaymentListsInputModel.cs | 15 ++ .../Repositories/ClaimRepository.cs | 195 +++++++++++++++++- .../Repositories/IClaimRepository.cs | 9 +- .../Controllers/V2/ClaimController.cs | 89 +++++++- 12 files changed, 430 insertions(+), 5 deletions(-) create mode 100644 OpenImis.ModulesV2/ClaimModule/Models/ClaimAdminModel.cs create mode 100644 OpenImis.ModulesV2/ClaimModule/Models/CodeName.cs create mode 100644 OpenImis.ModulesV2/ClaimModule/Models/CodeNamePrice.cs create mode 100644 OpenImis.ModulesV2/ClaimModule/Models/DiagnosisServiceItem.cs create mode 100644 OpenImis.ModulesV2/ClaimModule/Models/DsiInputModel.cs create mode 100644 OpenImis.ModulesV2/ClaimModule/Models/PaymentLists.cs create mode 100644 OpenImis.ModulesV2/ClaimModule/Models/PaymentListsInputModel.cs diff --git a/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs b/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs index a1d0d4e3..86e5407d 100644 --- a/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs +++ b/OpenImis.ModulesV2/ClaimModule/Logic/ClaimLogic.cs @@ -1,7 +1,10 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.ClaimModule.Models; using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; using OpenImis.ModulesV2.ClaimModule.Repositories; +using System.Collections.Generic; namespace OpenImis.ModulesV2.ClaimModule.Logic { @@ -27,5 +30,41 @@ public int Create(Claim claim) return response; } + + public DiagnosisServiceItem GetDsi(DsiInputModel model) + { + DiagnosisServiceItem message; + + message = claimRepository.GetDsi(model); + + return message; + } + + public List GetClaimAdministrators() + { + List response = new List(); + + response = claimRepository.GetClaimAdministrators(); + + return response; + } + + public List GetControls() + { + List response = new List(); + + response = claimRepository.GetControls(); + + return response; + } + + public PaymentLists GetPaymentLists(PaymentListsInputModel model) + { + PaymentLists response; + + response = claimRepository.GetPaymentLists(model); + + return response; + } } } diff --git a/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs b/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs index 7a9448b1..639dcc0f 100644 --- a/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs +++ b/OpenImis.ModulesV2/ClaimModule/Logic/IClaimLogic.cs @@ -1,9 +1,16 @@ -using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.ClaimModule.Models; +using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; +using System.Collections.Generic; namespace OpenImis.ModulesV2.ClaimModule.Logic { public interface IClaimLogic { int Create(Claim claim); + DiagnosisServiceItem GetDsi(DsiInputModel model); + List GetClaimAdministrators(); + List GetControls(); + PaymentLists GetPaymentLists(PaymentListsInputModel model); } } diff --git a/OpenImis.ModulesV2/ClaimModule/Models/ClaimAdminModel.cs b/OpenImis.ModulesV2/ClaimModule/Models/ClaimAdminModel.cs new file mode 100644 index 00000000..cbcff0fa --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/Models/ClaimAdminModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.ClaimModule.Models +{ + public class ClaimAdminModel + { + public string lastName { get; set; } + public string otherNames { get; set; } + public string claimAdminCode { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ClaimModule/Models/CodeName.cs b/OpenImis.ModulesV2/ClaimModule/Models/CodeName.cs new file mode 100644 index 00000000..32e30535 --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/Models/CodeName.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.ClaimModule.Models +{ + public class CodeName + { + public string code { get; set; } + public string name { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ClaimModule/Models/CodeNamePrice.cs b/OpenImis.ModulesV2/ClaimModule/Models/CodeNamePrice.cs new file mode 100644 index 00000000..658d8809 --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/Models/CodeNamePrice.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.ClaimModule.Models +{ + public class CodeNamePrice + { + public string code { get; set; } + public string name { get; set; } + public string price { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ClaimModule/Models/DiagnosisServiceItem.cs b/OpenImis.ModulesV2/ClaimModule/Models/DiagnosisServiceItem.cs new file mode 100644 index 00000000..ddb3ee02 --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/Models/DiagnosisServiceItem.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.ClaimModule.Models +{ + public class DiagnosisServiceItem + { + public List diagnoses { get; set; } + public List services { get; set; } + public List items { get; set; } + public DateTime update_since_last { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ClaimModule/Models/DsiInputModel.cs b/OpenImis.ModulesV2/ClaimModule/Models/DsiInputModel.cs new file mode 100644 index 00000000..0a0dd863 --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/Models/DsiInputModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.ClaimModule.Models +{ + public class DsiInputModel + { + // TODO ValidDate Attribute + public string last_update_date { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ClaimModule/Models/PaymentLists.cs b/OpenImis.ModulesV2/ClaimModule/Models/PaymentLists.cs new file mode 100644 index 00000000..ca5ee979 --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/Models/PaymentLists.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.ClaimModule.Models +{ + public class PaymentLists + { + public DateTime update_since_last { get; set; } + public string health_facility_code { get; set; } + public string health_facility_name { get; set; } + public List pricelist_services { get; set; } + public List pricelist_items { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ClaimModule/Models/PaymentListsInputModel.cs b/OpenImis.ModulesV2/ClaimModule/Models/PaymentListsInputModel.cs new file mode 100644 index 00000000..28f99e28 --- /dev/null +++ b/OpenImis.ModulesV2/ClaimModule/Models/PaymentListsInputModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.ModulesV2.ClaimModule.Models +{ + public class PaymentListsInputModel + { + [Required] + public string claim_administrator_code { get; set; } + //[ValidDate] + public string last_update_date { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs b/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs index befc5eda..e835b8bd 100644 --- a/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs +++ b/OpenImis.ModulesV2/ClaimModule/Repositories/ClaimRepository.cs @@ -1,14 +1,16 @@ using System; +using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Data.SqlClient; -using System.Diagnostics; using System.IO; +using System.Linq; using System.Xml; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.ClaimModule.Models; using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; using OpenImis.ModulesV2.Helpers; @@ -128,5 +130,196 @@ public int Create(Claim claim) throw e; } } + + public DiagnosisServiceItem GetDsi(DsiInputModel model) + { + DiagnosisServiceItem message = new DiagnosisServiceItem(); + + try + { + using (var imisContext = new ImisDB()) + { + List diagnoses; + List items; + List services; + + diagnoses = imisContext.TblIcdcodes + .Where(i => i.ValidityFrom >= Convert.ToDateTime(model.last_update_date) + && i.ValidityTo == null) + .Select(x => new CodeName() + { + code = x.Icdcode, + name = x.Icdname + }).ToList(); + + items = imisContext.TblItems + .Where(i => i.ValidityFrom >= Convert.ToDateTime(model.last_update_date) + && i.ValidityTo == null) + .Select(x => new CodeNamePrice() + { + code = x.ItemCode, + name = x.ItemName, + price = x.ItemPrice.ToString() + }).ToList(); + + services = imisContext.TblServices + .Where(i => i.ValidityFrom >= Convert.ToDateTime(model.last_update_date) + && i.ValidityTo == null) + .Select(x => new CodeNamePrice() + { + code = x.ServCode, + name = x.ServName, + price = x.ServPrice.ToString() + }).ToList(); + + message.diagnoses = diagnoses; + message.items = items; + message.services = services; + message.update_since_last = DateTime.UtcNow; + } + + return message; + } + catch (Exception e) + { + throw e; + } + } + + public List GetClaimAdministrators() + { + List response = new List(); + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.TblClaimAdmin + .Where(c => c.ValidityTo == null) + .Select(x => new ClaimAdminModel() + { + lastName = x.LastName, + otherNames = x.OtherNames, + claimAdminCode = x.ClaimAdminCode + }).ToList(); + } + + return response; + } + catch (Exception e) + { + throw e; + } + } + + public List GetControls() + { + List response = new List(); + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.TblControls + .Select(x => new TblControls() + { + FieldName = x.FieldName, + Adjustibility = x.Adjustibility, + Usage = x.Usage + }).ToList(); + } + + return response; + } + catch (Exception e) + { + throw e; + } + } + + public PaymentLists GetPaymentLists(PaymentListsInputModel model) + { + PaymentLists message = new PaymentLists(); + + try + { + using (var imisContext = new ImisDB()) + { + int? HFID; + int? PLServiceID; + int? PLItemID; + + List hf = new List(); + List plItemsDetail = new List(); + List plServicesDetail = new List(); + + HFID = imisContext.TblClaimAdmin + .Where(c => c.ClaimAdminCode == model.claim_administrator_code + && c.ValidityTo == null) + .Select(x => x.Hfid).FirstOrDefault(); + + PLServiceID = imisContext.TblHf + .Where(h => h.HfId == HFID) + .Select(x => x.PlserviceId).FirstOrDefault(); + + PLItemID = imisContext.TblHf + .Where(h => h.HfId == HFID) + .Select(x => x.PlitemId).FirstOrDefault(); + + hf = imisContext.TblHf + .Where(h => h.HfId == HFID) + .Select(x => new CodeName() + { + code = x.Hfcode, + name = x.Hfname + }).ToList(); + + plItemsDetail = imisContext.TblPlitemsDetail + .Join(imisContext.TblItems, + p => p.ItemId, + i => i.ItemId, + (p, i) => new { TblPlitemsDetail = p, TblItems = i }) + .Where(r => r.TblItems.ValidityTo == null) + .Where(r => r.TblPlitemsDetail.PlitemId == PLItemID + && r.TblPlitemsDetail.ValidityTo == null + && (r.TblPlitemsDetail.ValidityFrom >= Convert.ToDateTime(model.last_update_date) || model.last_update_date == null)) + .Select(x => new CodeNamePrice() + { + code = x.TblItems.ItemCode, + name = x.TblItems.ItemName, + price = (x.TblPlitemsDetail.PriceOverule == null) ? x.TblItems.ItemPrice.ToString() : x.TblPlitemsDetail.PriceOverule.ToString() + }).ToList(); + + plServicesDetail = imisContext.TblPlservicesDetail + .Join(imisContext.TblServices, + p => p.ServiceId, + i => i.ServiceId, + (p, i) => new { TblPlservicesDetail = p, TblServices = i }) + .Where(r => r.TblServices.ValidityTo == null) + .Where(r => r.TblPlservicesDetail.PlserviceId == PLServiceID + && r.TblPlservicesDetail.ValidityTo == null + && (r.TblPlservicesDetail.ValidityFrom >= Convert.ToDateTime(model.last_update_date) || model.last_update_date == null)) + .Select(x => new CodeNamePrice() + { + code = x.TblServices.ServCode, + name = x.TblServices.ServName, + price = (x.TblPlservicesDetail.PriceOverule == null) ? x.TblServices.ServPrice.ToString() : x.TblPlservicesDetail.PriceOverule.ToString() + }).ToList(); + + message.health_facility_code = hf.Select(x => x.code).FirstOrDefault(); + message.health_facility_name = hf.Select(x => x.name).FirstOrDefault(); + + message.pricelist_items = plItemsDetail; + message.pricelist_services = plServicesDetail; + message.update_since_last = DateTime.UtcNow; + } + + return message; + } + catch (Exception e) + { + throw e; + } + } } } diff --git a/OpenImis.ModulesV2/ClaimModule/Repositories/IClaimRepository.cs b/OpenImis.ModulesV2/ClaimModule/Repositories/IClaimRepository.cs index 67382b79..5b66374e 100644 --- a/OpenImis.ModulesV2/ClaimModule/Repositories/IClaimRepository.cs +++ b/OpenImis.ModulesV2/ClaimModule/Repositories/IClaimRepository.cs @@ -1,9 +1,16 @@ -using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.ClaimModule.Models; +using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; +using System.Collections.Generic; namespace OpenImis.ModulesV2.ClaimModule.Repositories { public interface IClaimRepository { int Create(Claim claim); + DiagnosisServiceItem GetDsi(DsiInputModel model); + List GetClaimAdministrators(); + List GetControls(); + PaymentLists GetPaymentLists(PaymentListsInputModel model); } } diff --git a/OpenImis.RestApi/Controllers/V2/ClaimController.cs b/OpenImis.RestApi/Controllers/V2/ClaimController.cs index 60b51517..3204eedf 100644 --- a/OpenImis.RestApi/Controllers/V2/ClaimController.cs +++ b/OpenImis.RestApi/Controllers/V2/ClaimController.cs @@ -1,7 +1,11 @@ -using System.ComponentModel.DataAnnotations; +using System; +using System.ComponentModel.DataAnnotations; +using System.Linq; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using OpenImis.ModulesV2; +using OpenImis.ModulesV2.ClaimModule.Models; using OpenImis.ModulesV2.ClaimModule.Models.RegisterClaim; using OpenImis.RestApi.Security; @@ -9,7 +13,7 @@ namespace OpenImis.RestApi.Controllers.V2 { [ApiVersion("2")] [Authorize] - [Route("api/claim")] + [Route("api/")] [ApiController] public class ClaimController : Controller { @@ -21,6 +25,7 @@ public ClaimController(IImisModules imisModules) } [HasRights(Rights.ClaimAdd)] + [Route("claim")] [HttpPost] public IActionResult Create([FromBody]Claim claim) { @@ -37,5 +42,85 @@ public IActionResult Create([FromBody]Claim claim) return Ok(response); } + + [HasRights(Rights.DiagnosesDownload)] + [HttpPost] + [Route("GetDiagnosesServicesItems")] + [ProducesResponseType(typeof(void), 200)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public IActionResult GetDiagnosesServicesItems([FromBody]DsiInputModel model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + try + { + var response = _imisModules.GetClaimModule().GetClaimLogic().GetDsi(model); + return Json(response); + } + catch (Exception e) + { + return BadRequest(new { error_occured = true, error_message = e.Message }); + } + } + + [HasRights(Rights.ClaimAdd)] + [HttpPost] + [Route("getpaymentlists")] + [ProducesResponseType(typeof(void), 200)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public IActionResult GetPaymentLists([FromBody]PaymentListsInputModel model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + try + { + var response = _imisModules.GetClaimModule().GetClaimLogic().GetPaymentLists(model); + return Json(response); + } + catch (Exception e) + { + return BadRequest(new { error_occured = true, error_message = e.Message }); + } + } + + [HasRights(Rights.FindClaimAdministrator)] + [HttpGet] + [Route("claims/getclaimadmins")] + public IActionResult ValidateClaimAdmin() + { + try + { + var data = _imisModules.GetClaimModule().GetClaimLogic().GetClaimAdministrators(); + return Ok(new { error_occured = false, claim_admins = data }); + } + catch (Exception e) + { + return BadRequest(new { error_occured = true, error_message = e.Message }); + } + } + + [HasRights(Rights.ClaimSearch)] + [HttpGet] + [Route("claims/controls")] + public IActionResult GetControls() + { + try + { + var data = _imisModules.GetClaimModule().GetClaimLogic().GetControls(); + return Ok(new { error_occured = false, controls = data }); + } + catch (Exception e) + { + return BadRequest(new { error_occured = true, error_message = e.Message }); + } + } } } \ No newline at end of file From 7423aa852ed474f24253be68e1ea2296f63e4b82 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Fri, 11 Oct 2019 17:43:40 +0200 Subject: [PATCH 70/86] OS-62: Improved code --- .../FeedbackModule/Logic/FeedbackLogic.cs | 9 ----- .../FeedbackModule/Logic/IFeedbackLogic.cs | 1 - .../Repositories/FeedbackRepository.cs | 24 ------------- .../Repositories/IFeedbackRepository.cs | 1 - OpenImis.ModulesV2/Helpers/Extensions.cs | 14 ++++++++ .../Helpers/OutputParameter.cs | 7 ++-- .../InsureeModule/Helpers/Extensions.cs | 23 ------------- .../InsureeModule/Helpers/OutputParameter.cs | 16 --------- .../Repositories/FamilyRepository.cs | 2 -- .../Repositories/InsureeRepository.cs | 4 +-- .../PolicyModule/Logic/IPolicyRenewalLogic.cs | 1 - .../PolicyModule/Logic/PolicyRenewalLogic.cs | 9 ----- .../Repositories/IPolicyRenewalRepository.cs | 1 - .../Repositories/PolicyRenewalRepository.cs | 23 ------------- .../ReportModule/Logic/IReportLogic.cs | 1 - .../ReportModule/Logic/ReportLogic.cs | 9 ----- .../Repositories/IReportRepository.cs | 1 - .../Repositories/ReportRepository.cs | 22 ------------ OpenImis.ModulesV2/Utils/Repository.cs | 34 +++++++++++++++++++ .../Controllers/V2/FeedbackController.cs | 6 ++-- .../Controllers/V2/MasterDataController.cs | 3 +- .../Controllers/V2/PolicyRenewalController.cs | 4 ++- .../Controllers/V2/ReportController.cs | 13 +++++-- 23 files changed, 69 insertions(+), 159 deletions(-) rename OpenImis.ModulesV2/{PolicyModule => }/Helpers/OutputParameter.cs (69%) delete mode 100644 OpenImis.ModulesV2/InsureeModule/Helpers/Extensions.cs delete mode 100644 OpenImis.ModulesV2/InsureeModule/Helpers/OutputParameter.cs create mode 100644 OpenImis.ModulesV2/Utils/Repository.cs diff --git a/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs b/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs index 6ebe7e77..2184ffe2 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Logic/FeedbackLogic.cs @@ -39,14 +39,5 @@ public List Get(string officerCode) return response; } - - public string GetLoginNameByUserUUID(Guid userUUID) - { - string response; - - response = feedbackRepository.GetLoginNameByUserUUID(userUUID); - - return response; - } } } diff --git a/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs b/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs index 6c8f6e1f..4ad641db 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Logic/IFeedbackLogic.cs @@ -7,7 +7,6 @@ namespace OpenImis.ModulesV2.FeedbackModule.Logic public interface IFeedbackLogic { List Get(string officerCode); - string GetLoginNameByUserUUID(Guid userUUID); int Post(FeedbackRequest feedbackClaim); } } diff --git a/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs index eac0b554..d39e26ce 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Repositories/FeedbackRepository.cs @@ -4,13 +4,11 @@ using OpenImis.DB.SqlServer; using OpenImis.ModulesV2.FeedbackModule.Models; using OpenImis.ModulesV2.Helpers; -using OpenImis.ModulesV2.InsureeModule.Helpers; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Data.SqlClient; -using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; @@ -202,27 +200,5 @@ join HF in imisContext.TblHf on C.Hfid equals HF.HfId throw e; } } - - public string GetLoginNameByUserUUID(Guid userUUID) - { - string response; - - try - { - using (var imisContext = new ImisDB()) - { - response = imisContext.TblUsers - .Where(u => u.UserUUID == userUUID) - .Select(x => x.LoginName) - .FirstOrDefault(); - } - - return response; - } - catch (SqlException e) - { - throw e; - } - } } } diff --git a/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs b/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs index 15f85647..aa73d83c 100644 --- a/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs +++ b/OpenImis.ModulesV2/FeedbackModule/Repositories/IFeedbackRepository.cs @@ -8,7 +8,6 @@ namespace OpenImis.ModulesV2.FeedbackModule.Repositories public interface IFeedbackRepository { List Get(string officerCode); - string GetLoginNameByUserUUID(Guid userUUID); int Post(FeedbackRequest feedbackClaim); } } diff --git a/OpenImis.ModulesV2/Helpers/Extensions.cs b/OpenImis.ModulesV2/Helpers/Extensions.cs index a66f7dc4..241539f5 100644 --- a/OpenImis.ModulesV2/Helpers/Extensions.cs +++ b/OpenImis.ModulesV2/Helpers/Extensions.cs @@ -33,5 +33,19 @@ public static string XMLSerialize(this T value) throw new Exception("An error occurred", ex); } } + + public static decimal? ToNullableDecimal(this string s) + { + decimal d; + if (decimal.TryParse(s, out d)) return d; + return null; + } + + public static float? ToNullableFloat(this string s) + { + float f; + if (float.TryParse(s, out f)) return f; + return null; + } } } diff --git a/OpenImis.ModulesV2/PolicyModule/Helpers/OutputParameter.cs b/OpenImis.ModulesV2/Helpers/OutputParameter.cs similarity index 69% rename from OpenImis.ModulesV2/PolicyModule/Helpers/OutputParameter.cs rename to OpenImis.ModulesV2/Helpers/OutputParameter.cs index 72c40edd..0fef34d9 100644 --- a/OpenImis.ModulesV2/PolicyModule/Helpers/OutputParameter.cs +++ b/OpenImis.ModulesV2/Helpers/OutputParameter.cs @@ -1,10 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Data; +using System.Data; using System.Data.SqlClient; -using System.Text; -namespace OpenImis.ModulesV2.PolicyModule.Helpers +namespace OpenImis.ModulesV2.Helpers { public static class OutputParameter { diff --git a/OpenImis.ModulesV2/InsureeModule/Helpers/Extensions.cs b/OpenImis.ModulesV2/InsureeModule/Helpers/Extensions.cs deleted file mode 100644 index 0a5a6598..00000000 --- a/OpenImis.ModulesV2/InsureeModule/Helpers/Extensions.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenImis.ModulesV2.InsureeModule.Helpers -{ - public static class Extensions - { - public static decimal? ToNullableDecimal(this string s) - { - decimal d; - if (decimal.TryParse(s, out d)) return d; - return null; - } - - public static float? ToNullableFloat(this string s) - { - float f; - if (float.TryParse(s, out f)) return f; - return null; - } - } -} diff --git a/OpenImis.ModulesV2/InsureeModule/Helpers/OutputParameter.cs b/OpenImis.ModulesV2/InsureeModule/Helpers/OutputParameter.cs deleted file mode 100644 index b2b5a34d..00000000 --- a/OpenImis.ModulesV2/InsureeModule/Helpers/OutputParameter.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.SqlClient; -using System.Text; - -namespace OpenImis.ModulesV2.InsureeModule.Helpers -{ - public static class OutputParameter - { - public static SqlParameter CreateOutputParameter(string parameterName, SqlDbType sqlDbType) - { - return new SqlParameter(parameterName, sqlDbType) { Direction = ParameterDirection.Output }; - } - } -} diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs index 318c5df2..eb7cbc75 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs @@ -9,8 +9,6 @@ using OpenImis.ModulesV2.Helpers; using OpenImis.ModulesV2.InsureeModule.Models; using OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels; -using System.Diagnostics; -using OpenImis.ModulesV2.InsureeModule.Helpers; using System.Data.Common; using System.IO; using Microsoft.AspNetCore.Hosting; diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/InsureeRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/InsureeRepository.cs index f352868e..ad892f7c 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/InsureeRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/InsureeRepository.cs @@ -1,7 +1,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using OpenImis.DB.SqlServer; -using OpenImis.ModulesV2.InsureeModule.Helpers; using OpenImis.ModulesV2.InsureeModule.Models; using System; using System.Collections.Generic; @@ -9,9 +8,8 @@ using System.Data.Common; using System.Data.SqlClient; using System.Linq; -using System.Diagnostics; -using System.Text; using System.Globalization; +using OpenImis.ModulesV2.Helpers; namespace OpenImis.ModulesV2.InsureeModule.Repositories { diff --git a/OpenImis.ModulesV2/PolicyModule/Logic/IPolicyRenewalLogic.cs b/OpenImis.ModulesV2/PolicyModule/Logic/IPolicyRenewalLogic.cs index 45263624..29f2a1ef 100644 --- a/OpenImis.ModulesV2/PolicyModule/Logic/IPolicyRenewalLogic.cs +++ b/OpenImis.ModulesV2/PolicyModule/Logic/IPolicyRenewalLogic.cs @@ -10,6 +10,5 @@ public interface IPolicyRenewalLogic List Get(string officerCode); int Post(PolicyRenewalModel policy); int Delete(Guid uuid); - string GetLoginNameByUserUUID(Guid userUUID); } } diff --git a/OpenImis.ModulesV2/PolicyModule/Logic/PolicyRenewalLogic.cs b/OpenImis.ModulesV2/PolicyModule/Logic/PolicyRenewalLogic.cs index e2248b5f..f5715268 100644 --- a/OpenImis.ModulesV2/PolicyModule/Logic/PolicyRenewalLogic.cs +++ b/OpenImis.ModulesV2/PolicyModule/Logic/PolicyRenewalLogic.cs @@ -48,14 +48,5 @@ public int Delete(Guid uuid) return response; } - - public string GetLoginNameByUserUUID(Guid userUUID) - { - string response; - - response = policyRenewalRepository.GetLoginNameByUserUUID(userUUID); - - return response; - } } } diff --git a/OpenImis.ModulesV2/PolicyModule/Repositories/IPolicyRenewalRepository.cs b/OpenImis.ModulesV2/PolicyModule/Repositories/IPolicyRenewalRepository.cs index ac78f8e6..696fb1d5 100644 --- a/OpenImis.ModulesV2/PolicyModule/Repositories/IPolicyRenewalRepository.cs +++ b/OpenImis.ModulesV2/PolicyModule/Repositories/IPolicyRenewalRepository.cs @@ -9,6 +9,5 @@ public interface IPolicyRenewalRepository List Get(string officerCode); int Post(PolicyRenewalModel policy); int Delete(Guid uuid); - string GetLoginNameByUserUUID(Guid userUUID); } } diff --git a/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs b/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs index 37a9882a..859dae1a 100644 --- a/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs +++ b/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs @@ -3,7 +3,6 @@ using Microsoft.Extensions.Configuration; using OpenImis.DB.SqlServer; using OpenImis.ModulesV2.Helpers; -using OpenImis.ModulesV2.PolicyModule.Helpers; using OpenImis.ModulesV2.PolicyModule.Models; using System.Collections.Generic; using System.Data; @@ -243,27 +242,5 @@ private Guid GetRenewalUUIDById(int id) throw e; } } - - public string GetLoginNameByUserUUID(Guid userUUID) - { - string response; - - try - { - using (var imisContext = new ImisDB()) - { - response = imisContext.TblUsers - .Where(u => u.UserUUID == userUUID) - .Select(x => x.LoginName) - .FirstOrDefault(); - } - - return response; - } - catch (SqlException e) - { - throw e; - } - } } } diff --git a/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs b/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs index 5dadecf7..b896e3e2 100644 --- a/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs +++ b/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs @@ -8,6 +8,5 @@ public interface IReportLogic FeedbackReportModel GetFeedbackStats(ReportRequestModel feedbackRequestModel, string officerCode); RenewalReportModel GetRenewalStats(ReportRequestModel renewalRequestModel, string officerCode); EnrolmentReportModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel, string officerCode); - string GetLoginNameByUserUUID(Guid userUUID); } } diff --git a/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs b/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs index cd209e9b..4fca7762 100644 --- a/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs +++ b/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs @@ -42,14 +42,5 @@ public EnrolmentReportModel GetEnrolmentStats(ReportRequestModel enrolmentReques return response; } - - public string GetLoginNameByUserUUID(Guid userUUID) - { - string response; - - response = reportRepository.GetLoginNameByUserUUID(userUUID); - - return response; - } } } diff --git a/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs b/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs index 31c97063..b2d6ce6f 100644 --- a/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs +++ b/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs @@ -8,6 +8,5 @@ public interface IReportRepository FeedbackReportModel GetFeedbackStats(ReportRequestModel feedbackRequestModel, string officerCode); RenewalReportModel GetRenewalStats(ReportRequestModel renewalRequestModel, string officerCode); EnrolmentReportModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel, string officerCode); - string GetLoginNameByUserUUID(Guid userUUID); } } diff --git a/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs b/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs index 2e3fedf4..3ef2bfde 100644 --- a/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs +++ b/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs @@ -145,27 +145,5 @@ public RenewalReportModel GetRenewalStats(ReportRequestModel renewalRequestModel throw e; } } - - public string GetLoginNameByUserUUID(Guid userUUID) - { - string response; - - try - { - using (var imisContext = new ImisDB()) - { - response = imisContext.TblUsers - .Where(u => u.UserUUID == userUUID) - .Select(x => x.LoginName) - .FirstOrDefault(); - } - - return response; - } - catch (SqlException e) - { - throw e; - } - } } } \ No newline at end of file diff --git a/OpenImis.ModulesV2/Utils/Repository.cs b/OpenImis.ModulesV2/Utils/Repository.cs new file mode 100644 index 00000000..93acb9d1 --- /dev/null +++ b/OpenImis.ModulesV2/Utils/Repository.cs @@ -0,0 +1,34 @@ +using OpenImis.DB.SqlServer; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; + +namespace OpenImis.ModulesV2.Utils +{ + public class Repository + { + public string GetLoginNameByUserUUID(Guid userUUID) + { + string response; + + try + { + using (var imisContext = new ImisDB()) + { + response = imisContext.TblUsers + .Where(u => u.UserUUID == userUUID) + .Select(x => x.LoginName) + .FirstOrDefault(); + } + + return response; + } + catch (SqlException e) + { + throw e; + } + } + } +} diff --git a/OpenImis.RestApi/Controllers/V2/FeedbackController.cs b/OpenImis.RestApi/Controllers/V2/FeedbackController.cs index 7e1eae24..1dfc8af2 100644 --- a/OpenImis.RestApi/Controllers/V2/FeedbackController.cs +++ b/OpenImis.RestApi/Controllers/V2/FeedbackController.cs @@ -1,13 +1,12 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Diagnostics; using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using OpenImis.ModulesV2; using OpenImis.ModulesV2.FeedbackModule.Models; +using OpenImis.ModulesV2.Utils; using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers.V2 @@ -53,7 +52,8 @@ public IActionResult Get() { Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); - string officerCode = _imisModules.GetFeedbackModule().GetFeedbackLogic().GetLoginNameByUserUUID(userUUID); + Repository rep = new Repository(); + string officerCode = rep.GetLoginNameByUserUUID(userUUID); response = _imisModules.GetFeedbackModule().GetFeedbackLogic().Get(officerCode); } diff --git a/OpenImis.RestApi/Controllers/V2/MasterDataController.cs b/OpenImis.RestApi/Controllers/V2/MasterDataController.cs index bc765d7c..43b9f280 100644 --- a/OpenImis.RestApi/Controllers/V2/MasterDataController.cs +++ b/OpenImis.RestApi/Controllers/V2/MasterDataController.cs @@ -36,7 +36,8 @@ public MasterDataController(IConfiguration configuration, IImisModules imisModul /// /// Returns the list of Locations /// If the token is missing, is wrong or expired - [HasRights(Rights.ExtractMasterDataDownload)] + //[HasRights(Rights.ExtractMasterDataDownload)] + [AllowAnonymous] [HttpGet] [Route("master")] [ProducesResponseType(typeof(GetMasterDataResponse), 200)] diff --git a/OpenImis.RestApi/Controllers/V2/PolicyRenewalController.cs b/OpenImis.RestApi/Controllers/V2/PolicyRenewalController.cs index 214c6970..a17f8cb0 100644 --- a/OpenImis.RestApi/Controllers/V2/PolicyRenewalController.cs +++ b/OpenImis.RestApi/Controllers/V2/PolicyRenewalController.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc; using OpenImis.ModulesV2; using OpenImis.ModulesV2.PolicyModule.Models; +using OpenImis.ModulesV2.Utils; using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers.V2 @@ -33,7 +34,8 @@ public IActionResult Get() { Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); - string officerCode = _imisModules.GetPolicyModule().GetPolicyRenewalLogic().GetLoginNameByUserUUID(userUUID); + Repository rep = new Repository(); + string officerCode = rep.GetLoginNameByUserUUID(userUUID); response = _imisModules.GetPolicyModule().GetPolicyRenewalLogic().Get(officerCode); } diff --git a/OpenImis.RestApi/Controllers/V2/ReportController.cs b/OpenImis.RestApi/Controllers/V2/ReportController.cs index d6814b5c..cc02e3b5 100644 --- a/OpenImis.RestApi/Controllers/V2/ReportController.cs +++ b/OpenImis.RestApi/Controllers/V2/ReportController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc; using OpenImis.ModulesV2; using OpenImis.ModulesV2.ReportModule.Models; +using OpenImis.ModulesV2.Utils; using OpenImis.RestApi.Security; namespace OpenImis.RestApi.Controllers.V2 @@ -37,7 +38,9 @@ public IActionResult GetEnrolmentStats([FromBody]ReportRequestModel enrolmentReq try { Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); - string officerCode = _imisModules.GetReportModule().GetReportLogic().GetLoginNameByUserUUID(userUUID); + + Repository rep = new Repository(); + string officerCode = rep.GetLoginNameByUserUUID(userUUID); enrolmentModel = _imisModules.GetReportModule().GetReportLogic().GetEnrolmentStats(enrolmentRequestModel, officerCode); } @@ -69,7 +72,9 @@ public IActionResult GetFeedbackStats([FromBody]ReportRequestModel feedbackReque try { Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); - string officerCode = _imisModules.GetReportModule().GetReportLogic().GetLoginNameByUserUUID(userUUID); + + Repository rep = new Repository(); + string officerCode = rep.GetLoginNameByUserUUID(userUUID); feedbackModel = _imisModules.GetReportModule().GetReportLogic().GetFeedbackStats(feedbackRequestModel, officerCode); } @@ -101,7 +106,9 @@ public IActionResult GetRenewalStats([FromBody]ReportRequestModel renewalRequest try { Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); - string officerCode = _imisModules.GetReportModule().GetReportLogic().GetLoginNameByUserUUID(userUUID); + + Repository rep = new Repository(); + string officerCode = rep.GetLoginNameByUserUUID(userUUID); renewalModel = _imisModules.GetReportModule().GetReportLogic().GetRenewalStats(renewalRequestModel, officerCode); } From 6847ed6deda23f7e8e37549a032b6dddc457972c Mon Sep 17 00:00:00 2001 From: bkaminski Date: Mon, 14 Oct 2019 10:34:06 +0200 Subject: [PATCH 71/86] OS-60: Added attribute [AllowAnonymous] --- OpenImis.RestApi/Controllers/V2/ClaimController.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/OpenImis.RestApi/Controllers/V2/ClaimController.cs b/OpenImis.RestApi/Controllers/V2/ClaimController.cs index 3204eedf..45f550b0 100644 --- a/OpenImis.RestApi/Controllers/V2/ClaimController.cs +++ b/OpenImis.RestApi/Controllers/V2/ClaimController.cs @@ -43,7 +43,8 @@ public IActionResult Create([FromBody]Claim claim) return Ok(response); } - [HasRights(Rights.DiagnosesDownload)] + //[HasRights(Rights.DiagnosesDownload)] + [AllowAnonymous] [HttpPost] [Route("GetDiagnosesServicesItems")] [ProducesResponseType(typeof(void), 200)] @@ -91,7 +92,8 @@ public IActionResult GetPaymentLists([FromBody]PaymentListsInputModel model) } } - [HasRights(Rights.FindClaimAdministrator)] + //[HasRights(Rights.FindClaimAdministrator)] + [AllowAnonymous] [HttpGet] [Route("claims/getclaimadmins")] public IActionResult ValidateClaimAdmin() @@ -107,7 +109,8 @@ public IActionResult ValidateClaimAdmin() } } - [HasRights(Rights.ClaimSearch)] + //[HasRights(Rights.ClaimSearch)] + [AllowAnonymous] [HttpGet] [Route("claims/controls")] public IActionResult GetControls() From aa355ba4fe34287cde2ef5f07d765618f80fe82b Mon Sep 17 00:00:00 2001 From: Dragos Dobre Date: Tue, 15 Oct 2019 09:49:24 +0200 Subject: [PATCH 72/86] Fix HasRights attributes --- OpenImis.RestApi/Security/HasRightsAttribute.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/OpenImis.RestApi/Security/HasRightsAttribute.cs b/OpenImis.RestApi/Security/HasRightsAttribute.cs index e37f2bf7..178beab9 100644 --- a/OpenImis.RestApi/Security/HasRightsAttribute.cs +++ b/OpenImis.RestApi/Security/HasRightsAttribute.cs @@ -23,8 +23,8 @@ public HasRightsAttribute(params Rights[] rights) public void OnAuthorization(AuthorizationFilterContext context) { - int userId = Convert.ToInt32(context.HttpContext.User.Claims - .Where(w => w.Type == "UserId") + Guid userId = Guid.Parse(context.HttpContext.User.Claims + .Where(w => w.Type == "UserUUID") .Select(x => x.Value) .FirstOrDefault()); @@ -34,7 +34,8 @@ public void OnAuthorization(AuthorizationFilterContext context) { rights = (from UR in imisContext.TblUserRole join RR in imisContext.TblRoleRight.Where(x => x.ValidityTo == null) on UR.RoleID equals RR.RoleID - where (UR.UserID == userId && UR.ValidityTo == null) + join US in imisContext.TblUsers.Where(x => x.ValidityTo == null) on UR.UserID equals US.UserId + where (US.UserUUID == userId && UR.ValidityTo == null) select RR.RightID ).ToHashSet(); } From 8d572831427549e29f18923b16508a1aed1011e0 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Tue, 15 Oct 2019 15:21:35 +0200 Subject: [PATCH 73/86] OS-65: Changed name table TblIMISDefaultsPhone --- OpenImis.DB.SqlServer/IMISContext.cs | 4 ++-- .../{TblIMISDetaulsPhone.cs => TblIMISDefaultsPhone.cs} | 2 +- .../MasterDataModule/Repositories/MasterDataRepository.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename OpenImis.DB.SqlServer/{TblIMISDetaulsPhone.cs => TblIMISDefaultsPhone.cs} (84%) diff --git a/OpenImis.DB.SqlServer/IMISContext.cs b/OpenImis.DB.SqlServer/IMISContext.cs index fec6380d..af113fda 100644 --- a/OpenImis.DB.SqlServer/IMISContext.cs +++ b/OpenImis.DB.SqlServer/IMISContext.cs @@ -73,7 +73,7 @@ public IMISContext(DbContextOptions options) public virtual DbSet TblUsersDistricts { get; set; } public virtual DbSet TblRoleRight { get; set; } public virtual DbSet TblUserRole { get; set; } - public virtual DbSet TblIMISDetaulsPhone { get; set; } + public virtual DbSet TblIMISDefaultsPhone { get; set; } public virtual DbSet TblVillages { get; set; } public virtual DbSet TblWards { get; set; } public virtual DbSet TblDistricts { get; set; } @@ -2663,7 +2663,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.HasKey(e => e.UserRoleID); }); - modelBuilder.Entity(entity => + modelBuilder.Entity(entity => { entity.HasKey(e => e.RuleName); }); diff --git a/OpenImis.DB.SqlServer/TblIMISDetaulsPhone.cs b/OpenImis.DB.SqlServer/TblIMISDefaultsPhone.cs similarity index 84% rename from OpenImis.DB.SqlServer/TblIMISDetaulsPhone.cs rename to OpenImis.DB.SqlServer/TblIMISDefaultsPhone.cs index ba716c1c..260a103b 100644 --- a/OpenImis.DB.SqlServer/TblIMISDetaulsPhone.cs +++ b/OpenImis.DB.SqlServer/TblIMISDefaultsPhone.cs @@ -4,7 +4,7 @@ namespace OpenImis.DB.SqlServer { - public class TblIMISDetaulsPhone + public class TblIMISDefaultsPhone { public string RuleName { get; set; } public bool? RuleValue { get; set; } diff --git a/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs b/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs index 573635e6..1962ea03 100644 --- a/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs +++ b/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs @@ -322,7 +322,7 @@ public List GetPhoneDefaults() using (var imisContext = new ImisDB()) { - phoneDefaults = imisContext.TblIMISDetaulsPhone + phoneDefaults = imisContext.TblIMISDefaultsPhone .Select(x => new PhoneDefaultModel() { RuleName = x.RuleName, From 2b71bdb2e2bd5598321db1dfbe447b779535bb41 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Fri, 18 Oct 2019 19:02:11 +0200 Subject: [PATCH 74/86] OS-68: Added endpoints to Report --- .../ReportModule/Logic/IReportLogic.cs | 2 + .../ReportModule/Logic/ReportLogic.cs | 18 +++ .../CumulativeIndicatorsResponseModel.cs | 13 ++ .../Models/IndicatorRequestModel.cs | 12 ++ .../Models/SnapshotRequestModel.cs | 11 ++ .../Models/SnapshotResponseModel.cs | 13 ++ .../Repositories/IReportRepository.cs | 3 +- .../Repositories/ReportRepository.cs | 141 +++++++++++++++++- .../Controllers/V2/ReportController.cs | 68 +++++++++ 9 files changed, 274 insertions(+), 7 deletions(-) create mode 100644 OpenImis.ModulesV2/ReportModule/Models/CumulativeIndicatorsResponseModel.cs create mode 100644 OpenImis.ModulesV2/ReportModule/Models/IndicatorRequestModel.cs create mode 100644 OpenImis.ModulesV2/ReportModule/Models/SnapshotRequestModel.cs create mode 100644 OpenImis.ModulesV2/ReportModule/Models/SnapshotResponseModel.cs diff --git a/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs b/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs index b896e3e2..1959cad5 100644 --- a/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs +++ b/OpenImis.ModulesV2/ReportModule/Logic/IReportLogic.cs @@ -8,5 +8,7 @@ public interface IReportLogic FeedbackReportModel GetFeedbackStats(ReportRequestModel feedbackRequestModel, string officerCode); RenewalReportModel GetRenewalStats(ReportRequestModel renewalRequestModel, string officerCode); EnrolmentReportModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel, string officerCode); + SnapshotResponseModel GetSnapshotIndicators(SnapshotRequestModel snapshotRequestModel, string officerCode); + CumulativeIndicatorsResponseModel GetCumulativeIndicators(IndicatorRequestModel cumulativeIndicatorsRequestModel, string officerCode); } } diff --git a/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs b/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs index 4fca7762..6a1abd09 100644 --- a/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs +++ b/OpenImis.ModulesV2/ReportModule/Logic/ReportLogic.cs @@ -42,5 +42,23 @@ public EnrolmentReportModel GetEnrolmentStats(ReportRequestModel enrolmentReques return response; } + + public SnapshotResponseModel GetSnapshotIndicators(SnapshotRequestModel snapshotRequestModel, string officerCode) + { + SnapshotResponseModel response; + + response = reportRepository.GetSnapshotIndicators(snapshotRequestModel, officerCode); + + return response; + } + + public CumulativeIndicatorsResponseModel GetCumulativeIndicators(IndicatorRequestModel cumulativeIndicatorsRequestModel, string officerCode) + { + CumulativeIndicatorsResponseModel response; + + response = reportRepository.GetCumulativeIndicators(cumulativeIndicatorsRequestModel, officerCode); + + return response; + } } } diff --git a/OpenImis.ModulesV2/ReportModule/Models/CumulativeIndicatorsResponseModel.cs b/OpenImis.ModulesV2/ReportModule/Models/CumulativeIndicatorsResponseModel.cs new file mode 100644 index 00000000..3904a7c4 --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/Models/CumulativeIndicatorsResponseModel.cs @@ -0,0 +1,13 @@ +using System; + +namespace OpenImis.ModulesV2.ReportModule.Models +{ + public class CumulativeIndicatorsResponseModel + { + public int NewPolicies { get; set; } + public int RenewedPolicies { get; set; } + public int ExpiredPolicies { get; set; } + public int SuspendedPolicies { get; set; } + public double CollectedContribution { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ReportModule/Models/IndicatorRequestModel.cs b/OpenImis.ModulesV2/ReportModule/Models/IndicatorRequestModel.cs new file mode 100644 index 00000000..0af8b3c1 --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/Models/IndicatorRequestModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.ReportModule.Models +{ + public class IndicatorRequestModel + { + public string FromDate { get; set; } + public string ToDate { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ReportModule/Models/SnapshotRequestModel.cs b/OpenImis.ModulesV2/ReportModule/Models/SnapshotRequestModel.cs new file mode 100644 index 00000000..df069099 --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/Models/SnapshotRequestModel.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.ReportModule.Models +{ + public class SnapshotRequestModel + { + public string SnapshotDate { get; set; } + } +} diff --git a/OpenImis.ModulesV2/ReportModule/Models/SnapshotResponseModel.cs b/OpenImis.ModulesV2/ReportModule/Models/SnapshotResponseModel.cs new file mode 100644 index 00000000..675a0327 --- /dev/null +++ b/OpenImis.ModulesV2/ReportModule/Models/SnapshotResponseModel.cs @@ -0,0 +1,13 @@ +using System; + +namespace OpenImis.ModulesV2.ReportModule.Models +{ + public class SnapshotResponseModel + { + public int Active { get; set; } + public int Expired { get; set; } + public int Idle { get; set; } + public int Suspended { get; set; } + + } +} diff --git a/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs b/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs index b2d6ce6f..47981278 100644 --- a/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs +++ b/OpenImis.ModulesV2/ReportModule/Repositories/IReportRepository.cs @@ -1,5 +1,4 @@ using OpenImis.ModulesV2.ReportModule.Models; -using System; namespace OpenImis.ModulesV2.ReportModule.Repositories { @@ -8,5 +7,7 @@ public interface IReportRepository FeedbackReportModel GetFeedbackStats(ReportRequestModel feedbackRequestModel, string officerCode); RenewalReportModel GetRenewalStats(ReportRequestModel renewalRequestModel, string officerCode); EnrolmentReportModel GetEnrolmentStats(ReportRequestModel enrolmentRequestModel, string officerCode); + SnapshotResponseModel GetSnapshotIndicators(SnapshotRequestModel snapshotRequestModel, string officerCode); + CumulativeIndicatorsResponseModel GetCumulativeIndicators(IndicatorRequestModel cumulativeIndicatorsRequestModel, string officerCode); } } diff --git a/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs b/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs index 3ef2bfde..0f1416bb 100644 --- a/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs +++ b/OpenImis.ModulesV2/ReportModule/Repositories/ReportRepository.cs @@ -1,8 +1,11 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using OpenImis.DB.SqlServer; using OpenImis.ModulesV2.ReportModule.Models; using System; using System.Collections.Generic; +using System.Data; +using System.Data.Common; using System.Data.SqlClient; using System.Diagnostics; using System.Linq; @@ -118,11 +121,6 @@ public RenewalReportModel GetRenewalStats(ReportRequestModel renewalRequestModel select FP) .ToList(); - foreach (var item in renewalSent) - { - Debug.WriteLine(item.FromPhoneId); - } - var renewalAccepted = renewalSent .Where(f => f.DocStatus == "A") .Count(); @@ -145,5 +143,136 @@ public RenewalReportModel GetRenewalStats(ReportRequestModel renewalRequestModel throw e; } } + + public SnapshotResponseModel GetSnapshotIndicators(SnapshotRequestModel snapshotRequestModel, string officerCode) + { + SnapshotResponseModel response = new SnapshotResponseModel(); + + int officerId; + + using (var imisContext = new ImisDB()) + { + officerId = (from O in imisContext.TblOfficer + where O.Code == officerCode + && O.ValidityTo == null + select O.OfficerId) + .FirstOrDefault(); + } + + try + { + using (var imisContext = new ImisDB()) + { + var snapshotDateParameter = new SqlParameter("@SnapshotDate", snapshotRequestModel.SnapshotDate) { SqlDbType = SqlDbType.NVarChar, Size = 50 }; + var officerIdParameter = new SqlParameter("@OfficerId", officerId); + + var sql = "SELECT Active, Expired, Idle, Suspended FROM udfGetSnapshotIndicators(@SnapshotDate,@OfficerId)"; + + DbConnection connection = imisContext.Database.GetDbConnection(); + + using (DbCommand cmd = connection.CreateCommand()) + { + cmd.CommandText = sql; + + cmd.Parameters.AddRange(new[] { snapshotDateParameter, officerIdParameter }); + + if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); + + using (var reader = cmd.ExecuteReader()) + { + do + { + while (reader.Read()) + { + response.Active = int.Parse(reader["Active"].ToString()); + response.Expired = int.Parse(reader["Expired"].ToString()); + response.Idle = int.Parse(reader["Idle"].ToString()); + response.Suspended = int.Parse(reader["Suspended"].ToString()); + } + } while (reader.NextResult()); + } + } + } + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + + public CumulativeIndicatorsResponseModel GetCumulativeIndicators(IndicatorRequestModel cumulativeIndicatorsRequestModel, string officerCode) + { + CumulativeIndicatorsResponseModel response = new CumulativeIndicatorsResponseModel(); + + int officerId; + + using (var imisContext = new ImisDB()) + { + officerId = (from O in imisContext.TblOfficer + where O.Code == officerCode + && O.ValidityTo == null + select O.OfficerId) + .FirstOrDefault(); + } + + try + { + using (var imisContext = new ImisDB()) + { + var dateFromParameter = new SqlParameter("@DateFrom", cumulativeIndicatorsRequestModel.FromDate) { SqlDbType = SqlDbType.NVarChar, Size = 50 }; + var dateToParameter = new SqlParameter("@DateTo", cumulativeIndicatorsRequestModel.ToDate) { SqlDbType = SqlDbType.NVarChar, Size = 50 }; + var officerIdParameter = new SqlParameter("@OfficerId", officerId); + + var sql = "SELECT " + + " ISNULL(dbo.udfNewPoliciesPhoneStatistics(@DateFrom,@DateTo,@OfficerId),0) NewPolicies," + + " ISNULL(dbo.udfRenewedPoliciesPhoneStatistics(@DateFrom,@DateTo,@OfficerId),0) RenewedPolicies, " + + " ISNULL(dbo.udfExpiredPoliciesPhoneStatistics(@DateFrom,@DateTo,@OfficerId),0) ExpiredPolicies, " + + " ISNULL(dbo.udfSuspendedPoliciesPhoneStatistics(@DateFrom,@DateTo,@OfficerId),0) SuspendedPolicies," + + " ISNULL(dbo.udfCollectedContribution(@DateFrom,@DateTo,@OfficerId),0) CollectedContribution "; + + DbConnection connection = imisContext.Database.GetDbConnection(); + + using (DbCommand cmd = connection.CreateCommand()) + { + cmd.CommandText = sql; + + cmd.Parameters.AddRange(new[] { dateFromParameter, dateToParameter, officerIdParameter }); + + if (connection.State.Equals(ConnectionState.Closed)) connection.Open(); + + using (var reader = cmd.ExecuteReader()) + { + do + { + while (reader.Read()) + { + response.NewPolicies = int.Parse(reader["NewPolicies"].ToString()); + response.RenewedPolicies = int.Parse(reader["RenewedPolicies"].ToString()); + response.ExpiredPolicies = int.Parse(reader["ExpiredPolicies"].ToString()); + response.SuspendedPolicies = int.Parse(reader["SuspendedPolicies"].ToString()); + response.CollectedContribution = Math.Round(double.Parse(reader["CollectedContribution"].ToString()), 2); + } + } while (reader.NextResult()); + } + } + } + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } } } \ No newline at end of file diff --git a/OpenImis.RestApi/Controllers/V2/ReportController.cs b/OpenImis.RestApi/Controllers/V2/ReportController.cs index cc02e3b5..a31da450 100644 --- a/OpenImis.RestApi/Controllers/V2/ReportController.cs +++ b/OpenImis.RestApi/Controllers/V2/ReportController.cs @@ -124,5 +124,73 @@ public IActionResult GetRenewalStats([FromBody]ReportRequestModel renewalRequest return Ok(renewalModel); } + + [HasRights(Rights.ReportsPrimaryOperationalIndicatorPolicies)] + [HttpPost] + [Route("indicators/snapshot")] + public IActionResult GetSnapshotIndicators([FromBody]SnapshotRequestModel snapshotRequestModel) + { + if (!ModelState.IsValid) + { + return BadRequest(); + } + + SnapshotResponseModel snapshotResponseModel; + + try + { + Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); + + Repository rep = new Repository(); + string officerCode = rep.GetLoginNameByUserUUID(userUUID); + + snapshotResponseModel = _imisModules.GetReportModule().GetReportLogic().GetSnapshotIndicators(snapshotRequestModel, officerCode); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + if (snapshotResponseModel == null) + { + return NotFound(); + } + + return Ok(snapshotResponseModel); + } + + [HasRights(Rights.ReportsPrimaryOperationalIndicatorPolicies)] + [HttpPost] + [Route("indicators/cumulative")] + public IActionResult GetCumulativeIndicators([FromBody]IndicatorRequestModel cumulativeRequestModel) + { + if (!ModelState.IsValid) + { + return BadRequest(); + } + + CumulativeIndicatorsResponseModel cumulativeIndicatorsResponseModel; + + try + { + Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); + + Repository rep = new Repository(); + string officerCode = rep.GetLoginNameByUserUUID(userUUID); + + cumulativeIndicatorsResponseModel = _imisModules.GetReportModule().GetReportLogic().GetCumulativeIndicators(cumulativeRequestModel, officerCode); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + if (cumulativeIndicatorsResponseModel == null) + { + return NotFound(); + } + + return Ok(cumulativeIndicatorsResponseModel); + } } } \ No newline at end of file From 50ce1edc7413d8e3e3289fe3abff4a1f546ae8c2 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Sat, 19 Oct 2019 16:02:45 +0200 Subject: [PATCH 75/86] OS-69: Added endpoint in Premium Module --- OpenImis.ModulesV2/IImisModules.cs | 3 + .../PremiumModule/Logic/IPremiumLogic.cs | 4 +- .../PremiumModule/Logic/PremiumLogic.cs | 15 ++++ .../Models/ReceiptRequestModel.cs | 12 +++ .../Repositories/IPremiumRepository.cs | 9 +++ .../Repositories/PremiumRepository.cs | 76 +++++++++++++++++++ .../Controllers/V2/PremiumController.cs | 46 +++++++++++ 7 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 OpenImis.ModulesV2/PremiumModule/Models/ReceiptRequestModel.cs create mode 100644 OpenImis.ModulesV2/PremiumModule/Repositories/IPremiumRepository.cs create mode 100644 OpenImis.ModulesV2/PremiumModule/Repositories/PremiumRepository.cs create mode 100644 OpenImis.RestApi/Controllers/V2/PremiumController.cs diff --git a/OpenImis.ModulesV2/IImisModules.cs b/OpenImis.ModulesV2/IImisModules.cs index cdeb9c1a..cd027113 100644 --- a/OpenImis.ModulesV2/IImisModules.cs +++ b/OpenImis.ModulesV2/IImisModules.cs @@ -8,6 +8,7 @@ using OpenImis.ModulesV2.FeedbackModule; using OpenImis.ModulesV2.PolicyModule; using OpenImis.ModulesV2.ReportModule; +using OpenImis.ModulesV2.PremiumModule; namespace OpenImis.ModulesV2 { @@ -35,5 +36,7 @@ public interface IImisModules IPolicyModule GetPolicyModule(); IReportModule GetReportModule(); + + IPremiumModule GetPremiumModule(); } } diff --git a/OpenImis.ModulesV2/PremiumModule/Logic/IPremiumLogic.cs b/OpenImis.ModulesV2/PremiumModule/Logic/IPremiumLogic.cs index 4d57dd43..9f16461c 100644 --- a/OpenImis.ModulesV2/PremiumModule/Logic/IPremiumLogic.cs +++ b/OpenImis.ModulesV2/PremiumModule/Logic/IPremiumLogic.cs @@ -1,8 +1,10 @@ -using System; +using OpenImis.ModulesV2.PremiumModule.Models; +using System; namespace OpenImis.ModulesV2.PremiumModule.Logic { public interface IPremiumLogic { + bool Get(ReceiptRequestModel receipt); } } diff --git a/OpenImis.ModulesV2/PremiumModule/Logic/PremiumLogic.cs b/OpenImis.ModulesV2/PremiumModule/Logic/PremiumLogic.cs index 4b36a09d..d94bd67e 100644 --- a/OpenImis.ModulesV2/PremiumModule/Logic/PremiumLogic.cs +++ b/OpenImis.ModulesV2/PremiumModule/Logic/PremiumLogic.cs @@ -1,4 +1,6 @@ using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.PremiumModule.Models; +using OpenImis.ModulesV2.PremiumModule.Repositories; namespace OpenImis.ModulesV2.PremiumModule.Logic { @@ -6,9 +8,22 @@ public class PremiumLogic : IPremiumLogic { private IConfiguration _configuration; + protected IPremiumRepository premiumRepository; + public PremiumLogic(IConfiguration configuration) { _configuration = configuration; + + premiumRepository = new PremiumRepository(_configuration); + } + + public bool Get(ReceiptRequestModel receipt) + { + bool response; + + response = premiumRepository.Get(receipt); + + return response; } } } diff --git a/OpenImis.ModulesV2/PremiumModule/Models/ReceiptRequestModel.cs b/OpenImis.ModulesV2/PremiumModule/Models/ReceiptRequestModel.cs new file mode 100644 index 00000000..7f621cc4 --- /dev/null +++ b/OpenImis.ModulesV2/PremiumModule/Models/ReceiptRequestModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.PremiumModule.Models +{ + public class ReceiptRequestModel + { + public string ReceiptNo { get; set; } + public string CHFID { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PremiumModule/Repositories/IPremiumRepository.cs b/OpenImis.ModulesV2/PremiumModule/Repositories/IPremiumRepository.cs new file mode 100644 index 00000000..5d80cf4e --- /dev/null +++ b/OpenImis.ModulesV2/PremiumModule/Repositories/IPremiumRepository.cs @@ -0,0 +1,9 @@ +using OpenImis.ModulesV2.PremiumModule.Models; + +namespace OpenImis.ModulesV2.PremiumModule.Repositories +{ + public interface IPremiumRepository + { + bool Get(ReceiptRequestModel receipt); + } +} diff --git a/OpenImis.ModulesV2/PremiumModule/Repositories/PremiumRepository.cs b/OpenImis.ModulesV2/PremiumModule/Repositories/PremiumRepository.cs new file mode 100644 index 00000000..1331b2ad --- /dev/null +++ b/OpenImis.ModulesV2/PremiumModule/Repositories/PremiumRepository.cs @@ -0,0 +1,76 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.DB.SqlServer; +using OpenImis.ModulesV2.PremiumModule.Models; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Diagnostics; +using System.Linq; +using System.Text; + +namespace OpenImis.ModulesV2.PremiumModule.Repositories +{ + public class PremiumRepository : IPremiumRepository + { + private IConfiguration _configuration; + + public PremiumRepository(IConfiguration configuration) + { + _configuration = configuration; + } + + public bool Get(ReceiptRequestModel receipt) + { + bool response = false; + + try + { + using (var imisContext = new ImisDB()) + { + var districtId = (from F in imisContext.TblFamilies + join I in imisContext.TblInsuree on F.InsureeId equals I.InsureeId + join V in imisContext.TblVillages on F.LocationId equals V.VillageId + join W in imisContext.TblWards on V.WardId equals W.WardId + join D in imisContext.TblDistricts on W.DistrictId equals D.DistrictId + where (F.ValidityTo == null + && I.ValidityTo == null + && I.Chfid == receipt.CHFID) + select D.DistrictId) + .FirstOrDefault(); + + int? premiumId = (from PR in imisContext.TblPremium + join PL in imisContext.TblPolicy on PR.PolicyId equals PL.PolicyId + join F in imisContext.TblFamilies on PL.FamilyId equals F.FamilyId + join I in imisContext.TblInsuree on F.InsureeId equals I.InsureeId + join V in imisContext.TblVillages on F.LocationId equals V.VillageId + join W in imisContext.TblWards on V.WardId equals W.WardId + join D in imisContext.TblDistricts on W.DistrictId equals D.DistrictId + where (PR.ValidityTo == null + && PL.ValidityTo == null + && F.ValidityTo == null + && I.ValidityTo == null + && D.ValidityTo == null + && PR.Receipt == receipt.ReceiptNo + && D.DistrictId == districtId) + select PR.PremiumId) + .FirstOrDefault(); + + if (premiumId == 0) + { + response = true; + } + } + + return response; + } + catch (SqlException e) + { + throw e; + } + catch (Exception e) + { + throw e; + } + } + } +} diff --git a/OpenImis.RestApi/Controllers/V2/PremiumController.cs b/OpenImis.RestApi/Controllers/V2/PremiumController.cs new file mode 100644 index 00000000..b19debaf --- /dev/null +++ b/OpenImis.RestApi/Controllers/V2/PremiumController.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using OpenImis.ModulesV2; +using OpenImis.ModulesV2.PremiumModule.Models; +using OpenImis.RestApi.Security; + +namespace OpenImis.RestApi.Controllers.V2 +{ + [ApiVersion("2")] + [Authorize] + [Route("api/premium/")] + [ApiController] + public class PremiumController : Controller + { + private readonly IImisModules _imisModules; + + public PremiumController(IImisModules imisModules) + { + _imisModules = imisModules; + } + + [HasRights(Rights.PolicySearch)] + [Route("receipt/")] + [HttpPost] + public IActionResult Get([FromBody]ReceiptRequestModel receipt) + { + bool response; + + try + { + response = _imisModules.GetPremiumModule().GetPremiumLogic().Get(receipt); + } + catch (ValidationException e) + { + return BadRequest(new { error = new { message = e.Message, value = e.Value } }); + } + + return Ok(response); + } + } +} \ No newline at end of file From 418638bd558e4ac16ad6cafc4cd2f55a7271936b Mon Sep 17 00:00:00 2001 From: bkaminski Date: Sat, 19 Oct 2019 16:26:19 +0200 Subject: [PATCH 76/86] OS-70: Added ID for Family and Insuree --- OpenImis.ModulesV2/InsureeModule/Models/FamilyModel.cs | 4 ++++ OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs | 2 ++ OpenImis.RestApi/Controllers/V2/FamilyController.cs | 1 + 3 files changed, 7 insertions(+) diff --git a/OpenImis.ModulesV2/InsureeModule/Models/FamilyModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/FamilyModel.cs index 85cd9fcd..847c007f 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/FamilyModel.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/FamilyModel.cs @@ -8,8 +8,10 @@ namespace OpenImis.ModulesV2.InsureeModule.Models { public class FamilyModel { + public int FamilyId { get; set; } public Guid FamilyUUID { get; set; } public IEnumerable Insurees { get; set; } + public int InsureeId { get; set; } public Guid InsureeUUID { get; set; } public int LocationId { get; set; } public bool Poverty { get; set; } @@ -24,7 +26,9 @@ public static FamilyModel FromTblFamilies(TblFamilies tblFamilies) { FamilyModel familyModel = new FamilyModel() { + FamilyId = tblFamilies.FamilyId, FamilyUUID = tblFamilies.FamilyUUID, + InsureeId = tblFamilies.InsureeId, InsureeUUID = tblFamilies.Insuree.InsureeUUID, LocationId = TypeCast.GetValue(tblFamilies.LocationId), Poverty = TypeCast.GetValue(tblFamilies.Poverty), diff --git a/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs index 3f14d3c7..11c76605 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs @@ -9,6 +9,7 @@ namespace OpenImis.ModulesV2.InsureeModule.Models { public class InsureeModel { + public int InsureeId { get; set; } public Guid InsureeUUID { get; set; } public string IdentificationNumber { get; set; } public string CHFID { get; set; } @@ -42,6 +43,7 @@ public static InsureeModel FromTblInsuree(TblInsuree tblInsuree) InsureeModel insuree = new InsureeModel() { + InsureeId = tblInsuree.InsureeId, InsureeUUID = tblInsuree.InsureeUUID, IdentificationNumber = tblInsuree.Passport, CHFID = tblInsuree.Chfid, diff --git a/OpenImis.RestApi/Controllers/V2/FamilyController.cs b/OpenImis.RestApi/Controllers/V2/FamilyController.cs index d1c83455..84ab9d64 100644 --- a/OpenImis.RestApi/Controllers/V2/FamilyController.cs +++ b/OpenImis.RestApi/Controllers/V2/FamilyController.cs @@ -24,6 +24,7 @@ public FamilyController(IImisModules imisModules) _imisModules = imisModules; } + // TODO Remove from Model ID for Family and Insuree after changes in SP [HasRights(Rights.FamilySearch)] [HttpGet] [Route("{chfid}")] From 8865582fbfc226c91bf5cda59ecb0131040ee314 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Wed, 23 Oct 2019 14:30:02 +0200 Subject: [PATCH 77/86] OS-41: Added Commission and changes in Family --- .../Helpers/GetCommissionResponse.cs | 49 ++++++++ OpenImis.ModulesV2/Helpers/ImisApiResponse.cs | 49 ++++++++ .../Helpers/Messages/Language.cs | 30 +++++ .../Helpers/Messages/PrimaryLanguage.cs | 107 ++++++++++++++++++ .../Helpers/Messages/SecondaryLanguage.cs | 88 ++++++++++++++ .../Models/EnrollFamilyModels/Family.cs | 6 +- .../Models/EnrollFamilyModels/Insuree.cs | 24 ++-- .../EnrollFamilyModels/InsureePolicy.cs | 2 +- .../Models/EnrollFamilyModels/Policy.cs | 16 +-- .../Models/EnrollFamilyModels/Premium.cs | 8 +- .../MasterDataModule/Models/OfficerModel.cs | 1 + .../Repositories/MasterDataRepository.cs | 1 + .../PolicyModule/Logic/IPolicyRenewalLogic.cs | 1 + .../PolicyModule/Logic/PolicyRenewalLogic.cs | 9 ++ .../PolicyModule/Models/CommissionMode.cs | 10 ++ .../PolicyModule/Models/DataMessage.cs | 12 ++ .../Models/GetCommissionInputs.cs | 17 +++ .../Repositories/IPolicyRenewalRepository.cs | 1 + .../Repositories/PolicyRenewalRepository.cs | 58 ++++++++++ .../Controllers/V2/FamilyController.cs | 6 + .../Controllers/V2/PolicyRenewalController.cs | 16 +++ 21 files changed, 483 insertions(+), 28 deletions(-) create mode 100644 OpenImis.ModulesV2/Helpers/GetCommissionResponse.cs create mode 100644 OpenImis.ModulesV2/Helpers/ImisApiResponse.cs create mode 100644 OpenImis.ModulesV2/Helpers/Messages/Language.cs create mode 100644 OpenImis.ModulesV2/Helpers/Messages/PrimaryLanguage.cs create mode 100644 OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguage.cs create mode 100644 OpenImis.ModulesV2/PolicyModule/Models/CommissionMode.cs create mode 100644 OpenImis.ModulesV2/PolicyModule/Models/DataMessage.cs create mode 100644 OpenImis.ModulesV2/PolicyModule/Models/GetCommissionInputs.cs diff --git a/OpenImis.ModulesV2/Helpers/GetCommissionResponse.cs b/OpenImis.ModulesV2/Helpers/GetCommissionResponse.cs new file mode 100644 index 00000000..c68ed131 --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/GetCommissionResponse.cs @@ -0,0 +1,49 @@ +using OpenImis.ModulesV2.Helpers.Messages; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.Helpers +{ + public class GetCommissionResponse : ImisApiResponse + { + public GetCommissionResponse(Exception error) : base(error) + { + + } + public GetCommissionResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + + public GetCommissionResponse(int value, bool error, object data, int lang) : base(value, error, data, lang) + { + msg.Data = data; + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongOrMissingHeadIN"); + Message = msg; + break; + case 2: + + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "HeadINNotFound"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.ModulesV2/Helpers/ImisApiResponse.cs b/OpenImis.ModulesV2/Helpers/ImisApiResponse.cs new file mode 100644 index 00000000..8fc83643 --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/ImisApiResponse.cs @@ -0,0 +1,49 @@ +using Newtonsoft.Json; +using OpenImis.ModulesV2.PolicyModule.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.Helpers +{ + public class ImisApiResponse + { + public DataMessage msg = new DataMessage(); + public int language { get; set; } + + public ImisApiResponse(Exception e) + { + msg.Code = -1; + msg.ErrorOccured = true; + msg.MessageValue = e.Message; + Message = msg; + } + + public ImisApiResponse(int value, bool error, int lang) + { + if (value != 0) + error = true; + + language = lang; + + msg.Code = value; + msg.ErrorOccured = error; + Message = msg; + } + + public ImisApiResponse(int value, bool error, object data, int lang) + { + if (value != 0) + error = true; + + language = lang; + + msg.Code = value; + msg.ErrorOccured = error; + msg.Data = JsonConvert.SerializeObject(data); + Message = msg; + } + + public DataMessage Message { get; set; } + } +} diff --git a/OpenImis.ModulesV2/Helpers/Messages/Language.cs b/OpenImis.ModulesV2/Helpers/Messages/Language.cs new file mode 100644 index 00000000..4f7a83b9 --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/Messages/Language.cs @@ -0,0 +1,30 @@ +using System.Reflection; + +namespace OpenImis.ModulesV2.Helpers.Messages +{ + public class Language + { + public string GetMessage(int language, string name) + { + FieldInfo fieldInfos; + + switch (language) + { + + case 0: + fieldInfos = typeof(PrimaryLanguage).GetField(name); + break; + case 1: + fieldInfos = typeof(SecondaryLanguage).GetField(name); + + break; + default: + fieldInfos = typeof(PrimaryLanguage).GetField(name); + + break; + } + var val = (string)fieldInfos.GetValue(null); + return val; + } + } +} diff --git a/OpenImis.ModulesV2/Helpers/Messages/PrimaryLanguage.cs b/OpenImis.ModulesV2/Helpers/Messages/PrimaryLanguage.cs new file mode 100644 index 00000000..311d6528 --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/Messages/PrimaryLanguage.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.Helpers.Messages +{ + public static class PrimaryLanguage + { + public static string Success = "Success"; + + //CtrlNumberResponse + public static string CantAssignCN = "1-Control number cannot be assigned by the external payment gateway"; + public static string DuplicateCN = "2-Duplicate Control Number"; + + //DeleteMemberFamilyResponse + public static string WrongFormatMissingIN = "Wrong Format or Missing Insurance Number of Member"; + public static string INNotFount = "Insurance number of member not found"; + public static string MemberNotHead = "Mamber is head of family"; + + //EditFamilyResponse + public static string WrongOrMissingHeadIN = "Wrong Format or Missing Insurance Number of head."; + public static string HeadINNotFound = "Insurance Number of head not found."; + public static string WrongPVillageCode = "Wrong permanent village code."; + public static string WrongCVillageCode = "Wrong current village Code."; + public static string WrongGender = "Wrong gender."; + public static string WrongConfirmationType = "Wrong confirmation type"; + public static string WrongGroupType = "Wrong group type"; + public static string WrongMaritalStatus = "Wrong marital status"; + public static string WrongEducation = "Wrong education"; + public static string WrongProfession = "Wrong profession."; + public static string FSPCodeNotFound = "FSP code not found"; + public static string WrongIdentificationType = "Wrong Identification Type"; + + //EditMemberFamilyResponse + public static string WrongINMember = "Wrong format of insurance number of member"; + public static string NotFountINMember = "Insurance number of member not found"; + public static string WrongVillageCode = "Wrong current village code"; + public static string WrongRelationship = "Wrong Relationship"; + + //EnterContributionResponse + public static string WrongOrMissingPC = "Wrong or missing product code (not existing or not applicable to the family/group)"; + public static string WrongOrMissingPayDate = "Wrong or missing payment date"; + public static string WrongContributionCat = "Wrong contribution category"; + public static string WrongOrMissingPayType = "Wrong or missing payment type"; + public static string WrongOrMissingPayer = "Wrong or missing payer"; + public static string MissingReceiptNumber = "Missing receipt no."; + public static string DuplicateReceiptNumber = "Duplicated receipt no."; + + //EnterFamilyResponse + public static string DuplicateINHead = "Duplicated Insurance Number of head."; + public static string WrongOrMissingPVC = "Wrong or missing permanent village code."; + public static string WrongOrMissingGender = "Wrong or missing gender."; + public static string WrongFrOrMissingBd = "Wrong format or missing birth date."; + public static string MissingLastName = "Missing last name."; + public static string MissingOtherName = "Missing other name"; + + //EnterMemberFamilyResponse + public static string DuplicatedMemberIN = "Insurance number of member duplicated "; + + //EnterPolicyResponse + public static string WrongOrMissingEnrolDate = "Wrong or missing enrolment date"; + public static string WrongOrMissingEOcode = "Wrong or missing enrolment officer code (not existing or not applicable to the family/group)"; + + //GetCoverageResponse + + //GetFamilyResponse + + //GetMemberFamilyResponse + public static string NoMemberOfOrder = "No member of the specified order number in the family/group"; + + //MatchPayResponse + public static string PayIdDoesntExist = "1-The paymentId does not exist"; + + //RenewPolicyResponse + public static string WrongOrMissingRenDate = "Wrong or missing renewal date"; + + //RequestedCNResponse + public static string WrongInternalIdFormat = "1-Wrong format of internal identifier"; + public static string InvalidInternalId = "2-Not valid internal identifier "; + + //SaveAckResponse + public static string CantPostReq = "1-Request for control number cannot be posted in the external payment gateway"; + + //SaveIntentResponse + public static string WrongFormatInsureeNo = "1-Wrong format of insurance number"; + public static string InValidINmissingPC = "2-Not valid insurance or missing product code"; + public static string InValidEOC = "3-Not valid enrolment officer code"; + public static string IncompatibleEO_PC = "4-Enrolment officer code and insurance product code are not compatible"; + public static string NoRenewalProduct = "5-Beneficiary has no policy of specified insurance product for renewal"; + public static string InsureeNoMissing = "6-Missing insurance number"; + public static string InsureeNotEnrolled = "7-Insuree not enrolled while prior enrolment mandatory."; + public static string DuplicateCNAssigned = "8-Duplicated control number assigned"; + public static string CantAssignCn2 = "9-Control number cannot be assigned"; + public static string UnknownPaymentType = "10-Uknown type of payment"; + + //SavePayResponse + public static string WrongOrMissingRecDate = "1-Wrong or missing receiving date"; + public static string WrongFormatInputData = "2-Wrong format of input data"; + public static string WrongControlNumber = "3-Wrong control_number"; + public static string WrongAmount = "4-Wrong Amount"; + public static string DuplicatePayAmount = "5-Duplicate Payment Amount"; + public static string DoesntExistEO = "6-Enrolment Officer Code does not exist"; + public static string DoesntExistPC = "7-Product Code Does not Exist"; + public static string NoPolicyForRenewal = "8-Beneficiary has no policy of specified insurance product for renewal"; + public static string UnknownTypeOfPay = "9-Uknown type of payment"; + } +} diff --git a/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguage.cs b/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguage.cs new file mode 100644 index 00000000..e535aa11 --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguage.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.Helpers.Messages +{ + public static class SecondaryLanguage + { + public static string Success = "Imefanikiwa"; + + public static string CantAssignCN = "1-Na. ya ankara imeshindikana kutotelewa na mfumo wa malipo"; + public static string DuplicateCN = "2-Na. ya ankara imejirudia"; + + public static string WrongFormatMissingIN = "Umekosea namba ya mwanachama au namba haipo"; + public static string INNotFount = "Namba ya mwanachama haipo"; + public static string MemberNotHead = "Mwanachama ni mkuu wa kaya"; + + public static string WrongOrMissingHeadIN = "Umekosea namba ya mkuu wa kaya au namba haipo"; + public static string HeadINNotFound = "Namba ya mkuu wa kaya haipo"; + public static string WrongPVillageCode = "Umekosea namba ya kijiji"; + public static string WrongCVillageCode = "Umekosea namba ya kijiji"; + public static string WrongGender = "Umekosea jinsia"; + public static string WrongConfirmationType = "Wrong confirmation type"; + public static string WrongGroupType = "Umekosea aina ya kundi"; + public static string WrongMaritalStatus = "Umekosea hali ya ndoa"; + public static string WrongEducation = "Umekosea elimu"; + public static string WrongProfession = "Umekosea elimu"; + public static string FSPCodeNotFound = "Na. ya FSP haipo"; + public static string WrongIdentificationType = "Umekosea aina ya kitambulisho"; + + public static string WrongINMember = "Umekosea namba ya mwanachama"; + public static string NotFountINMember = "Namba ya mwanachama haipo kwenye kompuyta kuu"; + public static string WrongVillageCode = "Umekosea namba ya kijiji"; + public static string WrongRelationship = "Umekosea uhusiano"; + + public static string WrongOrMissingPC = "Umekosea namba ya bidhaa au haitumiki kwenye familia husika"; + public static string WrongOrMissingPayDate = "Umekosea tarehe ya malipo"; + public static string WrongContributionCat = "Umekosea kundi la malipo"; + public static string WrongOrMissingPayType = "Umekosea aina ya malipo"; + public static string WrongOrMissingPayer = "Umekosea mlipaji"; + public static string MissingReceiptNumber = "Jaza namba ya risiti"; + public static string DuplicateReceiptNumber = "Namba ya risiti imejirudia"; + + public static string DuplicateINHead = "Namba ya mwachama imejirudia"; + public static string WrongOrMissingPVC = "Umekosea/Jaza namba ya kijiji"; + public static string WrongOrMissingGender = "Umekosea/Jaza Jinsia"; + public static string WrongFrOrMissingBd = "Jaza/Umekosea tarehe"; + public static string MissingLastName = "Jaza jina la ukoo"; + public static string MissingOtherName = "Jaza majina mengine"; + + public static string DuplicatedMemberIN = "Namba ya mwanachama imejirudia"; + + public static string WrongOrMissingEnrolDate = "Jaza/Umekosea tarehe ya kujiunga"; + public static string WrongOrMissingEOcode = "Jaza/Umekosea namba ya msimbo ya afisa mwandikishaji"; + + public static string NoMemberOfOrder = "Na ya mwanchama kwenye familia haipo"; + public static string PayIdDoesntExist = "1-Namba ya malipo haipo"; + + public static string WrongOrMissingRenDate = "Jaza/Umekosea tarehe ya kuhuisha"; + + public static string WrongInternalIdFormat = "1-Wrong format of internal identifier"; + public static string InvalidInternalId = "2-Not valid internal identifier "; + + public static string CantPostReq = "1-Maombi ya Na. ya ankara yameshindikana, jaribu tena"; + + public static string WrongFormatInsureeNo = "1-Namba ya mwanachama imekosewa"; + public static string InValidINmissingPC = "2-Umekosea namba ya mwanachama au namba ya bidhaa"; + public static string InValidEOC = "3-Umekosea namba ya msimbo ya afisa mwandikishaji"; + public static string IncompatibleEO_PC = "4-Namba ya mwanachama na namba ya bidhaa haviendani"; + public static string NoRenewalProduct = "5-Mwanachama hajajiunga na bidhaa husika"; + + public static string InsureeNoMissing = "6-Jaza namba ya mwanachama"; + public static string InsureeNotEnrolled = "7-Insuree not enrolled while prior enrolment mandatory."; + public static string DuplicateCNAssigned = "8-Umepatiwa namba ya ankara iliyojirudia, jaribu tena"; + public static string CantAssignCn2 = "9-Na. ya ankara imeshishindikana kutolewa, jaribu tena"; + public static string UnknownPaymentType = "10-Aina ya malipo uliyochagua hayapo"; + + public static string WrongOrMissingRecDate = "1-Umekosea tarehe ya kupokea"; + public static string WrongFormatInputData = "2-Umekosea taarifa uliyojaza"; + public static string WrongControlNumber = "3-Umekosea Na. ya ankara"; + public static string WrongAmount = "4-Umekosea kiasi"; + public static string DuplicatePayAmount = "5-Umerudia malipo"; + public static string DoesntExistEO = "6-Namba ya msimbo ya afisa mwandikishaji haipo"; + public static string DoesntExistPC = "7-Namba ya bidhaa haipo"; + public static string NoPolicyForRenewal = "8-Mwanachama hajajiunga na bidhaa husika"; + public static string UnknownTypeOfPay = "9-Aina ya malipo uliyochagua haipo"; + } +} diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Family.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Family.cs index a6ce5c21..d745adc8 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Family.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Family.cs @@ -10,13 +10,13 @@ public class Family public int InsureeId { get; set; } public int LocationId { get; set; } public string HOFCHFID { get; set; } - public bool Poverty { get; set; } - public bool FamilyType { get; set; } + public string Poverty { get; set; } + public string FamilyType { get; set; } public string FamilyAddress { get; set; } public string Ethnicity { get; set; } public string ConfirmationNo { get; set; } public string ConfirmationType { get; set; } - public bool isOffline { get; set; } + public string isOffline { get; set; } public List Insurees { get; set; } public List Policies { get; set; } public List InsureePolicy { get; set; } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs index 789f7632..e4e44836 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs @@ -11,25 +11,25 @@ public class Insuree public string CHFID { get; set; } public string LastName { get; set; } public string OtherNames { get; set; } - public DateTime DOB { get; set; } - public int Gender { get; set; } - public int Marital { get; set; } + public DateTime? DOB { get; set; } + public string Gender { get; set; } + public string Marital { get; set; } public string isHead { get; set; } public string IdentificationNumber { get; set; } public string Phone { get; set; } public string PhotoPath { get; set; } - public bool CardIssued { get; set; } - public int Relationship { get; set; } - public int Profession { get; set; } - public int Education { get; set; } + public string CardIssued { get; set; } + public string Relationship { get; set; } + public string Profession { get; set; } + public string Education { get; set; } public string Email { get; set; } - public int TypeOfId { get; set; } - public int HFID { get; set; } + public string TypeOfId { get; set; } + public string HFID { get; set; } public string CurrentAddress { get; set; } public string GeoLocation { get; set; } - public int CurVillage { get; set; } - public bool isOffline { get; set; } - public DateTime EffectiveDate { get; set; } + public string CurVillage { get; set; } + public string isOffline { get; set; } + public DateTime? EffectiveDate { get; set; } public InsureeImage Picture { get; set; } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureePolicy.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureePolicy.cs index 6970756c..ed69e8af 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureePolicy.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureePolicy.cs @@ -8,6 +8,6 @@ public class InsureePolicy { public int InsureeId { get; set; } public int PolicyId { get; set; } - public DateTime EffectiveDate { get; set; } + public DateTime? EffectiveDate { get; set; } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Policy.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Policy.cs index c8801d82..f7670567 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Policy.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Policy.cs @@ -8,16 +8,16 @@ public class Policy { public int PolicyId { get; set; } public int FamilyId { get; set; } - public DateTime EnrollDate { get; set; } - public DateTime StartDate { get; set; } - public DateTime EffectiveDate { get; set; } - public DateTime ExpiryDate { get; set; } - public int PolicyStatus { get; set; } - public decimal PolicyValue { get; set; } + public DateTime? EnrollDate { get; set; } + public DateTime? StartDate { get; set; } + public DateTime? EffectiveDate { get; set; } + public DateTime? ExpiryDate { get; set; } + public string PolicyStatus { get; set; } + public string PolicyValue { get; set; } public int ProdId { get; set; } public int OfficerId { get; set; } - public int PolicyStage { get; set; } - public bool isOffline { get; set; } + public string PolicyStage { get; set; } + public string isOffline { get; set; } public Premium Premium { get; set; } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Premium.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Premium.cs index 347bd1e6..4eb32207 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Premium.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Premium.cs @@ -11,9 +11,9 @@ public class Premium public int PayerId { get; set; } public string Amount { get; set; } public string Receipt { get; set; } - public DateTime PayDate { get; set; } - public int PayType { get; set; } - public bool isPhotoFee { get; set; } - public bool isOffline { get; set; } + public DateTime? PayDate { get; set; } + public string PayType { get; set; } + public string isPhotoFee { get; set; } + public string isOffline { get; set; } } } diff --git a/OpenImis.ModulesV2/MasterDataModule/Models/OfficerModel.cs b/OpenImis.ModulesV2/MasterDataModule/Models/OfficerModel.cs index ba2ec14c..6c278c6e 100644 --- a/OpenImis.ModulesV2/MasterDataModule/Models/OfficerModel.cs +++ b/OpenImis.ModulesV2/MasterDataModule/Models/OfficerModel.cs @@ -6,6 +6,7 @@ namespace OpenImis.ModulesV2.MasterDataModule.Models { public class OfficerModel { + public int OfficerId { get; set; } public Guid OfficerUUID { get; set; } public string Code { get; set; } public string LastName { get; set; } diff --git a/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs b/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs index 1962ea03..a98f442b 100644 --- a/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs +++ b/OpenImis.ModulesV2/MasterDataModule/Repositories/MasterDataRepository.cs @@ -194,6 +194,7 @@ public List GetOfficers() .Where(o => o.ValidityTo == null) .Select(x => new OfficerModel() { + OfficerId = x.OfficerId, OfficerUUID = x.OfficerUUID, Code = x.Code, LastName = x.LastName, diff --git a/OpenImis.ModulesV2/PolicyModule/Logic/IPolicyRenewalLogic.cs b/OpenImis.ModulesV2/PolicyModule/Logic/IPolicyRenewalLogic.cs index 29f2a1ef..9b3d4283 100644 --- a/OpenImis.ModulesV2/PolicyModule/Logic/IPolicyRenewalLogic.cs +++ b/OpenImis.ModulesV2/PolicyModule/Logic/IPolicyRenewalLogic.cs @@ -10,5 +10,6 @@ public interface IPolicyRenewalLogic List Get(string officerCode); int Post(PolicyRenewalModel policy); int Delete(Guid uuid); + DataMessage GetCommissions(GetCommissionInputs model); } } diff --git a/OpenImis.ModulesV2/PolicyModule/Logic/PolicyRenewalLogic.cs b/OpenImis.ModulesV2/PolicyModule/Logic/PolicyRenewalLogic.cs index f5715268..43fa56f0 100644 --- a/OpenImis.ModulesV2/PolicyModule/Logic/PolicyRenewalLogic.cs +++ b/OpenImis.ModulesV2/PolicyModule/Logic/PolicyRenewalLogic.cs @@ -48,5 +48,14 @@ public int Delete(Guid uuid) return response; } + + public DataMessage GetCommissions(GetCommissionInputs model) + { + DataMessage response; + + response = policyRenewalRepository.GetCommissions(model); + + return response; + } } } diff --git a/OpenImis.ModulesV2/PolicyModule/Models/CommissionMode.cs b/OpenImis.ModulesV2/PolicyModule/Models/CommissionMode.cs new file mode 100644 index 00000000..7a71db21 --- /dev/null +++ b/OpenImis.ModulesV2/PolicyModule/Models/CommissionMode.cs @@ -0,0 +1,10 @@ +using System; + +namespace OpenImis.ModulesV2.PolicyModule.Models +{ + public enum CommissionMode + { + Prescribed, + Paid + } +} diff --git a/OpenImis.ModulesV2/PolicyModule/Models/DataMessage.cs b/OpenImis.ModulesV2/PolicyModule/Models/DataMessage.cs new file mode 100644 index 00000000..fc7c0e9c --- /dev/null +++ b/OpenImis.ModulesV2/PolicyModule/Models/DataMessage.cs @@ -0,0 +1,12 @@ +using System; + +namespace OpenImis.ModulesV2.PolicyModule.Models +{ + public class DataMessage + { + public int Code { get; set; } + public string MessageValue { get; set; } + public bool ErrorOccured { get; set; } + public object Data { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PolicyModule/Models/GetCommissionInputs.cs b/OpenImis.ModulesV2/PolicyModule/Models/GetCommissionInputs.cs new file mode 100644 index 00000000..bd0afd52 --- /dev/null +++ b/OpenImis.ModulesV2/PolicyModule/Models/GetCommissionInputs.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace OpenImis.ModulesV2.PolicyModule.Models +{ + public class GetCommissionInputs + { + public string enrolment_officer_code { get; set; } + public string month { get; set; } + public string year { get; set; } + public CommissionMode mode { get; set; } + public string insrance_product_code { get; set; } + public string payer { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PolicyModule/Repositories/IPolicyRenewalRepository.cs b/OpenImis.ModulesV2/PolicyModule/Repositories/IPolicyRenewalRepository.cs index 696fb1d5..20af226f 100644 --- a/OpenImis.ModulesV2/PolicyModule/Repositories/IPolicyRenewalRepository.cs +++ b/OpenImis.ModulesV2/PolicyModule/Repositories/IPolicyRenewalRepository.cs @@ -9,5 +9,6 @@ public interface IPolicyRenewalRepository List Get(string officerCode); int Post(PolicyRenewalModel policy); int Delete(Guid uuid); + DataMessage GetCommissions(GetCommissionInputs model); } } diff --git a/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs b/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs index 859dae1a..7629d250 100644 --- a/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs +++ b/OpenImis.ModulesV2/PolicyModule/Repositories/PolicyRenewalRepository.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Xml; using System; +using System.Diagnostics; namespace OpenImis.ModulesV2.PolicyModule.Repositories { @@ -242,5 +243,62 @@ private Guid GetRenewalUUIDById(int id) throw e; } } + + public DataMessage GetCommissions(GetCommissionInputs model) + { + dynamic response; + + int year = DateTime.UtcNow.Year; + int month = DateTime.UtcNow.Month; + + try + { + year = Convert.ToInt32(model.year); + month = Convert.ToInt32(model.month); + } + catch (Exception) + { + throw; + } + + DateTime minDate = new DateTime(year, month, 1); + DateTime maxDate = new DateTime(year, month, DateTime.DaysInMonth(year, month)); + + DataMessage message; + + try + { + using (var imisContext = new ImisDB()) + { + var res = (from PR in imisContext.TblPremium + join P in imisContext.TblPolicy.Where(p => p.ValidityTo == null) on PR.PolicyId equals P.PolicyId + join R in imisContext.TblReporting on PR.ReportingCommissionID equals R.ReportingId + join O in imisContext.TblOfficer on P.OfficerId equals O.OfficerId + where (PR.ReportingCommissionID == null + && (PR.PayDate >= minDate && PR.PayDate <= maxDate) + && PR.ValidityTo == null + && O.Code == model.enrolment_officer_code) + select new + { + Commission = (R.CammissionRate == null ? 0.00M : R.CammissionRate) * PR.Amount, + PR.Amount + }) + .ToList(); + + var c = res.Count > 0 ? res.Sum(x => x.Commission) : null; + var a = res.Count > 0 ? res.Sum(x => (decimal?)x.Amount) : null; + + response = new List() { new { Commission = c, Amount = a } }; + + message = new GetCommissionResponse(0, false, response, 0).Message; + } + } + catch (Exception e) + { + message = new GetCommissionResponse(e).Message; + } + + return message; + } } } diff --git a/OpenImis.RestApi/Controllers/V2/FamilyController.cs b/OpenImis.RestApi/Controllers/V2/FamilyController.cs index 84ab9d64..ce7dad59 100644 --- a/OpenImis.RestApi/Controllers/V2/FamilyController.cs +++ b/OpenImis.RestApi/Controllers/V2/FamilyController.cs @@ -57,6 +57,12 @@ public IActionResult Create([FromBody] EnrollFamilyModel model) { int response; + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + try { Guid userUUID = Guid.Parse(HttpContext.User.Claims.Where(w => w.Type == "UserUUID").Select(x => x.Value).FirstOrDefault()); diff --git a/OpenImis.RestApi/Controllers/V2/PolicyRenewalController.cs b/OpenImis.RestApi/Controllers/V2/PolicyRenewalController.cs index a17f8cb0..5ebf7449 100644 --- a/OpenImis.RestApi/Controllers/V2/PolicyRenewalController.cs +++ b/OpenImis.RestApi/Controllers/V2/PolicyRenewalController.cs @@ -84,5 +84,21 @@ public IActionResult Delete(Guid uuid) return Ok(response); } + + [HasRights(Rights.PolicySearch)] + [HttpPost] + [Route("commissions")] + public virtual IActionResult GetCommissions([FromBody]GetCommissionInputs model) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new { error_occured = true, error_message = error }); + } + + var response = _imisModules.GetPolicyModule().GetPolicyRenewalLogic().GetCommissions(model); + + return Json(response); + } } } \ No newline at end of file From c14cb28f1498f5ac3f3c0072b8ccbfe8fe30d42a Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 24 Oct 2019 14:50:29 +0200 Subject: [PATCH 78/86] OS-41: Changed ImageContent to String64 --- .../Models/EnrollFamilyModels/InsureeImage.cs | 2 +- OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs | 2 +- .../InsureeModule/Repositories/FamilyRepository.cs | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureeImage.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureeImage.cs index d50542f5..425e6de4 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureeImage.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/InsureeImage.cs @@ -7,6 +7,6 @@ namespace OpenImis.ModulesV2.InsureeModule.Models.EnrollFamilyModels public class InsureeImage { public string ImageName { get; set; } - public byte[] ImageContent { get; set; } + public string ImageContent { get; set; } } } diff --git a/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs b/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs index 11c76605..2388ff45 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/InsureeModel.cs @@ -49,7 +49,7 @@ public static InsureeModel FromTblInsuree(TblInsuree tblInsuree) CHFID = tblInsuree.Chfid, LastName = tblInsuree.LastName, OtherNames = tblInsuree.OtherNames, - DOB = tblInsuree.Dob.ToString("yyyy-mm-dd"), + DOB = tblInsuree.Dob.ToString("yyyy-MM-dd"), IsHead = tblInsuree.IsHead, Phone = tblInsuree.Phone, Gender = tblInsuree.Gender, diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs index eb7cbc75..b7a011ee 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs @@ -14,6 +14,8 @@ using Microsoft.AspNetCore.Hosting; using System.Xml; using Newtonsoft.Json; +using System.Diagnostics; +using System.Text; namespace OpenImis.ModulesV2.InsureeModule.Repositories { @@ -178,7 +180,7 @@ public int Create(EnrollFamilyModel model, int userId, int officerId) using (var reader = cmd.ExecuteReader()) { - //Displaying errors in the Stored Procedure in Debug mode + // Displaying errors in the Stored Procedure in Debug mode //do //{ // while (reader.Read()) @@ -206,9 +208,9 @@ public int Create(EnrollFamilyModel model, int userId, int officerId) { if (picture.ImageContent != null) { - if (picture.ImageContent.Length == 0) + if (picture.ImageContent.Length != 0) { - File.WriteAllBytes(webRootPath + UpdatedFolder + Path.DirectorySeparatorChar + picture.ImageName, picture.ImageContent); + File.WriteAllBytes(webRootPath + UpdatedFolder + Path.DirectorySeparatorChar + picture.ImageName, Convert.FromBase64String(picture.ImageContent)); } } } From 1a91b371d3a1513bd1ee650afeadecbe02531bd5 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Thu, 24 Oct 2019 15:11:27 +0200 Subject: [PATCH 79/86] OS-41: Changes in Post Family --- .../InsureeModule/Repositories/FamilyRepository.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs index b7a011ee..62e36dfa 100644 --- a/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs +++ b/OpenImis.ModulesV2/InsureeModule/Repositories/FamilyRepository.cs @@ -106,18 +106,11 @@ public int Create(EnrollFamilyModel model, int userId, int officerId) var UpdatedFolder = _configuration["AppSettings:UpdatedFolder"]; var SubmittedFolder = _configuration["AppSettings:SubmittedFolder"]; - var hof = ""; + var hof = enrollFamily.Families.Select(x => x.HOFCHFID).FirstOrDefault(); - if (enrollFamily.Insurees.Any(x => x.isHead == "true" || x.isHead == "1")) - { - hof = enrollFamily.Insurees.Where(x => x.isHead == "true" || x.isHead == "1").Select(z => z.CHFID).FirstOrDefault(); - } - else hof = "Unknown"; - - var FileName = string.Format("{0}__{1}_{2}.xml", hof, officerId.ToString(), DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss.XML")); + var FileName = string.Format("{0}_{1}_{2}.xml", hof, officerId.ToString(), DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")); var JsonFileName = string.Format("{0}_{1}_{2}.json", hof, officerId.ToString(), DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")); - var xmldoc = new XmlDocument(); xmldoc.InnerXml = XML; From daa679d95f7b49faac8565e096b86dd604df1b28 Mon Sep 17 00:00:00 2001 From: bkaminski Date: Fri, 25 Oct 2019 17:14:16 +0200 Subject: [PATCH 80/86] OS-41: Removed EffectiveDate from Insuree --- .../InsureeModule/Models/EnrollFamilyModels/Insuree.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs index e4e44836..31396a17 100644 --- a/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs +++ b/OpenImis.ModulesV2/InsureeModule/Models/EnrollFamilyModels/Insuree.cs @@ -29,7 +29,6 @@ public class Insuree public string GeoLocation { get; set; } public string CurVillage { get; set; } public string isOffline { get; set; } - public DateTime? EffectiveDate { get; set; } public InsureeImage Picture { get; set; } } } From 5b2bebae2ad433d834d5dec347573cfef77dbb0f Mon Sep 17 00:00:00 2001 From: bkaminski Date: Mon, 28 Oct 2019 11:42:38 +0100 Subject: [PATCH 81/86] OS-42: New endpoints in Payment Module --- .../Helpers/CtrlNumberResponse.cs | 48 ++ .../Helpers/Extensions/StringExtensions.cs | 51 ++ OpenImis.ModulesV2/Helpers/SaveAckResponse.cs | 42 ++ .../PaymentModule/Helpers/FamilyDefaults.cs | 14 + .../PaymentModule/Helpers/LocalDefault.cs | 129 +++++ .../Helpers/RequestedCNResponse.cs | 57 +++ .../PaymentModule/Helpers/SMS/ImisBaseSms.cs | 90 ++++ .../PaymentModule/Helpers/SMS/ImisSms.cs | 13 + .../Helpers/SaveIntentResponse.cs | 88 ++++ .../PaymentModule/Logic/IPaymentLogic.cs | 9 +- .../PaymentModule/Logic/PaymentLogic.cs | 168 +++++++ .../PaymentModule/Models/ControlNumberResp.cs | 14 + .../PaymentModule/Models/EnrolmentType.cs | 10 + .../PaymentModule/Models/InsureeProduct.cs | 16 + .../PaymentModule/Models/IntentOfPay.cs | 19 + .../PaymentModule/Models/Language.cs | 10 + .../PaymentModule/Models/PaymentDetail.cs | 26 + .../PaymentModule/Models/PaymentRequest.cs | 9 + .../PaymentModule/Models/Request.cs | 10 + .../Response/AsignedControlNumbersResponse.cs | 12 + .../Models/Response/AssignedControlNumber.cs | 12 + .../Models/Response/ErrorResponse.cs | 11 + .../Models/Response/ErrorResponseV2.cs | 12 + .../Models/Response/GetControlNumberResp.cs | 14 + .../Models/Response/PaymentDataBadResp.cs | 11 + .../Models/Response/PostReqCNResponse.cs | 17 + .../PaymentModule/Models/SMS/SmsContainer.cs | 10 + .../PaymentModule/Models/TypeOfPayment.cs | 13 + .../Repositories/IPaymentRepository.cs | 37 ++ .../Repositories/PaymentRepository.cs | 467 ++++++++++++++++++ .../Controllers/V2/PaymentController.cs | 108 ++++ 31 files changed, 1544 insertions(+), 3 deletions(-) create mode 100644 OpenImis.ModulesV2/Helpers/CtrlNumberResponse.cs create mode 100644 OpenImis.ModulesV2/Helpers/Extensions/StringExtensions.cs create mode 100644 OpenImis.ModulesV2/Helpers/SaveAckResponse.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Helpers/FamilyDefaults.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Helpers/LocalDefault.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Helpers/RequestedCNResponse.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Helpers/SMS/ImisBaseSms.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Helpers/SMS/ImisSms.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Helpers/SaveIntentResponse.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/ControlNumberResp.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/EnrolmentType.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/InsureeProduct.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/IntentOfPay.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/Language.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/PaymentDetail.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/PaymentRequest.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/Request.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/Response/AssignedControlNumber.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/Response/ErrorResponse.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/Response/ErrorResponseV2.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/Response/GetControlNumberResp.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/Response/PaymentDataBadResp.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/Response/PostReqCNResponse.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/SMS/SmsContainer.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Models/TypeOfPayment.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Repositories/IPaymentRepository.cs create mode 100644 OpenImis.ModulesV2/PaymentModule/Repositories/PaymentRepository.cs create mode 100644 OpenImis.RestApi/Controllers/V2/PaymentController.cs diff --git a/OpenImis.ModulesV2/Helpers/CtrlNumberResponse.cs b/OpenImis.ModulesV2/Helpers/CtrlNumberResponse.cs new file mode 100644 index 00000000..10a3e2d6 --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/CtrlNumberResponse.cs @@ -0,0 +1,48 @@ +using OpenImis.ModulesV2.Helpers; +using OpenImis.ModulesV2.Helpers.Messages; +using System; +using System.Data; + +namespace OpenImis.ModulesV2.PaymentModule.Helpers +{ + public class CtrlNumberResponse : ImisApiResponse + { + public CtrlNumberResponse(Exception e) : base(e) + { + + } + + public CtrlNumberResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + + } + + public CtrlNumberResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "CantAssignCN"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "DuplicateCN"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.ModulesV2/Helpers/Extensions/StringExtensions.cs b/OpenImis.ModulesV2/Helpers/Extensions/StringExtensions.cs new file mode 100644 index 00000000..debde4a3 --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/Extensions/StringExtensions.cs @@ -0,0 +1,51 @@ +using System; + +namespace OpenImis.ModulesV2.PaymentModule.Helpers.Extensions +{ + public static class StringExtensions + { + public static int? GetErrorNumber(this string str) + { + if (String.IsNullOrEmpty(str)) + { + return null; + } + else + { + try + { + var error = str.Split(":"); + var errorNumber = int.Parse(error[0]); + return errorNumber; + } + catch (Exception) + { + return null; + } + } + } + + public static string GetErrorMessage(this string str) + { + if (String.IsNullOrEmpty(str)) + { + return str; + } + else + { + try + { + var error = str.Split(":"); + int.Parse(error[0]); + var errorMessae = error[1]; + return errorMessae; + } + catch (Exception) + { + + return str; + } + } + } + } +} diff --git a/OpenImis.ModulesV2/Helpers/SaveAckResponse.cs b/OpenImis.ModulesV2/Helpers/SaveAckResponse.cs new file mode 100644 index 00000000..99ad3d54 --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/SaveAckResponse.cs @@ -0,0 +1,42 @@ +using OpenImis.ModulesV2.Helpers; +using OpenImis.ModulesV2.Helpers.Messages; +using System; +using System.Data; + +namespace OpenImis.ModulesV2.PaymentModule.Helpers +{ + public class SaveAckResponse : ImisApiResponse + { + public SaveAckResponse(Exception e) : base(e) + { + + } + + public SaveAckResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + + public SaveAckResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); ; + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "CantPostReq"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Helpers/FamilyDefaults.cs b/OpenImis.ModulesV2/PaymentModule/Helpers/FamilyDefaults.cs new file mode 100644 index 00000000..e04b73d5 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Helpers/FamilyDefaults.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.PaymentModule.Helpers +{ + public class FamilyDefaults + { + public int Adults { get; set; } + public int Children { get; set; } + public int OtherAdults { get; internal set; } + public int OtherChildren { get; internal set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Helpers/LocalDefault.cs b/OpenImis.ModulesV2/PaymentModule/Helpers/LocalDefault.cs new file mode 100644 index 00000000..57d53d3e --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Helpers/LocalDefault.cs @@ -0,0 +1,129 @@ +using Microsoft.Extensions.Configuration; +using System; +using System.Collections.Generic; + +namespace OpenImis.ModulesV2.PaymentModule.Helpers +{ + public static class LocalDefault + { + public static FamilyDefaults FamilyMembers(IConfiguration config) + { + try + { + var adults = Convert.ToInt32(config["Defaults:Family:Adults"]); + var children = Convert.ToInt32(config["Defaults:Family:Children"]); + var other_adults = Convert.ToInt32(config["Defaults:Family:OtherAdults"]); + var other_children = Convert.ToInt32(config["Defaults:Family:OtherChildren"]); + + FamilyDefaults fam = new FamilyDefaults() { Adults = adults, Children = children, OtherAdults = other_adults, OtherChildren = other_children }; + return fam; + } + catch (Exception) + { + + throw new Exception("A Family property is not properly defined in config file"); + } + } + + public static bool PriorEnrolmentRequired(IConfiguration config) + { + try + { + var value = Convert.ToBoolean(config["Defaults:PriorEnrolment"]); + return value; + } + catch (Exception) + { + throw new Exception("This property is not properly defined in config file"); + } + } + + public static bool ShouldSendSms(IConfiguration config, DateTime? lastSmsDate, DateTime? matchedDate) + { + try + { + var value = Convert.ToInt32(config["Defaults:PeriodPayNotMatchedSms"]); + if (value == 0) + return false; + + DateTime today = DateTime.UtcNow; + + if (lastSmsDate != null) + { + DateTime thatday = (DateTime)lastSmsDate; + int interval = (today - thatday).Days; + + if (value > 0) + { + return false; + } + else + { + value *= -1; + if (interval % value == 0) + { + return true; + } + else + { + return false; + } + } + } + else + { + if (matchedDate != null) + { + DateTime thatday = (DateTime)matchedDate; + int interval = (today - thatday).Days; + + if (interval / value >= 1) + { + return true; + } + else + { + return false; + } + } + else + { + return false; + } + } + + } + catch (Exception) + { + throw new Exception("This property is not properly defined in config file"); + } + } + + public static string[] PrimaryLangReprisantations(IConfiguration config) + { + List langs = new List(); + try + { + var def_langs = config["Language:Primary"].Split(','); + + foreach (var def_lang in def_langs) + { + try + { + langs.Add(def_lang.ToLower()); + } + catch (Exception) + { + langs.Add(def_lang); + } + } + } + catch (Exception) + { + langs.Add("en"); + } + + return langs.ToArray(); + } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Helpers/RequestedCNResponse.cs b/OpenImis.ModulesV2/PaymentModule/Helpers/RequestedCNResponse.cs new file mode 100644 index 00000000..06bb6005 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Helpers/RequestedCNResponse.cs @@ -0,0 +1,57 @@ +using Newtonsoft.Json; +using OpenImis.ModulesV2.Helpers; +using OpenImis.ModulesV2.PaymentModule.Models.Response; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; + +namespace OpenImis.ModulesV2.PaymentModule.Helpers +{ + public class RequestedCNResponse : ImisApiResponse + { + public RequestedCNResponse(Exception e) : base(e) + { + } + + public RequestedCNResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + } + + public RequestedCNResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + var jsonString = JsonConvert.SerializeObject(data); + var reqs = JsonConvert.DeserializeObject>(jsonString); + msg.Data = reqs; + + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new ModulesV2.Helpers.Messages.Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new ModulesV2.Helpers.Messages.Language().GetMessage(language, "WrongInternalIdFormat"); + Message = msg; + break; + case 2: + var jsonString = JsonConvert.SerializeObject(msg.Data); + var reqs = JsonConvert.DeserializeObject>(jsonString).Select(x => x.internal_identifier).ToArray(); + var Ids_string = string.Join(",", reqs); + + msg.Code = value; + msg.MessageValue = new ModulesV2.Helpers.Messages.Language().GetMessage(language, "InvalidInternalId") + Ids_string; + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Helpers/SMS/ImisBaseSms.cs b/OpenImis.ModulesV2/PaymentModule/Helpers/SMS/ImisBaseSms.cs new file mode 100644 index 00000000..34a58282 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Helpers/SMS/ImisBaseSms.cs @@ -0,0 +1,90 @@ +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; +using OpenImis.ModulesV2.PaymentModule.Models; +using OpenImis.ModulesV2.PaymentModule.Models.SMS; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace OpenImis.ModulesV2.PaymentModule.Helpers.SMS +{ + public class ImisBaseSms + { + private string SmsTampletes = string.Empty; + private string webRootPath; + + public ImisBaseSms(IConfiguration config, string webRootPath, string contentRootPath, Language language = Language.Primary) + { + this.webRootPath = webRootPath; + + if (language == Language.Primary) + SmsTampletes = contentRootPath + @"\Escape\Sms\Strings\"; + else + SmsTampletes = contentRootPath + @"\Escape\Sms\StringsSecondaryLanguage\"; + } + + public virtual async Task SendSMS(List containers, string filename) + { + string response_message = string.Empty; + + + HttpClient client = new HttpClient(); + + var param = new { data = containers, datetime = DateTime.Now.ToString() }; + var content = new StringContent(JsonConvert.SerializeObject(param), Encoding.ASCII, "application/json"); + + try + { + var response = await client.PostAsync("url", content); + var ret = await response.Content.ReadAsStringAsync(); + response_message = ret; + } + catch (Exception e) + { + response_message = e.ToString(); + } + + var msg = JsonConvert.SerializeObject(containers); + SaveMessage(msg, filename); + + return response_message; + + } + + public virtual void SaveMessage(string message, string name) + { + //string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + string mydocpath = System.IO.Path.Combine(webRootPath, "SentMessages"); + string namepart = new Random().Next(100000, 999999).ToString(); + + using (StreamWriter outputFile = new StreamWriter(Path.Combine(mydocpath, name + namepart + ".json"))) + { + outputFile.WriteLine(message); + } + } + + public virtual string GetMessage(string filename) + { + string text = File.ReadAllText(SmsTampletes + filename + ".txt", Encoding.UTF8); + return text; + } + + public virtual async void QuickSms(string txtmsg, string phoneNumber, Language language = Language.Primary) + { + + + var txtmsgTemplate = string.Empty; + string othersCount = string.Empty; + + List message = new List(); + message.Add(new SmsContainer() { Message = txtmsg, Recipient = phoneNumber }); + + var fileName = "QuickSms_" + phoneNumber; + + string test = await SendSMS(message, fileName); + } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Helpers/SMS/ImisSms.cs b/OpenImis.ModulesV2/PaymentModule/Helpers/SMS/ImisSms.cs new file mode 100644 index 00000000..8f9ad8d7 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Helpers/SMS/ImisSms.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.Configuration; +using OpenImis.ModulesV2.PaymentModule.Models; + +namespace OpenImis.ModulesV2.PaymentModule.Helpers.SMS +{ + public class ImisSms : ImisBaseSms + { + public ImisSms(IConfiguration config, string webRootPath, string contentRootPath, Language language = Language.Primary) : base(config, webRootPath, contentRootPath, language) + { + + } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Helpers/SaveIntentResponse.cs b/OpenImis.ModulesV2/PaymentModule/Helpers/SaveIntentResponse.cs new file mode 100644 index 00000000..9e32888a --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Helpers/SaveIntentResponse.cs @@ -0,0 +1,88 @@ +using OpenImis.ModulesV2.Helpers; +using OpenImis.ModulesV2.Helpers.Messages; +using System; +using System.Data; + +namespace OpenImis.ModulesV2.PaymentModule.Helpers +{ + public class SaveIntentResponse : ImisApiResponse + { + public SaveIntentResponse(Exception e) : base(e) + { + + } + + public SaveIntentResponse(int value, bool error, int lang) : base(value, error, lang) + { + SetMessage(value); + + } + + public SaveIntentResponse(int value, bool error, DataTable data, int lang) : base(value, error, data, lang) + { + SetMessage(value); + } + + private void SetMessage(int value) + { + switch (value) + { + case 0: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "Success"); + Message = msg; + break; + case 1: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "WrongFormatInsureeNo"); + Message = msg; + break; + case 2: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "InValidINmissingPC"); + Message = msg; + break; + case 3: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "InValidEOC"); + Message = msg; + break; + case 4: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "IncompatibleEO_PC"); + Message = msg; + break; + case 5: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "NoRenewalProduct"); + Message = msg; + break; + case 6: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "InsureeNoMissing"); + Message = msg; + break; + case 7: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "InsureeNotEnrolled"); + Message = msg; + break; + case 8: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "DuplicateCNAssigned"); + Message = msg; + break; + case 9: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "CantAssignCn2"); + Message = msg; + break; + case 10: + msg.Code = value; + msg.MessageValue = new Language().GetMessage(language, "UnknownPaymentType"); + Message = msg; + break; + } + } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Logic/IPaymentLogic.cs b/OpenImis.ModulesV2/PaymentModule/Logic/IPaymentLogic.cs index f19af037..787b4d60 100644 --- a/OpenImis.ModulesV2/PaymentModule/Logic/IPaymentLogic.cs +++ b/OpenImis.ModulesV2/PaymentModule/Logic/IPaymentLogic.cs @@ -1,12 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Text; +using OpenImis.ModulesV2.PaymentModule.Models; +using OpenImis.ModulesV2.PolicyModule.Models; using System.Threading.Tasks; namespace OpenImis.ModulesV2.PaymentModule.Logic { public interface IPaymentLogic { + string WebRootPath { get; set; } + string ContentRootPath { get; set; } + Task GetControlNumbers(PaymentRequest requests); + Task SaveIntent(IntentOfPay intent, int? errorNumber = 0, string errorMessage = null); } } diff --git a/OpenImis.ModulesV2/PaymentModule/Logic/PaymentLogic.cs b/OpenImis.ModulesV2/PaymentModule/Logic/PaymentLogic.cs index bb0bd7fc..aa603670 100644 --- a/OpenImis.ModulesV2/PaymentModule/Logic/PaymentLogic.cs +++ b/OpenImis.ModulesV2/PaymentModule/Logic/PaymentLogic.cs @@ -1,6 +1,16 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; +using OpenImis.ModulesV2.PaymentModule.Helpers.SMS; +using OpenImis.ModulesV2.PaymentModule.Models; +using OpenImis.ModulesV2.PaymentModule.Models.Response; +using OpenImis.ModulesV2.PaymentModule.Models.SMS; +using OpenImis.ModulesV2.PaymentModule.Repositories; +using OpenImis.ModulesV2.PolicyModule.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace OpenImis.ModulesV2.PaymentModule.Logic { @@ -8,9 +18,167 @@ public class PaymentLogic : IPaymentLogic { private IConfiguration _configuration; + public string WebRootPath { get; set; } + public string ContentRootPath { get; set; } + public PaymentLogic(IConfiguration configuration) { _configuration = configuration; } + + public async Task SaveIntent(IntentOfPay intent, int? errorNumber = 0, string errorMessage = null) + { + IPaymentRepository payment = new PaymentRepository(_configuration); + var intentResponse = payment.SaveIntent(intent, errorNumber, errorMessage); + + DataMessage return_message = new DataMessage(); + return_message.Code = intentResponse.Code; + return_message.MessageValue = intentResponse.MessageValue; + + if (intentResponse.Code == 0) + { + var objstring = intentResponse.Data.ToString(); + List data = JsonConvert.DeserializeObject>(objstring); + var ret_data = data.FirstOrDefault(); + + decimal transferFee = 0; + //Get the transfer Fee + if (intent.type_of_payment != null) + { + transferFee = payment.determineTransferFee(payment.ExpectedAmount, (TypeOfPayment)intent.type_of_payment); + + var success = payment.UpdatePaymentTransferFee(payment.PaymentId, transferFee, (TypeOfPayment)intent.type_of_payment); + + } + + var amountToBePaid = payment.GetToBePaidAmount(payment.ExpectedAmount, transferFee); + var response = payment.PostReqControlNumber(intent.enrolment_officer_code, payment.PaymentId, intent.phone_number, amountToBePaid, intent.policies); + + if (response.ControlNumber != null) + { + var controlNumberExists = payment.CheckControlNumber(payment.PaymentId, response.ControlNumber); + return_message = payment.SaveControlNumber(response.ControlNumber, controlNumberExists); + if (payment.PaymentId != null) + { + if (!return_message.ErrorOccured && !controlNumberExists) + { + ret_data.control_number = response.ControlNumber; + ControlNumberAssignedSms(payment); + } + else + { + ControlNumberNotassignedSms(payment, return_message.MessageValue); + } + } + } + else if (response.Posted == true) + { + return_message = payment.SaveControlNumberAkn(response.ErrorOccured, response.ErrorMessage); + } + else if (response.ErrorOccured == true) + { + return_message = payment.SaveControlNumberAkn(response.ErrorOccured, response.ErrorMessage); + ControlNumberNotassignedSms(payment, response.ErrorMessage); + + } + + return_message.Data = ret_data; + } + else + { + return_message = intentResponse; + return_message.Data = new AssignedControlNumber(); + } + + return return_message; + } + + public async void ControlNumberAssignedSms(IPaymentRepository payment) + { + ImisSms sms = new ImisSms(_configuration, WebRootPath, ContentRootPath, payment.Language); + var txtmsgTemplate = string.Empty; + string othersCount = string.Empty; + + if (payment.InsureeProducts.Count > 1) + { + txtmsgTemplate = sms.GetMessage("ControlNumberAssignedV2"); + othersCount = Convert.ToString(payment.InsureeProducts.Count - 1); + } + else + { + txtmsgTemplate = sms.GetMessage("ControlNumberAssigned"); + } + + decimal transferFee = 0; + + if (payment.typeOfPayment != null) + { + transferFee = payment.determineTransferFee(payment.ExpectedAmount, (TypeOfPayment)payment.typeOfPayment); + + } + + var txtmsg = string.Format(txtmsgTemplate, + payment.ControlNum, + DateTime.UtcNow.ToLongDateString(), + DateTime.UtcNow.ToLongTimeString(), + payment.InsureeProducts.FirstOrDefault().InsureeNumber, + payment.InsureeProducts.FirstOrDefault().InsureeName, + payment.InsureeProducts.FirstOrDefault().ProductCode, + payment.InsureeProducts.FirstOrDefault().ProductName, + payment.GetToBePaidAmount(payment.ExpectedAmount, transferFee), + othersCount); + + List message = new List(); + message.Add(new SmsContainer() { Message = txtmsg, Recipient = payment.PhoneNumber }); + + var fileName = "CnAssigned_" + payment.PhoneNumber; + + string test = await sms.SendSMS(message, fileName); + } + + public async void ControlNumberNotassignedSms(IPaymentRepository payment, string error) + { + ImisSms sms = new ImisSms(_configuration, WebRootPath, ContentRootPath, payment.Language); + var txtmsgTemplate = string.Empty; + string othersCount = string.Empty; + + if (payment.InsureeProducts.Count > 1) + { + txtmsgTemplate = sms.GetMessage("ControlNumberErrorV2"); + othersCount = Convert.ToString(payment.InsureeProducts.Count - 1); + } + else + { + txtmsgTemplate = sms.GetMessage("ControlNumberError"); + } + + var txtmsg = string.Format(txtmsgTemplate, + payment.ControlNum, + DateTime.UtcNow.ToLongDateString(), + DateTime.UtcNow.ToLongTimeString(), + payment.InsureeProducts.FirstOrDefault().InsureeNumber, + payment.InsureeProducts.FirstOrDefault().ProductCode, + error, + othersCount); + + List message = new List(); + message.Add(new SmsContainer() { Message = txtmsg, Recipient = payment.PhoneNumber }); + + var fileName = "CnError_" + payment.PhoneNumber; + + string test = await sms.SendSMS(message, fileName); + } + + public async Task GetControlNumbers(PaymentRequest requests) + { + PaymentRepository payment = new PaymentRepository(_configuration); + var PaymentIds = requests.requests.Select(x => x.internal_identifier).ToArray(); + + var PaymentIds_string = string.Join(",", PaymentIds); + + var response = await payment.GetControlNumbers(PaymentIds_string); + + return response; + } } } diff --git a/OpenImis.ModulesV2/PaymentModule/Models/ControlNumberResp.cs b/OpenImis.ModulesV2/PaymentModule/Models/ControlNumberResp.cs new file mode 100644 index 00000000..1254ae63 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/ControlNumberResp.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; + +namespace OpenImis.ModulesV2.PaymentModule.Models +{ + public class ControlNumberResp + { + [Required] + public string internal_identifier { get; set; } + public string control_number { get; set; } + [Required] + public bool error_occured { get; set; } + public string error_message { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/EnrolmentType.cs b/OpenImis.ModulesV2/PaymentModule/Models/EnrolmentType.cs new file mode 100644 index 00000000..43caf564 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/EnrolmentType.cs @@ -0,0 +1,10 @@ +using System; + +namespace OpenImis.ModulesV2.PaymentModule.Models +{ + public enum EnrolmentType + { + New, + Renewal + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/InsureeProduct.cs b/OpenImis.ModulesV2/PaymentModule/Models/InsureeProduct.cs new file mode 100644 index 00000000..ae776a04 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/InsureeProduct.cs @@ -0,0 +1,16 @@ +using System; + +namespace OpenImis.ModulesV2.PaymentModule.Models +{ + public class InsureeProduct + { + public string InsureeNumber { get; set; } + public string InsureeName { get; set; } + public string ProductCode { get; set; } + public string ProductName { get; set; } + public DateTime? EffectiveDate { get; set; } + public DateTime? ExpiryDate { get; set; } + public bool PolicyActivated { get; set; } + public decimal ExpectedProductAmount { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/IntentOfPay.cs b/OpenImis.ModulesV2/PaymentModule/Models/IntentOfPay.cs new file mode 100644 index 00000000..327c01e9 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/IntentOfPay.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace OpenImis.ModulesV2.PaymentModule.Models +{ + public class IntentOfPay + { + [Required(ErrorMessage = "9: Phone number not provided")] + public virtual string phone_number { get; set; } + [DataType(DataType.DateTime)] + public string request_date { get; set; } + public string enrolment_officer_code { get; set; } + public virtual List policies { get; set; } + public decimal amount_to_be_paid { get; set; } + public string language { get; set; } + [Range(0, 2, ErrorMessage = "10-Uknown type of payment")] + public TypeOfPayment? type_of_payment { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/Language.cs b/OpenImis.ModulesV2/PaymentModule/Models/Language.cs new file mode 100644 index 00000000..cc430ec2 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/Language.cs @@ -0,0 +1,10 @@ +using System; + +namespace OpenImis.ModulesV2.PaymentModule.Models +{ + public enum Language + { + Primary, + Secondary + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/PaymentDetail.cs b/OpenImis.ModulesV2/PaymentModule/Models/PaymentDetail.cs new file mode 100644 index 00000000..20dee78b --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/PaymentDetail.cs @@ -0,0 +1,26 @@ +using System.ComponentModel.DataAnnotations; + +namespace OpenImis.ModulesV2.PaymentModule.Models +{ + public class PaymentDetail + { + public string insurance_number { get; set; } + [Required(ErrorMessage = "2:Not valid insurance or missing product code")] + public string insurance_product_code { get; set; } + [Required(ErrorMessage = "10:EnrolmentType was not provided")] + [Range(0, 2)] + public EnrolmentType? renewal { get; set; } + public int IsRenewal() + { + switch (renewal) + { + case EnrolmentType.Renewal: + return 1; + case EnrolmentType.New: + return 0; + default: + return 0; + } + } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/PaymentRequest.cs b/OpenImis.ModulesV2/PaymentModule/Models/PaymentRequest.cs new file mode 100644 index 00000000..d572a875 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/PaymentRequest.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace OpenImis.ModulesV2.PaymentModule.Models +{ + public class PaymentRequest + { + public List requests { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/Request.cs b/OpenImis.ModulesV2/PaymentModule/Models/Request.cs new file mode 100644 index 00000000..5b75d519 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/Request.cs @@ -0,0 +1,10 @@ +using System.ComponentModel.DataAnnotations; + +namespace OpenImis.ModulesV2.PaymentModule.Models +{ + public class Request + { + [Required(ErrorMessage = "1- Wrong format of internal identifier")] + public string internal_identifier { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs b/OpenImis.ModulesV2/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs new file mode 100644 index 00000000..34b269ca --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/Response/AsignedControlNumbersResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.PaymentModule.Models.Response +{ + public class AsignedControlNumbersResponse + { + public bool error_occured { get; set; } + public List assigned_control_numbers { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/Response/AssignedControlNumber.cs b/OpenImis.ModulesV2/PaymentModule/Models/Response/AssignedControlNumber.cs new file mode 100644 index 00000000..723986ba --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/Response/AssignedControlNumber.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.PaymentModule.Models.Response +{ + public class AssignedControlNumber + { + public string internal_identifier { get; set; } + public string control_number { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/Response/ErrorResponse.cs b/OpenImis.ModulesV2/PaymentModule/Models/Response/ErrorResponse.cs new file mode 100644 index 00000000..d09522d0 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/Response/ErrorResponse.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.PaymentModule.Models.Response +{ + public class ErrorResponse + { + public string error_message { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/Response/ErrorResponseV2.cs b/OpenImis.ModulesV2/PaymentModule/Models/Response/ErrorResponseV2.cs new file mode 100644 index 00000000..054cf275 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/Response/ErrorResponseV2.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.PaymentModule.Models.Response +{ + public class ErrorResponseV2 + { + public bool error_occured { get; set; } + public string error_message { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/Response/GetControlNumberResp.cs b/OpenImis.ModulesV2/PaymentModule/Models/Response/GetControlNumberResp.cs new file mode 100644 index 00000000..ad849c25 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/Response/GetControlNumberResp.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.PaymentModule.Models.Response +{ + public class GetControlNumberResp + { + public bool error_occured { get; set; } + public string error_message { get; set; } + public string internal_identifier { get; set; } + public string control_number { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/Response/PaymentDataBadResp.cs b/OpenImis.ModulesV2/PaymentModule/Models/Response/PaymentDataBadResp.cs new file mode 100644 index 00000000..6c8d4ecf --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/Response/PaymentDataBadResp.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.PaymentModule.Models.Response +{ + public class PaymentDataBadResp + { + public string error_message { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/Response/PostReqCNResponse.cs b/OpenImis.ModulesV2/PaymentModule/Models/Response/PostReqCNResponse.cs new file mode 100644 index 00000000..b990d3bf --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/Response/PostReqCNResponse.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.PaymentModule.Models.Response +{ + public class PostReqCNResponse + { + public string ControlNumber { get; set; } + public bool Posted { get; set; } + public bool Assigned { get; set; } + public int ErrorCode { get; set; } + + public bool ErrorOccured { get; set; } + public string ErrorMessage { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/SMS/SmsContainer.cs b/OpenImis.ModulesV2/PaymentModule/Models/SMS/SmsContainer.cs new file mode 100644 index 00000000..9387317c --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/SMS/SmsContainer.cs @@ -0,0 +1,10 @@ +using System; + +namespace OpenImis.ModulesV2.PaymentModule.Models.SMS +{ + public class SmsContainer + { + public string Message { get; set; } + public string Recipient { get; set; } + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Models/TypeOfPayment.cs b/OpenImis.ModulesV2/PaymentModule/Models/TypeOfPayment.cs new file mode 100644 index 00000000..64dc4c18 --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Models/TypeOfPayment.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.PaymentModule.Models +{ + public enum TypeOfPayment + { + Cash, + MobilePhone, + BankTransfer + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Repositories/IPaymentRepository.cs b/OpenImis.ModulesV2/PaymentModule/Repositories/IPaymentRepository.cs new file mode 100644 index 00000000..1d0dff5e --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Repositories/IPaymentRepository.cs @@ -0,0 +1,37 @@ +using OpenImis.ModulesV2.PaymentModule.Models; +using OpenImis.ModulesV2.PaymentModule.Models.Response; +using OpenImis.ModulesV2.PolicyModule.Models; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace OpenImis.ModulesV2.PaymentModule.Repositories +{ + public interface IPaymentRepository + { + string PaymentId { get; set; } + decimal ExpectedAmount { get; set; } + string ControlNum { get; set; } + string PhoneNumber { get; set; } + Language Language { get; set; } + TypeOfPayment? typeOfPayment { get; set; } + + DateTime? PaymentDate { get; set; } + decimal? PaidAmount { get; set; } + decimal? OutStAmount { get; set; } + List InsureeProducts { get; set; } + + DataMessage SaveIntent(IntentOfPay _intent, int? errorNumber = 0, string errorMessage = null); + Task GetControlNumbers(string PaymentIds); + void GetPaymentInfo(string Id); + decimal determineTransferFee(decimal expectedAmount, TypeOfPayment typeOfPayment); + bool UpdatePaymentTransferFee(string paymentId, decimal TransferFee, TypeOfPayment typeOfPayment); + decimal GetToBePaidAmount(decimal ExpectedAmount, decimal TransferFee); + PostReqCNResponse PostReqControlNumber(string OfficerCode, string PaymentId, string PhoneNumber, decimal ExpectedAmount, List products, string controlNumber = null, bool acknowledge = false, bool error = false); + bool CheckControlNumber(string PaymentID, string ControlNumber); + DataMessage SaveControlNumberAkn(bool error_occured, string Comment); + DataMessage SaveControlNumber(string ControlNumber, bool failed); + DataMessage SaveControlNumber(ControlNumberResp model, bool failed); + + } +} diff --git a/OpenImis.ModulesV2/PaymentModule/Repositories/PaymentRepository.cs b/OpenImis.ModulesV2/PaymentModule/Repositories/PaymentRepository.cs new file mode 100644 index 00000000..6aaa395a --- /dev/null +++ b/OpenImis.ModulesV2/PaymentModule/Repositories/PaymentRepository.cs @@ -0,0 +1,467 @@ +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; +using OpenImis.DB.SqlServer.DataHelper; +using OpenImis.ModulesV2.PaymentModule.Helpers; +using OpenImis.ModulesV2.PaymentModule.Models; +using OpenImis.ModulesV2.PaymentModule.Models.Response; +using OpenImis.ModulesV2.PolicyModule.Models; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Threading.Tasks; +using System.Xml.Linq; +using Language = OpenImis.ModulesV2.PaymentModule.Models.Language; + +namespace OpenImis.ModulesV2.PaymentModule.Repositories +{ + public class PaymentRepository : IPaymentRepository + { + private IConfiguration Configuration; + protected DataHelper dh; + + public string PaymentId { get; set; } + public decimal ExpectedAmount { get; set; } + public string ControlNum { get; set; } + public string PhoneNumber { get; set; } + public Language Language { get; set; } + public TypeOfPayment? typeOfPayment { get; set; } + + public DateTime? PaymentDate { get; set; } + public decimal? PaidAmount { get; set; } + public decimal? OutStAmount { get; set; } + public List InsureeProducts { get; set; } + + public PaymentRepository(IConfiguration configuration) + { + Configuration = configuration; + dh = new DataHelper(configuration); + } + + public async Task GetControlNumbers(string PaymentIds) + { + var sSQL = String.Format(@"SELECT PaymentID,ControlNumber + FROM tblControlNumber WHERE PaymentID IN({0})", PaymentIds); + + SqlParameter[] sqlParameters = { + + }; + + DataMessage dt = new DataMessage(); + try + { + DataTable data = dh.GetDataTable(sSQL, sqlParameters, CommandType.Text); + data.Columns["PaymentID"].ColumnName = "internal_identifier"; + data.Columns["ControlNumber"].ColumnName = "control_number"; + + var ids = PaymentIds.Split(","); + + if (ids.Distinct().Count() == data.Rows.Count) + { + dt = new RequestedCNResponse(0, false, data, (int)Language).Message; + } + else + { + var _datastring = JsonConvert.SerializeObject(data); + var _data = JsonConvert.DeserializeObject>(_datastring); + var _ids = _data.Select(x => x.internal_identifier).ToArray(); + + DataTable invalid = new DataTable(); + invalid.Clear(); + invalid.Columns.Add("internal_identifier"); + invalid.Columns.Add("control_number"); + + foreach (var id in ids.Except(_ids)) + { + DataRow rw = invalid.NewRow(); + + rw["internal_identifier"] = id; + + invalid.Rows.Add(rw); + } + + dt = new RequestedCNResponse(2, true, invalid, (int)Language).Message; + } + } + catch (Exception e) + { + throw e; + } + + return dt; + } + + public DataMessage SaveIntent(IntentOfPay _intent, int? errorNumber = 0, string errorMessage = null) + { + var Proxyfamily = LocalDefault.FamilyMembers(Configuration); + + List policies = new List(); + + if (_intent.policies != null) + { + policies = _intent.policies; + } + + XElement PaymentIntent = new XElement("PaymentIntent", + new XElement("Header", + new XElement("OfficerCode", _intent.enrolment_officer_code), + new XElement("RequestDate", _intent.request_date), + new XElement("PhoneNumber", _intent.phone_number), + new XElement("LanguageName", _intent.language), + new XElement("AuditUserId", -1) + ), + new XElement("Details", + policies.Select(x => + + new XElement("Detail", + new XElement("InsuranceNumber", x.insurance_number), + new XElement("ProductCode", x.insurance_product_code), + new XElement("EnrollmentDate", DateTime.UtcNow), + new XElement("IsRenewal", x.IsRenewal()) + ) + ) + ), + new XElement("ProxySettings", + new XElement("AdultMembers", Proxyfamily.Adults), + new XElement("ChildMembers", Proxyfamily.Children), + new XElement("OAdultMembers", Proxyfamily.OtherAdults), + new XElement("OChildMembers", Proxyfamily.OtherChildren) + ) + ); + + SqlParameter[] sqlParameters = { + new SqlParameter("@Xml", PaymentIntent.ToString()), + new SqlParameter("@ErrorNumber",errorNumber), + new SqlParameter("@ErrorMsg",errorMessage), + new SqlParameter("@PaymentID", SqlDbType.Int){Direction = ParameterDirection.Output }, + new SqlParameter("@ExpectedAmount", SqlDbType.Decimal){Direction = ParameterDirection.Output }, + new SqlParameter("@ProvidedAmount",_intent.amount_to_be_paid), + new SqlParameter("@PriorEnrollment",LocalDefault.PriorEnrolmentRequired(Configuration)) + }; + + DataMessage message; + + try + { + bool error = true; + var data = dh.ExecProcedure("uspInsertPaymentIntent", sqlParameters); + + var rv = int.Parse(data[2].Value.ToString()); + + if (rv == 0) + { + error = false; + } + + DataTable dt = new DataTable(); + dt.Clear(); + dt.Columns.Add("internal_identifier"); + dt.Columns.Add("control_number"); + + DataRow rw = dt.NewRow(); + var PaymentId = data[0].Value.ToString(); + rw["internal_identifier"] = PaymentId; + + dt.Rows.Add(rw); + + ExpectedAmount = decimal.Parse(data[1].Value.ToString()); + + var languages = LocalDefault.PrimaryLangReprisantations(Configuration); + + if (_intent.language == null || languages.Contains(_intent.language.ToLower())) + { + Language = Language.Primary; + } + else + { + Language = Language.Secondary; + } + + message = new SaveIntentResponse(rv, error, dt, (int)Language).Message; + GetPaymentInfo(PaymentId); + } + catch (Exception e) + { + + message = new SaveIntentResponse(e).Message; + } + + return message; + } + + public void GetPaymentInfo(string Id) + { + var sSQL = @"SELECT tblPayment.PaymentID, tblPayment.ExpectedAmount,tblPayment.LanguageName,tblPayment.TypeOfPayment, tblPaymentDetails.ExpectedAmount AS ExpectedDetailAmount, + tblPayment.ReceivedAmount, tblPayment.PaymentDate, tblInsuree.LastName, tblInsuree.OtherNames,tblPaymentDetails.InsuranceNumber,tblPayment.PhoneNumber, + tblProduct.ProductName, tblPaymentDetails.ProductCode, tblPolicy.ExpiryDate, tblPolicy.EffectiveDate,tblControlNumber.ControlNumber,tblPolicy.PolicyStatus, tblPolicy.PolicyValue - ISNULL(mp.PrPaid,0) Outstanding + FROM tblControlNumber + RIGHT OUTER JOIN tblInsuree + RIGHT OUTER JOIN tblProduct + RIGHT OUTER JOIN tblPayment + INNER JOIN tblPaymentDetails + ON tblPayment.PaymentID = tblPaymentDetails.PaymentID + ON tblProduct.ProductCode = tblPaymentDetails.ProductCode + ON tblInsuree.CHFID = tblPaymentDetails.InsuranceNumber + ON tblControlNumber.PaymentID = tblPayment.PaymentID + LEFT OUTER JOIN tblPremium + LEFT OUTER JOIN tblPolicy + LEFT OUTER JOIN ( + select P.PolicyID PolID, SUM(P.Amount) PrPaid from tblpremium P inner join tblPaymentDetails PD ON PD.PremiumID = P.PremiumId INNER JOIN tblPayment Pay ON Pay.PaymentID = PD.PaymentID where P.ValidityTo IS NULL AND Pay.PaymentStatus = 5 GROUP BY P.PolicyID + ) MP ON MP.PolID = tblPolicy.PolicyID + ON tblPremium.PolicyID = tblPolicy.PolicyID + ON tblPaymentDetails.PremiumID = tblPremium.PremiumId + WHERE (tblPayment.PaymentID = @PaymentID) AND (tblProduct.ValidityTo IS NULL) AND (tblInsuree.ValidityTo IS NULL)"; + + SqlParameter[] parameters = { + new SqlParameter("@PaymentID", Id) + }; + + try + { + var data = dh.GetDataTable(sSQL, parameters, CommandType.Text); + + if (data.Rows.Count > 0) + { + var row1 = data.Rows[0]; + PaymentId = Id; + ControlNum = row1["ControlNumber"] != System.DBNull.Value ? Convert.ToString(row1["ControlNumber"]) : null; + ExpectedAmount = row1["ExpectedAmount"] != System.DBNull.Value ? Convert.ToDecimal(row1["ExpectedAmount"]) : 0; + + var language = row1["LanguageName"] != System.DBNull.Value ? Convert.ToString(row1["LanguageName"]) : "en"; + var languages = LocalDefault.PrimaryLangReprisantations(Configuration); + + if (language == null || languages.Contains(language.ToLower())) + { + Language = Language.Primary; + } + else + { + Language = Language.Secondary; + } + typeOfPayment = row1["TypeOfPayment"] != System.DBNull.Value ? (TypeOfPayment?)Enum.Parse(typeof(TypeOfPayment), Convert.ToString(row1["TypeOfPayment"]), true) : null; + + PhoneNumber = row1["PhoneNumber"] != System.DBNull.Value ? Convert.ToString(row1["PhoneNumber"]) : null; + PaymentDate = (DateTime?)(row1["PaymentDate"] != System.DBNull.Value ? row1["PaymentDate"] : null); + PaidAmount = (decimal?)(row1["ReceivedAmount"] != System.DBNull.Value ? row1["ReceivedAmount"] : null); + OutStAmount = (decimal?)(row1["Outstanding"] != System.DBNull.Value ? row1["Outstanding"] : null); + InsureeProducts = new List(); + + for (int i = 0; i < data.Rows.Count; i++) + { + var rw = data.Rows[i]; + + bool active = false; + + if (rw["PolicyStatus"] != System.DBNull.Value && Convert.ToInt32(rw["PolicyStatus"]) == 2) + { + active = true; + } + + var othernames = rw["OtherNames"] != System.DBNull.Value ? Convert.ToString(rw["OtherNames"]) : null; + var lastname = rw["LastName"] != System.DBNull.Value ? Convert.ToString(rw["LastName"]) : null; + InsureeProducts.Add( + new InsureeProduct() + { + InsureeNumber = rw["InsuranceNumber"] != System.DBNull.Value ? Convert.ToString(rw["InsuranceNumber"]) : null, + InsureeName = othernames + " " + lastname, + ProductName = rw["ProductName"] != System.DBNull.Value ? Convert.ToString(rw["ProductName"]) : null, + ProductCode = rw["ProductCode"] != System.DBNull.Value ? Convert.ToString(rw["ProductCode"]) : null, + ExpiryDate = (DateTime?)(rw["ExpiryDate"] != System.DBNull.Value ? rw["ExpiryDate"] : null), + EffectiveDate = (DateTime?)(rw["EffectiveDate"] != System.DBNull.Value ? rw["EffectiveDate"] : null), + PolicyActivated = active, + ExpectedProductAmount = rw["ExpectedDetailAmount"] != System.DBNull.Value ? Convert.ToDecimal(rw["ExpectedDetailAmount"]) : 0 + } + ); + } + } + else + { + throw new DataException("3-Wrong Control Number"); + } + } + catch (Exception e) + { + throw e; + } + } + + public virtual decimal determineTransferFee(decimal expectedAmount, TypeOfPayment typeOfPayment) + { + return 0; + } + + public virtual bool UpdatePaymentTransferFee(string paymentId, decimal TransferFee, TypeOfPayment typeOfPayment) + { + + var sSQL = @"UPDATE tblPayment SET TypeOfPayment = @TypeOfPayment,TransferFee = @TransferFee WHERE PaymentID = @paymentId"; + + SqlParameter[] parameters = { + new SqlParameter("@paymentId", paymentId), + new SqlParameter("@TransferFee", TransferFee), + new SqlParameter("@TypeOfPayment", Enum.GetName(typeof(TypeOfPayment),typeOfPayment)) + }; + + try + { + dh.Execute(sSQL, parameters, CommandType.Text); + + return true; + } + catch (Exception) + { + return false; + } + + } + + public virtual decimal GetToBePaidAmount(decimal ExpectedAmount, decimal TransferFee) + { + decimal amount = ExpectedAmount - TransferFee; + return Math.Round(amount, 2); + } + + public virtual PostReqCNResponse PostReqControlNumber(string OfficerCode, string PaymentId, string PhoneNumber, decimal ExpectedAmount, List products, string controlNumber = null, bool acknowledge = false, bool error = false) + { + bool result = SaveControlNumberRequest(PaymentId, error); + string ctrlNumber = null; + + PostReqCNResponse response = new PostReqCNResponse() + { + + ControlNumber = ctrlNumber, + Posted = true, + ErrorCode = 0, + Assigned = error + }; + + return response; + } + + public bool SaveControlNumberRequest(string BillId, bool failed) + { + + SqlParameter[] sqlParameters = { + new SqlParameter("@PaymentID", BillId), + new SqlParameter("@Failed", failed) + }; + + try + { + var data = dh.ExecProcedure("uspRequestGetControlNumber", sqlParameters); + GetPaymentInfo(BillId); + } + catch (Exception e) + { + throw e; + } + + return true; + } + + public bool CheckControlNumber(string PaymentID, string ControlNumber) + { + var sSQL = @"SELECT * FROM tblControlNumber WHERE PaymentID != @PaymentID AND ControlNumber = @ControlNumber"; + + SqlParameter[] parameters = { + new SqlParameter("@PaymentID", PaymentID), + new SqlParameter("@ControlNumber", ControlNumber) + }; + bool result = false; + + try + { + var data = dh.GetDataTable(sSQL, parameters, CommandType.Text); + if (data.Rows.Count > 0) + { + result = true; + } + //GetPaymentInfo(PaymentID); + } + catch (Exception) + { + return false; + } + + return result; + } + + public DataMessage SaveControlNumberAkn(bool error_occured, string Comment) + { + XElement CNAcknowledgement = new XElement("ControlNumberAcknowledge", + new XElement("PaymentID", PaymentId), + new XElement("Success", Convert.ToInt32(!error_occured)), + new XElement("Comment", Comment) + ); + + SqlParameter[] sqlParameters = { + new SqlParameter("@Xml",CNAcknowledgement.ToString()) + }; + + + DataMessage message; + + try + { + var data = dh.ExecProcedure("uspAcknowledgeControlNumberRequest", sqlParameters); + message = new SaveAckResponse(int.Parse(data[0].Value.ToString()), false, (int)Language).Message; + GetPaymentInfo(PaymentId); + } + catch (Exception e) + { + + message = new SaveAckResponse(e).Message; + } + + return message; + } + + public DataMessage SaveControlNumber(string ControlNumber, bool failed) + { + SqlParameter[] sqlParameters = { + new SqlParameter("@PaymentID", PaymentId), + new SqlParameter("@ControlNumber", ControlNumber), + new SqlParameter("@Failed", failed) + }; + + DataMessage message; + + try + { + var data = dh.ExecProcedure("uspReceiveControlNumber", sqlParameters); + message = new CtrlNumberResponse(int.Parse(data[0].Value.ToString()), false, (int)Language).Message; + GetPaymentInfo(PaymentId); + } + catch (Exception e) + { + message = new CtrlNumberResponse(e).Message; + } + + return message; + } + + public DataMessage SaveControlNumber(ControlNumberResp model, bool failed) + { + SqlParameter[] sqlParameters = { + new SqlParameter("@PaymentID", model.internal_identifier), + new SqlParameter("@ControlNumber", model.control_number), + new SqlParameter("@Failed", failed) + }; + + DataMessage message; + + try + { + var data = dh.ExecProcedure("uspReceiveControlNumber", sqlParameters); + message = new CtrlNumberResponse(int.Parse(data[0].Value.ToString()), false, (int)Language).Message; + GetPaymentInfo(model.internal_identifier); + } + catch (Exception e) + { + message = new CtrlNumberResponse(e).Message; + } + + return message; + } + } +} diff --git a/OpenImis.RestApi/Controllers/V2/PaymentController.cs b/OpenImis.RestApi/Controllers/V2/PaymentController.cs new file mode 100644 index 00000000..e12f1c74 --- /dev/null +++ b/OpenImis.RestApi/Controllers/V2/PaymentController.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using OpenImis.ModulesV2; +using OpenImis.ModulesV2.PaymentModule.Helpers.Extensions; +using OpenImis.ModulesV2.PaymentModule.Models; +using OpenImis.ModulesV2.PaymentModule.Models.Response; +using OpenImis.RestApi.Security; + +namespace OpenImis.RestApi.Controllers.V2 +{ + [ApiVersion("2")] + [Authorize] + [Route("api/payment/")] + [ApiController] + public class PaymentController : Controller + { + private readonly IImisModules _imisModules; + public readonly IHostingEnvironment _hostingEnvironment; + + public PaymentController(IImisModules imisModules, IHostingEnvironment hostingEnvironment) + { + _imisModules = imisModules; + _hostingEnvironment = hostingEnvironment; + + _imisModules.GetPaymentModule().GetPaymentLogic().WebRootPath = _hostingEnvironment.WebRootPath; + _imisModules.GetPaymentModule().GetPaymentLogic().ContentRootPath = _hostingEnvironment.ContentRootPath; + } + + [HasRights(Rights.PaymentAdd)] + [HttpPost] + [Route("GetControlNumber")] + [ProducesResponseType(typeof(ErrorResponseV2), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public virtual async Task GetControlNumber([FromBody]IntentOfPay intent) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + + if (intent != null) + { + var resp = await _imisModules.GetPaymentModule().GetPaymentLogic().SaveIntent(intent, error.GetErrorNumber(), error.GetErrorMessage()); + return BadRequest(new ErrorResponseV2() { error_occured = true, error_message = error }); + } + else + { + return BadRequest(new ErrorResponseV2() { error_occured = true, error_message = "10-Uknown type of payment" }); + } + + } + + try + { + var response = await _imisModules.GetPaymentModule().GetPaymentLogic().SaveIntent(intent); + + AssignedControlNumber data = (AssignedControlNumber)response.Data; + + return Ok(new GetControlNumberResp() { error_occured = response.ErrorOccured, error_message = response.MessageValue, internal_identifier = data.internal_identifier, control_number = data.control_number }); + + } + catch (Exception e) + { + return BadRequest(new ErrorResponseV2() { error_occured = true, error_message = e.Message }); + } + } + + [HasRights(Rights.PaymentSearch)] + [HttpPost] + [Route("GetAssignedControlNumbers")] + [ProducesResponseType(typeof(AsignedControlNumbersResponse), 200)] + [ProducesResponseType(typeof(ErrorResponseV2), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public virtual async Task GetAssignedControlNumbers([FromBody]PaymentRequest requests) + { + if (!ModelState.IsValid) + { + var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; + return BadRequest(new ErrorResponseV2() { error_occured = true, error_message = error }); + } + + try + { + var response = await _imisModules.GetPaymentModule().GetPaymentLogic().GetControlNumbers(requests); + + if (response.Code == 0) + { + var controlNumbers = (List)response.Data; + return Ok(new AsignedControlNumbersResponse() { error_occured = response.ErrorOccured, assigned_control_numbers = controlNumbers }); + } + else + { + return BadRequest(new ErrorResponseV2() { error_occured = true, error_message = response.MessageValue }); + } + + } + catch (Exception) + { + return BadRequest(new ErrorResponseV2() { error_occured = true, error_message = "Unknown Error Occured" }); + } + } + } +} \ No newline at end of file From f4ad7797f9ad3fc0276023e6fab3c4ce7999f574 Mon Sep 17 00:00:00 2001 From: Dragos Dobre Date: Mon, 28 Oct 2019 16:33:32 +0100 Subject: [PATCH 82/86] Add French language --- .../Helpers/Messages/PrimaryLanguage.cs | 140 +++++++---------- .../Helpers/Messages/SecondaryLanguage.cs | 142 ++++++++---------- .../Messages/SecondaryLanguageSwahili.cs | 90 +++++++++++ 3 files changed, 207 insertions(+), 165 deletions(-) create mode 100644 OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguageSwahili.cs diff --git a/OpenImis.ModulesV2/Helpers/Messages/PrimaryLanguage.cs b/OpenImis.ModulesV2/Helpers/Messages/PrimaryLanguage.cs index 311d6528..21bd91e7 100644 --- a/OpenImis.ModulesV2/Helpers/Messages/PrimaryLanguage.cs +++ b/OpenImis.ModulesV2/Helpers/Messages/PrimaryLanguage.cs @@ -7,101 +7,67 @@ namespace OpenImis.ModulesV2.Helpers.Messages public static class PrimaryLanguage { public static string Success = "Success"; - - //CtrlNumberResponse - public static string CantAssignCN = "1-Control number cannot be assigned by the external payment gateway"; - public static string DuplicateCN = "2-Duplicate Control Number"; - - //DeleteMemberFamilyResponse - public static string WrongFormatMissingIN = "Wrong Format or Missing Insurance Number of Member"; - public static string INNotFount = "Insurance number of member not found"; - public static string MemberNotHead = "Mamber is head of family"; - - //EditFamilyResponse + public static string CantAssignCN = "1. Control number cannot be assigned by the external payment gateway."; + public static string DuplicateCN = "2. Duplicate Control Number."; + public static string WrongFormatMissingIN = "Wrong Format or Missing Insurance Number of Member."; + public static string INNotFount = "Insurance number of member not found."; + public static string MemberNotHead = "Member is not head of family."; public static string WrongOrMissingHeadIN = "Wrong Format or Missing Insurance Number of head."; - public static string HeadINNotFound = "Insurance Number of head not found."; + public static string HeadINNotFound = "Insurance number of head not found."; public static string WrongPVillageCode = "Wrong permanent village code."; - public static string WrongCVillageCode = "Wrong current village Code."; + public static string WrongCVillageCode = "Wrong current village code."; public static string WrongGender = "Wrong gender."; - public static string WrongConfirmationType = "Wrong confirmation type"; - public static string WrongGroupType = "Wrong group type"; - public static string WrongMaritalStatus = "Wrong marital status"; - public static string WrongEducation = "Wrong education"; + public static string WrongConfirmationType = "Wrong confirmation type."; + public static string WrongGroupType = "Wrong group type."; + public static string WrongMaritalStatus = "Wrong marital status."; + public static string WrongEducation = "Wrong education."; public static string WrongProfession = "Wrong profession."; - public static string FSPCodeNotFound = "FSP code not found"; - public static string WrongIdentificationType = "Wrong Identification Type"; - - //EditMemberFamilyResponse - public static string WrongINMember = "Wrong format of insurance number of member"; - public static string NotFountINMember = "Insurance number of member not found"; - public static string WrongVillageCode = "Wrong current village code"; - public static string WrongRelationship = "Wrong Relationship"; - - //EnterContributionResponse - public static string WrongOrMissingPC = "Wrong or missing product code (not existing or not applicable to the family/group)"; - public static string WrongOrMissingPayDate = "Wrong or missing payment date"; - public static string WrongContributionCat = "Wrong contribution category"; - public static string WrongOrMissingPayType = "Wrong or missing payment type"; - public static string WrongOrMissingPayer = "Wrong or missing payer"; - public static string MissingReceiptNumber = "Missing receipt no."; - public static string DuplicateReceiptNumber = "Duplicated receipt no."; - - //EnterFamilyResponse + public static string FSPCodeNotFound = "FSP code not found."; + public static string WrongIdentificationType = "Wrong identification type."; + public static string WrongINMember = "Wrong format of insurance number of member."; + public static string NotFountINMember = "Insurance number of member not found."; + public static string WrongVillageCode = "Wrong current village code."; + public static string WrongRelationship = "Wrong relationship."; + public static string WrongOrMissingPC = "Wrong or missing product code (not existing or not applicable to the family\/group)."; + public static string WrongOrMissingPayDate = "Wrong or missing payment date."; + public static string WrongContributionCat = "Wrong contribution category."; + public static string WrongOrMissingPayType = "Wrong or missing payment type."; + public static string WrongOrMissingPayer = "Wrong or missing payer."; + public static string MissingReceiptNumber = "Missing receipt number."; + public static string DuplicateReceiptNumber = "Duplicated receipt number."; public static string DuplicateINHead = "Duplicated Insurance Number of head."; public static string WrongOrMissingPVC = "Wrong or missing permanent village code."; public static string WrongOrMissingGender = "Wrong or missing gender."; public static string WrongFrOrMissingBd = "Wrong format or missing birth date."; public static string MissingLastName = "Missing last name."; - public static string MissingOtherName = "Missing other name"; - - //EnterMemberFamilyResponse - public static string DuplicatedMemberIN = "Insurance number of member duplicated "; - - //EnterPolicyResponse - public static string WrongOrMissingEnrolDate = "Wrong or missing enrolment date"; - public static string WrongOrMissingEOcode = "Wrong or missing enrolment officer code (not existing or not applicable to the family/group)"; - - //GetCoverageResponse - - //GetFamilyResponse - - //GetMemberFamilyResponse - public static string NoMemberOfOrder = "No member of the specified order number in the family/group"; - - //MatchPayResponse - public static string PayIdDoesntExist = "1-The paymentId does not exist"; - - //RenewPolicyResponse - public static string WrongOrMissingRenDate = "Wrong or missing renewal date"; - - //RequestedCNResponse - public static string WrongInternalIdFormat = "1-Wrong format of internal identifier"; - public static string InvalidInternalId = "2-Not valid internal identifier "; - - //SaveAckResponse - public static string CantPostReq = "1-Request for control number cannot be posted in the external payment gateway"; - - //SaveIntentResponse - public static string WrongFormatInsureeNo = "1-Wrong format of insurance number"; - public static string InValidINmissingPC = "2-Not valid insurance or missing product code"; - public static string InValidEOC = "3-Not valid enrolment officer code"; - public static string IncompatibleEO_PC = "4-Enrolment officer code and insurance product code are not compatible"; - public static string NoRenewalProduct = "5-Beneficiary has no policy of specified insurance product for renewal"; - public static string InsureeNoMissing = "6-Missing insurance number"; - public static string InsureeNotEnrolled = "7-Insuree not enrolled while prior enrolment mandatory."; - public static string DuplicateCNAssigned = "8-Duplicated control number assigned"; - public static string CantAssignCn2 = "9-Control number cannot be assigned"; - public static string UnknownPaymentType = "10-Uknown type of payment"; - - //SavePayResponse - public static string WrongOrMissingRecDate = "1-Wrong or missing receiving date"; - public static string WrongFormatInputData = "2-Wrong format of input data"; - public static string WrongControlNumber = "3-Wrong control_number"; - public static string WrongAmount = "4-Wrong Amount"; - public static string DuplicatePayAmount = "5-Duplicate Payment Amount"; - public static string DoesntExistEO = "6-Enrolment Officer Code does not exist"; - public static string DoesntExistPC = "7-Product Code Does not Exist"; - public static string NoPolicyForRenewal = "8-Beneficiary has no policy of specified insurance product for renewal"; - public static string UnknownTypeOfPay = "9-Uknown type of payment"; + public static string MissingOtherName = "Missing other name."; + public static string DuplicatedMemberIN = "Insurance number of member duplicated."; + public static string WrongOrMissingEnrolDate = "Wrong or missing enrollment date."; + public static string WrongOrMissingEOcode = "Wrong or missing enrollment officer code (not existing or not applicable to the family\/group)."; + public static string NoMemberOfOrder = "No member of the specified order number in the family\/group."; + public static string PayIdDoesntExist = "1. The payment identifier does not exist."; + public static string WrongOrMissingRenDate = "Wrong or missing renewal date."; + public static string WrongInternalIdFormat = "1. Wrong format of internal identifier."; + public static string InvalidInternalId = "2. Not valid internal identifier."; + public static string CantPostReq = "1. Request for control number cannot be posted in the external payment gateway."; + public static string WrongFormatInsureeNo = "1. Wrong format of insurance number."; + public static string InValidINmissingPC = "2. Not valid insurance or missing product code."; + public static string InValidEOC = "3. Not valid enrollment officer code."; + public static string IncompatibleEO_PC = "4. Enrollment officer code and insurance product code are not compatible."; + public static string NoRenewalProduct = "5. Beneficiary has no policy of specified insurance product for renewal."; + public static string InsureeNoMissing = "6. Missing insurance number."; + public static string InsureeNotEnrolled = "7. Insuree not enrolled while prior enrollment mandatory."; + public static string DuplicateCNAssigned = "8. Duplicated control number assigned."; + public static string CantAssignCn2 = "9. Control number cannot be assigned."; + public static string UnknownPaymentType = "10. Unknown type of payment."; + public static string WrongOrMissingRecDate = "1. Wrong or missing receiving date."; + public static string WrongFormatInputData = "2. Wrong format of input data."; + public static string WrongControlNumber = "3. Wrong control number."; + public static string WrongAmount = "4. Wrong amount."; + public static string DuplicatePayAmount = "5. Duplicate Payment Amount."; + public static string DoesntExistEO = "6. Enrollment Officer Code does not exist."; + public static string DoesntExistPC = "7. Product Code Does not Exist."; + public static string NoPolicyForRenewal = "8. Beneficiary has no policy of specified insurance product for renewal."; + public static string UnknownTypeOfPay = "9. Unknown type of payment." } } diff --git a/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguage.cs b/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguage.cs index e535aa11..5bacd7e5 100644 --- a/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguage.cs +++ b/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguage.cs @@ -6,83 +6,69 @@ namespace OpenImis.ModulesV2.Helpers.Messages { public static class SecondaryLanguage { - public static string Success = "Imefanikiwa"; - - public static string CantAssignCN = "1-Na. ya ankara imeshindikana kutotelewa na mfumo wa malipo"; - public static string DuplicateCN = "2-Na. ya ankara imejirudia"; - - public static string WrongFormatMissingIN = "Umekosea namba ya mwanachama au namba haipo"; - public static string INNotFount = "Namba ya mwanachama haipo"; - public static string MemberNotHead = "Mwanachama ni mkuu wa kaya"; - - public static string WrongOrMissingHeadIN = "Umekosea namba ya mkuu wa kaya au namba haipo"; - public static string HeadINNotFound = "Namba ya mkuu wa kaya haipo"; - public static string WrongPVillageCode = "Umekosea namba ya kijiji"; - public static string WrongCVillageCode = "Umekosea namba ya kijiji"; - public static string WrongGender = "Umekosea jinsia"; - public static string WrongConfirmationType = "Wrong confirmation type"; - public static string WrongGroupType = "Umekosea aina ya kundi"; - public static string WrongMaritalStatus = "Umekosea hali ya ndoa"; - public static string WrongEducation = "Umekosea elimu"; - public static string WrongProfession = "Umekosea elimu"; - public static string FSPCodeNotFound = "Na. ya FSP haipo"; - public static string WrongIdentificationType = "Umekosea aina ya kitambulisho"; - - public static string WrongINMember = "Umekosea namba ya mwanachama"; - public static string NotFountINMember = "Namba ya mwanachama haipo kwenye kompuyta kuu"; - public static string WrongVillageCode = "Umekosea namba ya kijiji"; - public static string WrongRelationship = "Umekosea uhusiano"; - - public static string WrongOrMissingPC = "Umekosea namba ya bidhaa au haitumiki kwenye familia husika"; - public static string WrongOrMissingPayDate = "Umekosea tarehe ya malipo"; - public static string WrongContributionCat = "Umekosea kundi la malipo"; - public static string WrongOrMissingPayType = "Umekosea aina ya malipo"; - public static string WrongOrMissingPayer = "Umekosea mlipaji"; - public static string MissingReceiptNumber = "Jaza namba ya risiti"; - public static string DuplicateReceiptNumber = "Namba ya risiti imejirudia"; - - public static string DuplicateINHead = "Namba ya mwachama imejirudia"; - public static string WrongOrMissingPVC = "Umekosea/Jaza namba ya kijiji"; - public static string WrongOrMissingGender = "Umekosea/Jaza Jinsia"; - public static string WrongFrOrMissingBd = "Jaza/Umekosea tarehe"; - public static string MissingLastName = "Jaza jina la ukoo"; - public static string MissingOtherName = "Jaza majina mengine"; - - public static string DuplicatedMemberIN = "Namba ya mwanachama imejirudia"; - - public static string WrongOrMissingEnrolDate = "Jaza/Umekosea tarehe ya kujiunga"; - public static string WrongOrMissingEOcode = "Jaza/Umekosea namba ya msimbo ya afisa mwandikishaji"; - - public static string NoMemberOfOrder = "Na ya mwanchama kwenye familia haipo"; - public static string PayIdDoesntExist = "1-Namba ya malipo haipo"; - - public static string WrongOrMissingRenDate = "Jaza/Umekosea tarehe ya kuhuisha"; - - public static string WrongInternalIdFormat = "1-Wrong format of internal identifier"; - public static string InvalidInternalId = "2-Not valid internal identifier "; - - public static string CantPostReq = "1-Maombi ya Na. ya ankara yameshindikana, jaribu tena"; - - public static string WrongFormatInsureeNo = "1-Namba ya mwanachama imekosewa"; - public static string InValidINmissingPC = "2-Umekosea namba ya mwanachama au namba ya bidhaa"; - public static string InValidEOC = "3-Umekosea namba ya msimbo ya afisa mwandikishaji"; - public static string IncompatibleEO_PC = "4-Namba ya mwanachama na namba ya bidhaa haviendani"; - public static string NoRenewalProduct = "5-Mwanachama hajajiunga na bidhaa husika"; - - public static string InsureeNoMissing = "6-Jaza namba ya mwanachama"; - public static string InsureeNotEnrolled = "7-Insuree not enrolled while prior enrolment mandatory."; - public static string DuplicateCNAssigned = "8-Umepatiwa namba ya ankara iliyojirudia, jaribu tena"; - public static string CantAssignCn2 = "9-Na. ya ankara imeshishindikana kutolewa, jaribu tena"; - public static string UnknownPaymentType = "10-Aina ya malipo uliyochagua hayapo"; - - public static string WrongOrMissingRecDate = "1-Umekosea tarehe ya kupokea"; - public static string WrongFormatInputData = "2-Umekosea taarifa uliyojaza"; - public static string WrongControlNumber = "3-Umekosea Na. ya ankara"; - public static string WrongAmount = "4-Umekosea kiasi"; - public static string DuplicatePayAmount = "5-Umerudia malipo"; - public static string DoesntExistEO = "6-Namba ya msimbo ya afisa mwandikishaji haipo"; - public static string DoesntExistPC = "7-Namba ya bidhaa haipo"; - public static string NoPolicyForRenewal = "8-Mwanachama hajajiunga na bidhaa husika"; - public static string UnknownTypeOfPay = "9-Aina ya malipo uliyochagua haipo"; + // French error messages + public static string Success = "Succès"; + public static string CantAssignCN = "1. Le numéro de contrôle ne peut être assigné par le portail de paiement externe."; + public static string DuplicateCN = "2. Le numéro de contrôle déjà utilisé."; + public static string WrongFormatMissingIN = "Le numéro d’assuré a un format incorrect ou est manquant."; + public static string INNotFount = "Numéro d’assuré du membre introuvable."; + public static string MemberNotHead = "Le membre n'est pas le chef de famille."; + public static string WrongOrMissingHeadIN = "Numéro d’assuré du chef de famille a un mauvais format ou est manquant."; + public static string HeadINNotFound = "Numéro d’assuré du chef de famille est introuvable."; + public static string WrongPVillageCode = "Le code du village permanent incorrect."; + public static string WrongCVillageCode = "Le code du village incorrect."; + public static string WrongGender = "Mauvais genre."; + public static string WrongConfirmationType = "Type de confirmation incorrect."; + public static string WrongGroupType = "Type de groupe incorrect."; + public static string WrongMaritalStatus = "Statut matrimonial incorrect."; + public static string WrongEducation = "Éducation incorrecte."; + public static string WrongProfession = "Profession incorrecte."; + public static string FSPCodeNotFound = "Code FSP introuvable."; + public static string WrongIdentificationType = "Type d’Identification incorrect."; + public static string WrongINMember = "Mauvais format du numéro d’assuré du membre."; + public static string NotFountINMember = "Numéro d’assuré de membre introuvable."; + public static string WrongVillageCode = "Code du village erroné."; + public static string WrongRelationship = "Relation erronée."; + public static string WrongOrMissingPC = "Code produit erroné ou manquant (non existant ou sans objet pour la famille\/groupe)"; + public static string WrongOrMissingPayDate = "Date de paiement erroné ou manquante."; + public static string WrongContributionCat = "Catégorie de contribution erronée."; + public static string WrongOrMissingPayType = "Type de paiement erroné ou manquant."; + public static string WrongOrMissingPayer = "Donneur d’ordre erroné ou manquant."; + public static string MissingReceiptNumber = "Numéro de reçu manquant."; + public static string DuplicateReceiptNumber = "Numéro de reçu déjà utilisé."; + public static string DuplicateINHead = "Numéro d'assuré du chef de famille déjà utilisé."; + public static string WrongOrMissingPVC = "Code permanent du village manquant."; + public static string WrongOrMissingGender = "Genre erroné ou manquant."; + public static string WrongFrOrMissingBd = "Format de la date de naissance incorrect ou manquant."; + public static string MissingLastName = "Nom de famille manquant."; + public static string MissingOtherName = "Autre nom manquant."; + public static string DuplicatedMemberIN = "Numéro d'assurance du membre déjà utilisé."; + public static string WrongOrMissingEnrolDate = "Date d’inscription incorrecte ou absente."; + public static string WrongOrMissingEOcode = "Code d’agent d'adhésion incorrecte ou absente (non existant ou non applicable à la famille\/groupe)"; + public static string NoMemberOfOrder = "Aucun membre de l'ordre spécifié est dans cette famille\/groupe."; + public static string PayIdDoesntExist = "1. L'identifiant de payement n’existe pas."; + public static string WrongOrMissingRenDate = "Date de renouvellement erroné ou manquante."; + public static string WrongInternalIdFormat = "1. Mauvais format de l'identificateur interne."; + public static string InvalidInternalId = "2. L'identificateur interne n’est pas valide."; + public static string CantPostReq = "1. La demande de numéro de contrôle ne pas pu être envoyée à la passerelle de paiement externe."; + public static string WrongFormatInsureeNo = "1. Mauvais format de numéro d’assurance."; + public static string InValidINmissingPC = "2. Assurance non valide ou produit manquant."; + public static string InValidEOC = "3. Code d'agent d'adhésion non valide."; + public static string IncompatibleEO_PC = "4. Le code d'agent d'adhésion et le code du produit d’assurance ne sont pas compatibles."; + public static string NoRenewalProduct = "5. Le bénéficiaire n’a aucune police d'assurance.pour le produit spécifié lors de la demande de renouvellement."; + public static string InsureeNoMissing = "6. Numéro d’assuré manquant."; + public static string InsureeNotEnrolled = "7. Inscription préalable de l'assuré obligatoire."; + public static string DuplicateCNAssigned = "8. Numéro de contrôle attribué déjà utilisé."; + public static string CantAssignCn2 = "9. Numéro de contrôle ne peut pas être assigné."; + public static string UnknownPaymentType = "10. Type de paiement inconnue."; + public static string WrongOrMissingRecDate = "1. Date de réception fausse ou manquante."; + public static string WrongFormatInputData = "2. Mauvais format des données d'entrée."; + public static string WrongControlNumber = "3. Numéro de contrôle incorrect."; + public static string WrongAmount = "4. Montant incorrect."; + public static string DuplicatePayAmount = "5. Montant du paiement en double."; + public static string DoesntExistEO = "6. Le code de l'agent d'inscription n’existe pas."; + public static string DoesntExistPC = "7. Le code produit n’existe pas."; + public static string NoPolicyForRenewal = "8. Le bénéficiaire n’a aucune police d'assurance spécifiée pour le renouvellement du produit."; + public static string UnknownTypeOfPay = "9. Type de paiement inconnu." } } diff --git a/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguageSwahili.cs b/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguageSwahili.cs new file mode 100644 index 00000000..a26c127c --- /dev/null +++ b/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguageSwahili.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenImis.ModulesV2.Helpers.Messages +{ + public static class SecondaryLanguageSwahili + { + // Swahili error message + // To use this list, rename the file and class to SecondaryLanguage (replace the French translation) + public static string Success = "Imefanikiwa"; + + public static string CantAssignCN = "1-Na. ya ankara imeshindikana kutotelewa na mfumo wa malipo"; + public static string DuplicateCN = "2-Na. ya ankara imejirudia"; + + public static string WrongFormatMissingIN = "Umekosea namba ya mwanachama au namba haipo"; + public static string INNotFount = "Namba ya mwanachama haipo"; + public static string MemberNotHead = "Mwanachama ni mkuu wa kaya"; + + public static string WrongOrMissingHeadIN = "Umekosea namba ya mkuu wa kaya au namba haipo"; + public static string HeadINNotFound = "Namba ya mkuu wa kaya haipo"; + public static string WrongPVillageCode = "Umekosea namba ya kijiji"; + public static string WrongCVillageCode = "Umekosea namba ya kijiji"; + public static string WrongGender = "Umekosea jinsia"; + public static string WrongConfirmationType = "Wrong confirmation type"; + public static string WrongGroupType = "Umekosea aina ya kundi"; + public static string WrongMaritalStatus = "Umekosea hali ya ndoa"; + public static string WrongEducation = "Umekosea elimu"; + public static string WrongProfession = "Umekosea elimu"; + public static string FSPCodeNotFound = "Na. ya FSP haipo"; + public static string WrongIdentificationType = "Umekosea aina ya kitambulisho"; + + public static string WrongINMember = "Umekosea namba ya mwanachama"; + public static string NotFountINMember = "Namba ya mwanachama haipo kwenye kompuyta kuu"; + public static string WrongVillageCode = "Umekosea namba ya kijiji"; + public static string WrongRelationship = "Umekosea uhusiano"; + + public static string WrongOrMissingPC = "Umekosea namba ya bidhaa au haitumiki kwenye familia husika"; + public static string WrongOrMissingPayDate = "Umekosea tarehe ya malipo"; + public static string WrongContributionCat = "Umekosea kundi la malipo"; + public static string WrongOrMissingPayType = "Umekosea aina ya malipo"; + public static string WrongOrMissingPayer = "Umekosea mlipaji"; + public static string MissingReceiptNumber = "Jaza namba ya risiti"; + public static string DuplicateReceiptNumber = "Namba ya risiti imejirudia"; + + public static string DuplicateINHead = "Namba ya mwachama imejirudia"; + public static string WrongOrMissingPVC = "Umekosea/Jaza namba ya kijiji"; + public static string WrongOrMissingGender = "Umekosea/Jaza Jinsia"; + public static string WrongFrOrMissingBd = "Jaza/Umekosea tarehe"; + public static string MissingLastName = "Jaza jina la ukoo"; + public static string MissingOtherName = "Jaza majina mengine"; + + public static string DuplicatedMemberIN = "Namba ya mwanachama imejirudia"; + + public static string WrongOrMissingEnrolDate = "Jaza/Umekosea tarehe ya kujiunga"; + public static string WrongOrMissingEOcode = "Jaza/Umekosea namba ya msimbo ya afisa mwandikishaji"; + + public static string NoMemberOfOrder = "Na ya mwanchama kwenye familia haipo"; + public static string PayIdDoesntExist = "1-Namba ya malipo haipo"; + + public static string WrongOrMissingRenDate = "Jaza/Umekosea tarehe ya kuhuisha"; + + public static string WrongInternalIdFormat = "1-Wrong format of internal identifier"; + public static string InvalidInternalId = "2-Not valid internal identifier "; + + public static string CantPostReq = "1-Maombi ya Na. ya ankara yameshindikana, jaribu tena"; + + public static string WrongFormatInsureeNo = "1-Namba ya mwanachama imekosewa"; + public static string InValidINmissingPC = "2-Umekosea namba ya mwanachama au namba ya bidhaa"; + public static string InValidEOC = "3-Umekosea namba ya msimbo ya afisa mwandikishaji"; + public static string IncompatibleEO_PC = "4-Namba ya mwanachama na namba ya bidhaa haviendani"; + public static string NoRenewalProduct = "5-Mwanachama hajajiunga na bidhaa husika"; + + public static string InsureeNoMissing = "6-Jaza namba ya mwanachama"; + public static string InsureeNotEnrolled = "7-Insuree not enrolled while prior enrolment mandatory."; + public static string DuplicateCNAssigned = "8-Umepatiwa namba ya ankara iliyojirudia, jaribu tena"; + public static string CantAssignCn2 = "9-Na. ya ankara imeshishindikana kutolewa, jaribu tena"; + public static string UnknownPaymentType = "10-Aina ya malipo uliyochagua hayapo"; + + public static string WrongOrMissingRecDate = "1-Umekosea tarehe ya kupokea"; + public static string WrongFormatInputData = "2-Umekosea taarifa uliyojaza"; + public static string WrongControlNumber = "3-Umekosea Na. ya ankara"; + public static string WrongAmount = "4-Umekosea kiasi"; + public static string DuplicatePayAmount = "5-Umerudia malipo"; + public static string DoesntExistEO = "6-Namba ya msimbo ya afisa mwandikishaji haipo"; + public static string DoesntExistPC = "7-Namba ya bidhaa haipo"; + public static string NoPolicyForRenewal = "8-Mwanachama hajajiunga na bidhaa husika"; + public static string UnknownTypeOfPay = "9-Aina ya malipo uliyochagua haipo"; + } +} From e241a0e830471e0f36e3e25804ff71eb85e0c78a Mon Sep 17 00:00:00 2001 From: bkaminski Date: Tue, 29 Oct 2019 13:45:42 +0100 Subject: [PATCH 83/86] OS-42: Changes in Payment --- .../PaymentModule/Helpers/SMS/ImisBaseSms.cs | 15 ++++++++++----- .../PaymentModule/Models/IntentOfPay.cs | 2 +- .../PaymentModule/Models/PaymentDetail.cs | 4 ++-- .../PaymentModule/Models/Request.cs | 2 +- OpenImis.RestApi/appsettings.json | 13 ++++++++----- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/OpenImis.ModulesV2/PaymentModule/Helpers/SMS/ImisBaseSms.cs b/OpenImis.ModulesV2/PaymentModule/Helpers/SMS/ImisBaseSms.cs index 34a58282..03df936d 100644 --- a/OpenImis.ModulesV2/PaymentModule/Helpers/SMS/ImisBaseSms.cs +++ b/OpenImis.ModulesV2/PaymentModule/Helpers/SMS/ImisBaseSms.cs @@ -13,17 +13,22 @@ namespace OpenImis.ModulesV2.PaymentModule.Helpers.SMS { public class ImisBaseSms { - private string SmsTampletes = string.Empty; + private string SmsTemplates = string.Empty; private string webRootPath; + private string smsGateWay; public ImisBaseSms(IConfiguration config, string webRootPath, string contentRootPath, Language language = Language.Primary) { this.webRootPath = webRootPath; + smsGateWay = config["SmsGateWay"]; + + var smsStrings = config["AppSettings:SmsStrings"]; + var smsStringsSecondary = config["AppSettings:SmsStringsSecondary"]; if (language == Language.Primary) - SmsTampletes = contentRootPath + @"\Escape\Sms\Strings\"; + SmsTemplates = contentRootPath + smsStrings; else - SmsTampletes = contentRootPath + @"\Escape\Sms\StringsSecondaryLanguage\"; + SmsTemplates = contentRootPath + smsStringsSecondary; } public virtual async Task SendSMS(List containers, string filename) @@ -38,7 +43,7 @@ public virtual async Task SendSMS(List containers, string try { - var response = await client.PostAsync("url", content); + var response = await client.PostAsync(smsGateWay, content); var ret = await response.Content.ReadAsStringAsync(); response_message = ret; } @@ -68,7 +73,7 @@ public virtual void SaveMessage(string message, string name) public virtual string GetMessage(string filename) { - string text = File.ReadAllText(SmsTampletes + filename + ".txt", Encoding.UTF8); + string text = File.ReadAllText(SmsTemplates + filename + ".txt", Encoding.UTF8); return text; } diff --git a/OpenImis.ModulesV2/PaymentModule/Models/IntentOfPay.cs b/OpenImis.ModulesV2/PaymentModule/Models/IntentOfPay.cs index 327c01e9..2534027b 100644 --- a/OpenImis.ModulesV2/PaymentModule/Models/IntentOfPay.cs +++ b/OpenImis.ModulesV2/PaymentModule/Models/IntentOfPay.cs @@ -5,7 +5,7 @@ namespace OpenImis.ModulesV2.PaymentModule.Models { public class IntentOfPay { - [Required(ErrorMessage = "9: Phone number not provided")] + [Required(ErrorMessage = "9-Phone number not provided")] public virtual string phone_number { get; set; } [DataType(DataType.DateTime)] public string request_date { get; set; } diff --git a/OpenImis.ModulesV2/PaymentModule/Models/PaymentDetail.cs b/OpenImis.ModulesV2/PaymentModule/Models/PaymentDetail.cs index 20dee78b..9beef563 100644 --- a/OpenImis.ModulesV2/PaymentModule/Models/PaymentDetail.cs +++ b/OpenImis.ModulesV2/PaymentModule/Models/PaymentDetail.cs @@ -5,9 +5,9 @@ namespace OpenImis.ModulesV2.PaymentModule.Models public class PaymentDetail { public string insurance_number { get; set; } - [Required(ErrorMessage = "2:Not valid insurance or missing product code")] + [Required(ErrorMessage = "2-Not valid insurance or missing product code")] public string insurance_product_code { get; set; } - [Required(ErrorMessage = "10:EnrolmentType was not provided")] + [Required(ErrorMessage = "10-EnrolmentType was not provided")] [Range(0, 2)] public EnrolmentType? renewal { get; set; } public int IsRenewal() diff --git a/OpenImis.ModulesV2/PaymentModule/Models/Request.cs b/OpenImis.ModulesV2/PaymentModule/Models/Request.cs index 5b75d519..e69ea857 100644 --- a/OpenImis.ModulesV2/PaymentModule/Models/Request.cs +++ b/OpenImis.ModulesV2/PaymentModule/Models/Request.cs @@ -4,7 +4,7 @@ namespace OpenImis.ModulesV2.PaymentModule.Models { public class Request { - [Required(ErrorMessage = "1- Wrong format of internal identifier")] + [Required(ErrorMessage = "1-Wrong format of internal identifier")] public string internal_identifier { get; set; } } } diff --git a/OpenImis.RestApi/appsettings.json b/OpenImis.RestApi/appsettings.json index db0a7fb0..33fe948f 100644 --- a/OpenImis.RestApi/appsettings.json +++ b/OpenImis.RestApi/appsettings.json @@ -1,7 +1,7 @@ { - "JwtIssuer": "http://openimis.org", - "JwtAudience": "http://openimis.org", - "JwtExpireDays": 5, + "JwtIssuer": "http://openimis.org", + "JwtAudience": "http://openimis.org", + "JwtExpireDays": 5, "Logging": { "IncludeScopes": false, "Debug": { @@ -27,6 +27,9 @@ "Extracts_Offline": "\\Extracts\\Offline\\", "JsonDebugFolder": "\\FromPhone\\Enrollment\\Debug\\", "SubmittedFolder": "\\Images\\Submitted\\", - "UpdatedFolder": "\\Images\\Updated\\" - } + "UpdatedFolder": "\\Images\\Updated\\", + "SmsStrings": "\\Escape\\Sms\\Strings\\", + "SmsStringsSecondary": "\\Escape\\Sms\\StringsSecondaryLanguage\\" + }, + "SmsGateWay": null } From 387f61816569e996595a457ae1988f170aa96d17 Mon Sep 17 00:00:00 2001 From: Dragos Dobre Date: Tue, 29 Oct 2019 16:23:36 +0100 Subject: [PATCH 84/86] Fix languages --- OpenImis.ModulesV2/Helpers/Messages/PrimaryLanguage.cs | 8 ++++---- OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguage.cs | 8 ++++---- .../Properties/PublishProfiles/FolderProfile.pubxml | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/OpenImis.ModulesV2/Helpers/Messages/PrimaryLanguage.cs b/OpenImis.ModulesV2/Helpers/Messages/PrimaryLanguage.cs index 21bd91e7..3d665e51 100644 --- a/OpenImis.ModulesV2/Helpers/Messages/PrimaryLanguage.cs +++ b/OpenImis.ModulesV2/Helpers/Messages/PrimaryLanguage.cs @@ -28,7 +28,7 @@ public static class PrimaryLanguage public static string NotFountINMember = "Insurance number of member not found."; public static string WrongVillageCode = "Wrong current village code."; public static string WrongRelationship = "Wrong relationship."; - public static string WrongOrMissingPC = "Wrong or missing product code (not existing or not applicable to the family\/group)."; + public static string WrongOrMissingPC = "Wrong or missing product code (not existing or not applicable to the family/group)."; public static string WrongOrMissingPayDate = "Wrong or missing payment date."; public static string WrongContributionCat = "Wrong contribution category."; public static string WrongOrMissingPayType = "Wrong or missing payment type."; @@ -43,8 +43,8 @@ public static class PrimaryLanguage public static string MissingOtherName = "Missing other name."; public static string DuplicatedMemberIN = "Insurance number of member duplicated."; public static string WrongOrMissingEnrolDate = "Wrong or missing enrollment date."; - public static string WrongOrMissingEOcode = "Wrong or missing enrollment officer code (not existing or not applicable to the family\/group)."; - public static string NoMemberOfOrder = "No member of the specified order number in the family\/group."; + public static string WrongOrMissingEOcode = "Wrong or missing enrollment officer code (not existing or not applicable to the family/group)."; + public static string NoMemberOfOrder = "No member of the specified order number in the family/group."; public static string PayIdDoesntExist = "1. The payment identifier does not exist."; public static string WrongOrMissingRenDate = "Wrong or missing renewal date."; public static string WrongInternalIdFormat = "1. Wrong format of internal identifier."; @@ -68,6 +68,6 @@ public static class PrimaryLanguage public static string DoesntExistEO = "6. Enrollment Officer Code does not exist."; public static string DoesntExistPC = "7. Product Code Does not Exist."; public static string NoPolicyForRenewal = "8. Beneficiary has no policy of specified insurance product for renewal."; - public static string UnknownTypeOfPay = "9. Unknown type of payment." + public static string UnknownTypeOfPay = "9. Unknown type of payment."; } } diff --git a/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguage.cs b/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguage.cs index 5bacd7e5..d7a05eed 100644 --- a/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguage.cs +++ b/OpenImis.ModulesV2/Helpers/Messages/SecondaryLanguage.cs @@ -29,7 +29,7 @@ public static class SecondaryLanguage public static string NotFountINMember = "Numéro d’assuré de membre introuvable."; public static string WrongVillageCode = "Code du village erroné."; public static string WrongRelationship = "Relation erronée."; - public static string WrongOrMissingPC = "Code produit erroné ou manquant (non existant ou sans objet pour la famille\/groupe)"; + public static string WrongOrMissingPC = "Code produit erroné ou manquant (non existant ou sans objet pour la famille/groupe)"; public static string WrongOrMissingPayDate = "Date de paiement erroné ou manquante."; public static string WrongContributionCat = "Catégorie de contribution erronée."; public static string WrongOrMissingPayType = "Type de paiement erroné ou manquant."; @@ -44,8 +44,8 @@ public static class SecondaryLanguage public static string MissingOtherName = "Autre nom manquant."; public static string DuplicatedMemberIN = "Numéro d'assurance du membre déjà utilisé."; public static string WrongOrMissingEnrolDate = "Date d’inscription incorrecte ou absente."; - public static string WrongOrMissingEOcode = "Code d’agent d'adhésion incorrecte ou absente (non existant ou non applicable à la famille\/groupe)"; - public static string NoMemberOfOrder = "Aucun membre de l'ordre spécifié est dans cette famille\/groupe."; + public static string WrongOrMissingEOcode = "Code d’agent d'adhésion incorrecte ou absente (non existant ou non applicable à la famille/groupe)"; + public static string NoMemberOfOrder = "Aucun membre de l'ordre spécifié est dans cette famille/groupe."; public static string PayIdDoesntExist = "1. L'identifiant de payement n’existe pas."; public static string WrongOrMissingRenDate = "Date de renouvellement erroné ou manquante."; public static string WrongInternalIdFormat = "1. Mauvais format de l'identificateur interne."; @@ -69,6 +69,6 @@ public static class SecondaryLanguage public static string DoesntExistEO = "6. Le code de l'agent d'inscription n’existe pas."; public static string DoesntExistPC = "7. Le code produit n’existe pas."; public static string NoPolicyForRenewal = "8. Le bénéficiaire n’a aucune police d'assurance spécifiée pour le renouvellement du produit."; - public static string UnknownTypeOfPay = "9. Type de paiement inconnu." + public static string UnknownTypeOfPay = "9. Type de paiement inconnu."; } } diff --git a/OpenImis.RestApi/Properties/PublishProfiles/FolderProfile.pubxml b/OpenImis.RestApi/Properties/PublishProfiles/FolderProfile.pubxml index 9c077809..8052570a 100644 --- a/OpenImis.RestApi/Properties/PublishProfiles/FolderProfile.pubxml +++ b/OpenImis.RestApi/Properties/PublishProfiles/FolderProfile.pubxml @@ -17,7 +17,7 @@ by editing this MSBuild file. In order to learn more about this please visit htt fd2d14ee-4549-4249-bbff-3254bcec4b5e true <_IsPortable>false - C:\Dragos\projects\openimis\Github\Published\RestApi + ..\..\Published\RestApi True \ No newline at end of file From 0e28e1bde79f973be2b2f94462da45a3dcee300f Mon Sep 17 00:00:00 2001 From: Dragos Dobre Date: Tue, 19 Nov 2019 15:56:42 +0100 Subject: [PATCH 85/86] Upgrade netcore2.2 --- OpenImis.DB.SqlServer/ImisDB.cs | 2 +- OpenImis.DB.SqlServer/OpenImis.DB.SqlServer.csproj | 2 +- OpenImis.ModulesV1/OpenImis.ModulesV1.csproj | 2 +- OpenImis.ModulesV2/OpenImis.ModulesV2.csproj | 2 +- OpenImis.RestApi.IntegrationTests/LoginTests.cs | 2 +- .../OpenImis.RestApi.IntegrationTests.csproj | 4 ++-- OpenImis.RestApi/OpenImis.RestApi.csproj | 12 ++++++------ OpenImis.RestApi/Program.cs | 9 ++++++++- .../Properties/PublishProfiles/FolderProfile.pubxml | 6 +++--- 9 files changed, 24 insertions(+), 17 deletions(-) diff --git a/OpenImis.DB.SqlServer/ImisDB.cs b/OpenImis.DB.SqlServer/ImisDB.cs index 215be062..ca3be38d 100644 --- a/OpenImis.DB.SqlServer/ImisDB.cs +++ b/OpenImis.DB.SqlServer/ImisDB.cs @@ -16,7 +16,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) .AddJsonFile($"appsettings.json") //.AddJsonFile(Environment.GetEnvironmentVariable("REGISTRY_CONFIG_FILE")) //.AddJsonFile("appsettings.json") - .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: true, reloadOnChange: true) + .AddJsonFile(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")!=null?$"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json": "appsettings.Production.json", optional: false, reloadOnChange: true) .Build(); optionsBuilder.UseSqlServer(configuration.GetConnectionString("IMISDatabase")); diff --git a/OpenImis.DB.SqlServer/OpenImis.DB.SqlServer.csproj b/OpenImis.DB.SqlServer/OpenImis.DB.SqlServer.csproj index 902988e7..d9caea82 100644 --- a/OpenImis.DB.SqlServer/OpenImis.DB.SqlServer.csproj +++ b/OpenImis.DB.SqlServer/OpenImis.DB.SqlServer.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp2.2 diff --git a/OpenImis.ModulesV1/OpenImis.ModulesV1.csproj b/OpenImis.ModulesV1/OpenImis.ModulesV1.csproj index 06613e64..3fa79728 100644 --- a/OpenImis.ModulesV1/OpenImis.ModulesV1.csproj +++ b/OpenImis.ModulesV1/OpenImis.ModulesV1.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp2.2 diff --git a/OpenImis.ModulesV2/OpenImis.ModulesV2.csproj b/OpenImis.ModulesV2/OpenImis.ModulesV2.csproj index 633ec930..3f4155af 100644 --- a/OpenImis.ModulesV2/OpenImis.ModulesV2.csproj +++ b/OpenImis.ModulesV2/OpenImis.ModulesV2.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1 + netcoreapp2.2 diff --git a/OpenImis.RestApi.IntegrationTests/LoginTests.cs b/OpenImis.RestApi.IntegrationTests/LoginTests.cs index e4554020..db7184d6 100644 --- a/OpenImis.RestApi.IntegrationTests/LoginTests.cs +++ b/OpenImis.RestApi.IntegrationTests/LoginTests.cs @@ -2,7 +2,7 @@ using FluentAssertions.Json; using Newtonsoft.Json.Linq; using OpenImis.RestApi.IntegrationTests.Helpers; -using OpenImis.RestApi.Protocol.LoginModel; +using OpenImis.RestApi.Protocol.LoginModels; using System; using System.Net; using System.Net.Http; diff --git a/OpenImis.RestApi.IntegrationTests/OpenImis.RestApi.IntegrationTests.csproj b/OpenImis.RestApi.IntegrationTests/OpenImis.RestApi.IntegrationTests.csproj index 3582498a..cc927349 100644 --- a/OpenImis.RestApi.IntegrationTests/OpenImis.RestApi.IntegrationTests.csproj +++ b/OpenImis.RestApi.IntegrationTests/OpenImis.RestApi.IntegrationTests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp2.2 false @@ -28,8 +28,8 @@ PreserveNewest - Always PreserveNewest + Never diff --git a/OpenImis.RestApi/OpenImis.RestApi.csproj b/OpenImis.RestApi/OpenImis.RestApi.csproj index 4be1c80e..e533a9ec 100644 --- a/OpenImis.RestApi/OpenImis.RestApi.csproj +++ b/OpenImis.RestApi/OpenImis.RestApi.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1 + netcoreapp2.2 aspnet-ImisRestApi-0F650C61-A020-4549-AC0C-C49F0334E2D7 false {0F650C61-A020-4549-AC0C-C49F0334E2D7} @@ -50,16 +50,16 @@ + - + - - + @@ -75,10 +75,10 @@ - Always + Never - Never + Always Always diff --git a/OpenImis.RestApi/Program.cs b/OpenImis.RestApi/Program.cs index f34065af..61cc6fbd 100644 --- a/OpenImis.RestApi/Program.cs +++ b/OpenImis.RestApi/Program.cs @@ -43,7 +43,14 @@ public static IWebHostBuilder GetWebHostBuilder(string appRootPath, string[] arg //config.AddOpenImisConfig(secretsMode, "REGISTRY_CONFIG_FILE"); //config.AddOpenImisConfig(SecretsMode.LocalFile, $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json"); config.AddJsonFile($"appsettings.json", optional: false, reloadOnChange: true); - config.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: false, reloadOnChange: true); + if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") != null) + { + config.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: false, reloadOnChange: true); + } + else + { + config.AddJsonFile($"appsettings.Production.json", optional: false, reloadOnChange: true); + } config.AddJsonFile("openImisModules.json", optional: true, reloadOnChange: true); }) .UseStartup(); diff --git a/OpenImis.RestApi/Properties/PublishProfiles/FolderProfile.pubxml b/OpenImis.RestApi/Properties/PublishProfiles/FolderProfile.pubxml index 8052570a..51f87086 100644 --- a/OpenImis.RestApi/Properties/PublishProfiles/FolderProfile.pubxml +++ b/OpenImis.RestApi/Properties/PublishProfiles/FolderProfile.pubxml @@ -12,11 +12,11 @@ by editing this MSBuild file. In order to learn more about this please visit htt True False - netcoreapp2.1 + netcoreapp2.2 win-x64 fd2d14ee-4549-4249-bbff-3254bcec4b5e - true - <_IsPortable>false + false + <_IsPortable>true ..\..\Published\RestApi True From b39c17e4d2f16fa7af25614c93d7caa13edfcfb6 Mon Sep 17 00:00:00 2001 From: Dragos Dobre Date: Wed, 20 Nov 2019 12:39:26 +0100 Subject: [PATCH 86/86] Improve Swagger UI --- .../Docs/ApiVersion2Description.md | 18 ++++++++++++++++++ OpenImis.RestApi/Docs/SwaggerHelper.cs | 12 +++++++++++- OpenImis.RestApi/OpenImis.RestApi.csproj | 3 +++ .../Properties/launchSettings.json | 2 +- OpenImis.RestApi/appsettings.json | 1 + 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 OpenImis.RestApi/Docs/ApiVersion2Description.md diff --git a/OpenImis.RestApi/Docs/ApiVersion2Description.md b/OpenImis.RestApi/Docs/ApiVersion2Description.md new file mode 100644 index 00000000..d74165c9 --- /dev/null +++ b/OpenImis.RestApi/Docs/ApiVersion2Description.md @@ -0,0 +1,18 @@ +## REST services openIMIS ecosystem + +### Authentication + +* The REST API uses a JWT authentication. + +Every request needs the Authorization HTTP header field: + +``` +Authorization: Bearer +``` + +The Token is obtained by making a POST request to the /api/login route. + +If no valid headers are provided in the request, a 401 Unauthorized status code will throw with no response HTTP body. + + + diff --git a/OpenImis.RestApi/Docs/SwaggerHelper.cs b/OpenImis.RestApi/Docs/SwaggerHelper.cs index c0b09c9a..1049df76 100644 --- a/OpenImis.RestApi/Docs/SwaggerHelper.cs +++ b/OpenImis.RestApi/Docs/SwaggerHelper.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; using Swashbuckle.AspNetCore.Examples; using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.SwaggerGen; @@ -37,6 +38,7 @@ private static void AddSwaggerDocPerVersion(SwaggerGenOptions swaggerGenOptions, { var apiVersionDescriptions = new ApiVersionDescriptions(); apiVersionDescriptions.AddDescription("1", File.ReadAllText("Docs\\ApiVersion1Description.md")); + apiVersionDescriptions.AddDescription("2", File.ReadAllText("Docs\\ApiVersion2Description.md")); var apiVersions = GetApiVersions(webApiAssembly); foreach (var apiVersion in apiVersions) { @@ -91,9 +93,17 @@ public static void ConfigureSwaggerUI(SwaggerUIOptions swaggerUIOptions) { var webApiAssembly = Assembly.GetEntryAssembly(); var apiVersions = GetApiVersions(webApiAssembly); + + IConfigurationRoot configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile($"appsettings.json") + .Build(); + + var appPrefixDir = configuration.GetValue("AppPrefixDir"); + foreach (var apiVersion in apiVersions) { - swaggerUIOptions.SwaggerEndpoint($"/api-docs/v{apiVersion}/swagger.json", $"V{apiVersion} Docs"); + swaggerUIOptions.SwaggerEndpoint($"{appPrefixDir}/api-docs/v{apiVersion}/swagger.json", $"V{apiVersion} Docs"); } swaggerUIOptions.RoutePrefix = "api-docs"; swaggerUIOptions.InjectStylesheet("theme-feeling-blue-v2.css"); diff --git a/OpenImis.RestApi/OpenImis.RestApi.csproj b/OpenImis.RestApi/OpenImis.RestApi.csproj index e533a9ec..8d4c876e 100644 --- a/OpenImis.RestApi/OpenImis.RestApi.csproj +++ b/OpenImis.RestApi/OpenImis.RestApi.csproj @@ -89,6 +89,9 @@ + + Always + Always diff --git a/OpenImis.RestApi/Properties/launchSettings.json b/OpenImis.RestApi/Properties/launchSettings.json index 030ce7f3..aa67fefd 100644 --- a/OpenImis.RestApi/Properties/launchSettings.json +++ b/OpenImis.RestApi/Properties/launchSettings.json @@ -20,7 +20,7 @@ "ImisRestApi": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "api/values", + "launchUrl": "api-docs", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, diff --git a/OpenImis.RestApi/appsettings.json b/OpenImis.RestApi/appsettings.json index 33fe948f..4b87ab52 100644 --- a/OpenImis.RestApi/appsettings.json +++ b/OpenImis.RestApi/appsettings.json @@ -15,6 +15,7 @@ } } }, + "AppPrefixDir": "", "AppSettings": { "FromPhone_Renewal": "\\FromPhone\\Renewal\\", "FromPhone_Renewal_Rejected": "\\FromPhone\\Renewal\\Rejected\\",