public async Task PolicyProductTypes() { var policyProductType = new PolicyProductType() { Id = Guid.NewGuid(), PolicyTypeId = Guid.NewGuid(), Name = "Name1", Code = "Code1" }; var policyProductTypes = new List <PolicyProductType>() { policyProductType }; var service = new Mock <IClientLookupService>(); service.Setup(c => c.GetPolicyProductTypes()) .ReturnsAsync(policyProductTypes); var controller = new LookupsController(service.Object); var result = await controller.PolicyProductTypes(); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <PolicyProductType> >(okResult.Value); Assert.Same(policyProductTypes, returnValue); }
public DataSet GetInstalmentSchedule(string policyNumber) { PolicyProductType productType = ValidatePolicyNumber(policyNumber); long policyInstalmentID = GetPolicyInstalmentIdFromPolicyNumber(policyNumber, productType); if (policyInstalmentID > 0) { string sql, sqlFormat = "Select InstalmentNumber, InstalmentDate, InstalmentAmount, PaymentStatusCode, ReasonForFailure, RetryCount, RetryDate From {0} Where {1} = {2} Order By InstalmentNumber, RetryCount Asc"; switch (productType) { case PolicyProductType.HOME: sql = String.Format(sqlFormat, "HomeContentPolicyPaymentScheduleDetails", "HomeContentPolicyInstalmentId", policyInstalmentID.ToString()); var resultH = RunSQLQuery(sql); return(resultH); case PolicyProductType.LANDLORD: sql = String.Format(sqlFormat, "LandlordPolicyPaymentScheduleDetails", "LandlordPolicyInstalmentId", policyInstalmentID.ToString()); var resultL = RunSQLQuery(sql); return(resultL); case PolicyProductType.MOTOR: sql = String.Format(sqlFormat, "MotorPolicyPaymentScheduleDetails", "MotorPolicyInstalmentId", policyInstalmentID.ToString()); var resultM = RunSQLQuery(sql); return(resultM); } return(null); } else { return(null); } }
public long GetPolicyInstalmentIdFromPolicyNumber(string policyNumber, PolicyProductType productType) { try { string sql = "JUNK", sqlQueryFormat = "Select TOP 1 {0}PolicyInstalmentID From {0}PolicyInstalmentSetup Where PolicyNumber = '{1}' And IsActive = 1"; switch (productType) { case PolicyProductType.HOME: sql = String.Format(sqlQueryFormat, "HomeContent", policyNumber); break; case PolicyProductType.LANDLORD: sql = String.Format(sqlQueryFormat, "Landlord", policyNumber); break; case PolicyProductType.MOTOR: sql = String.Format(sqlQueryFormat, "Motor", policyNumber); break; } var sqlResponse = RunSQLQuerySingleResult(sql); return(Convert.ToInt64(sqlResponse)); } catch (Exception ex) { return(0); throw; } }
public async Task <IActionResult> InsertPolicyProductType([FromBody] PolicyProductType policyProductType) { var result = await LookupService.InsertPolicyProductType(policyProductType); if (!result.Success) { return(BadRequest(result.ValidationFailures)); } return(Ok(result)); }
public async Task InsertPolicyProductType() { var options = TestHelper.GetDbContext("InsertPolicyProductType"); var policyType = TestHelper.InsertPolicyType(options); var char1 = new PolicyTypeCharacteristicEntity { Id = Guid.NewGuid(), Name = "A", DisplayOrder = 0, PolicyTypeId = policyType.Id }; var charDesc1 = new PolicyTypeCharacteristicDescription() { PolicyTypeCharacteristicId = char1.Id, Description = "Description 1" }; using (var context = new DataContext(options)) { context.PolicyTypeCharacteristic.Add(char1); context.SaveChanges(); } //Given var model = new PolicyProductType() { Name = "1", Code = "one", PolicyTypeId = policyType.Id, PolicyTypeCharacteristics = new List <PolicyTypeCharacteristicDescription>() { charDesc1 } }; using (var context = new DataContext(options)) { var service = new ClientLookupService(context); //When var result = await service.InsertPolicyProductType(model); //Then Assert.True(result.Success); var actual = await context.PolicyProductType.FindAsync(((PolicyProductType)result.Tag).Id); Assert.Equal(model.Name, actual.Name); Assert.Equal(model.Code, actual.Code); Assert.Equal(model.PolicyTypeId, actual.PolicyTypeId); Assert.Equal(model.PolicyTypeCharacteristics.Single().PolicyTypeCharacteristicId, actual.PolicyTypeCharacteristics.Single().PolicyTypeCharacteristicId); } }
private PolicyProductTypeEntity MapPolicyProductTypeModelToEntity(PolicyProductType model, PolicyProductTypeEntity entity = null) { if (entity == null) { entity = new PolicyProductTypeEntity(); } entity.Name = model.Name; entity.Code = model.Code; entity.PolicyTypeId = model.PolicyTypeId.Value; entity.PolicyTypeCharacteristics = model.PolicyTypeCharacteristics; return(entity); }
public int UpdatePaymentStatus(string policyNumber, int instalmentNumber, int retryCount, string paymentStatus, string failureReason) { try { PolicyProductType productType = ValidatePolicyNumber(policyNumber); long policyInstalmentID = GetPolicyInstalmentIdFromPolicyNumber(policyNumber, productType); string sql = "JUNK", sqlFormat = "Update {0}PolicyPaymentScheduleDetails Set PaymentStatusCode = '{1}', ReasonForFailure = '{5}' Where InstalmentNumber = {2} And {3} And {0}PolicyInstalmentID = {4}"; string retryCountText = " RetryCount = " + retryCount.ToString() + " "; if (retryCount == 0) { retryCountText = " (RetryCount = 0 Or RetryCount Is Null) "; } switch (productType) { case PolicyProductType.HOME: sql = string.Format(sqlFormat, "HomeContent", paymentStatus, instalmentNumber, retryCountText, policyInstalmentID, failureReason); break; case PolicyProductType.LANDLORD: sql = string.Format(sqlFormat, "Landlord", paymentStatus, instalmentNumber, retryCountText, policyInstalmentID, failureReason); break; case PolicyProductType.MOTOR: sql = string.Format(sqlFormat, "Motor", paymentStatus, instalmentNumber, retryCountText, policyInstalmentID, failureReason); break; } connection.Open(); SqlCommand updateCommand = new SqlCommand(sql, connection); return(updateCommand.ExecuteNonQuery()); } catch (Exception) { throw; } finally { connection.Close(); } }
public async Task <Result> InsertPolicyProductType(PolicyProductType model) { var validator = new PolicyProductTypeValidator(_context, true); var result = validator.Validate(model).GetResult(); if (!result.Success) { return(result); } var entity = MapPolicyProductTypeModelToEntity(model); await _context.PolicyProductType.AddAsync(entity); await _context.SaveChangesAsync(); model.Id = entity.Id; result.Tag = model; return(result); }
public async Task <Result> UpdatePolicyProductType(PolicyProductType model) { var validator = new PolicyProductTypeValidator(_context, false); var result = validator.Validate(model).GetResult(); if (!result.Success) { return(result); } var entity = await _context.PolicyProductType.FindAsync(model.Id); if (entity == null) { return(new Result()); } entity = MapPolicyProductTypeModelToEntity(model, entity); await _context.SaveChangesAsync(); return(result); }
public async Task UpdatePolicyProductType() { var policyProductType = new PolicyProductType() { Id = Guid.NewGuid(), PolicyTypeId = Guid.NewGuid(), Name = "Name1", Code = "Code1" }; var service = new Mock <IClientLookupService>(); var result = new Result() { Success = true }; PolicyProductType updated = null; service.Setup(c => c.UpdatePolicyProductType(It.IsAny <PolicyProductType>())) .Callback((PolicyProductType i) => { updated = i; }) .ReturnsAsync(result); var controller = new LookupsController(service.Object); var actual = await controller.UpdatePolicyProductType(policyProductType.Id.Value, policyProductType); Assert.Same(policyProductType, updated); var okResult = Assert.IsType <OkObjectResult>(actual); var returnValue = Assert.IsType <Result>(okResult.Value); Assert.Same(result, returnValue); }
public async Task <IActionResult> UpdatePolicyProductType(Guid policyProductTypeId, [FromBody] PolicyProductType policyProductType) { policyProductType.Id = policyProductTypeId; var result = await LookupService.UpdatePolicyProductType(policyProductType); if (!result.Success) { return(BadRequest(result.ValidationFailures)); } return(Ok(result)); }
public async Task All() { var policyType = new PolicyType() { Id = Guid.NewGuid(), Name = "Name4", Code = "Code4" }; var policyProductType = new PolicyProductType() { Id = Guid.NewGuid(), Name = "Name4", Code = "Code4", PolicyTypeId = Guid.NewGuid() }; var policyProduct = new PolicyProduct() { Id = Guid.NewGuid(), Name = "Name4", Code = "Code4", PolicyProductTypeId = Guid.NewGuid(), CompanyId = Guid.NewGuid() }; var contactType = new ContactType() { Id = Guid.NewGuid(), Name = "Name5" }; var marritalStatus = new MarritalStatus() { Id = Guid.NewGuid(), Name = "Name6" }; var clientType = new ClientType() { Id = Guid.NewGuid(), Name = "Name8", Code = "Code8" }; var policyTypeCharacteristic = new PolicyTypeCharacteristic() { Id = Guid.NewGuid(), Name = "Name8", DisplayOrder = 1 }; var policyTypes = new List <PolicyType>() { policyType }; var policyProductTypes = new List <PolicyProductType>() { policyProductType }; var policyProducts = new List <PolicyProduct>() { policyProduct }; var clientTypes = new List <ClientType>() { clientType }; var contactTypes = new List <ContactType>() { contactType }; var marritalStatusList = new List <MarritalStatus>() { marritalStatus }; var policyTypeCharacteristicList = new List <PolicyTypeCharacteristic>() { policyTypeCharacteristic }; var service = new Mock <IClientLookupService>(); service.Setup(c => c.GetPolicyTypes()).ReturnsAsync(policyTypes); service.Setup(c => c.GetPolicyProductTypes()).ReturnsAsync(policyProductTypes); service.Setup(c => c.GetPolicyProducts()).ReturnsAsync(policyProducts); service.Setup(c => c.GetContactTypes()).ReturnsAsync(contactTypes); service.Setup(c => c.GetClientTypes()).ReturnsAsync(clientTypes); service.Setup(c => c.GetMarritalStatus()).ReturnsAsync(marritalStatusList); service.Setup(c => c.GetPolicyTypeCharacteristics()).ReturnsAsync(policyTypeCharacteristicList); var controller = new LookupsController(service.Object); var result = await controller.All(); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <api.Controllers.Client.Lookups.Dto.Lookups>(okResult.Value); var all = new api.Controllers.Client.Lookups.Dto.Lookups() { PolicyTypes = policyTypes, PolicyProductTypes = policyProductTypes, PolicyProducts = policyProducts, ContactTypes = contactTypes, MarritalStatus = marritalStatusList, PolicyTypeCharacteristics = policyTypeCharacteristicList }; Assert.NotStrictEqual(all, returnValue); }