// NOTES *************************************************** // // This classed is used for mapping the source data objects // to the formatted objects expected by the consumer as per // the user story. So - id field should not be exposed; the // currentUnitPrice price field should be rounded to 2 dp; // marketCode field should be exposed as code field. Also, // worth nothing that the consumer has not specified HOW to // round, so if this was real I would be asking that question // for sure, because there are many different ways we can // round, especially when dealing with financials..... // ********************************************************* // Public methods public List <FundDetails> MapFunds(List <FundDetailsDTO> fundsDTO) { List <FundDetails> funds = new List <FundDetails>(); foreach (FundDetailsDTO fundDTO in fundsDTO) { // Round the unit price. I have used Math.Round for simplicity here, // as no specific intructions on how to round were provided... decimal currUnitPrice = Math.Round(fundDTO.CurrentUnitPrice, 2); // Map the new object from DTO FundDetails fund = new FundDetails { Active = fundDTO.Active, CurrentUnitPrice = currUnitPrice, FundManager = fundDTO.FundManager, Name = fundDTO.Name, Code = fundDTO.MarketCode }; // Add to list funds.Add(fund); } return(funds); }
public IActionResult Post([FromBody] object payload) { // TO DO, validation of required fields // TO DO, validation if request includes breakdown item, ensure the sum of all breakdown is equal to 100 // TO DO, fail request if stored "pricedOn" is greater that request "pricedOn" IFundMapper fundMapper = new FundMapper(); if (payload is JObject) { FundDetails fundsDetails = ((JObject)payload).ToObject <FundDetails>(); ValidationContext vc = new ValidationContext(fundsDetails); var results = new List <ValidationResult>(); if (_context.Funds.Any(x => x.Id == fundsDetails.id)) { return(Conflict("fund already exists")); } var isValid = Validator.TryValidateObject(fundsDetails, vc, results); _context.Funds.Add(fundMapper.FromContractToDomain(fundsDetails)); _context.SaveChangesAsync(); return(Created("http://localhost:5000/api/funds", fundsDetails.id)); } return(BadRequest()); }
public async void GetFundByMarketCode_WithMatch_ReturnsExpectedFund() { var expectedFund = new FundDetails() { Id = Guid.NewGuid(), Active = true, CurrentUnitPrice = 100.2345M, MarketCode = "AAA", FundManager = "Berty", Name = "GuiltIndex" }; var mockRepository = new Mock <IQueryRepository <FundDetails> >(); mockRepository.Setup(m => m.GetFirstOrDefaultDataEntity(It.IsAny <ISpecification <FundDetails> >())) .ReturnsAsync(expectedFund); var controller = CreateController(mockRepository.Object); var result = await controller.GetFundByMarketCode("AAA"); Assert.NotNull(result); var objectResult = Assert.IsType <OkObjectResult>(result); Assert.Equal(expectedFund, objectResult.Value); }
public List <FundDetails> GetFundDetails() { try { var connectionString = _configuration.GetConnectionString("FundDBConnection"); List <FundDetails> listFundDetails = new List <FundDetails>(); using (var conn = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("GetFundDetails", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { FundDetails obj = new FundDetails(); obj.FundName = reader["FundName"].ToString(); obj.Ticker = reader["Ticker"].ToString(); obj.MorningStar = reader["MorningStar"].ToString(); obj.MonthlyAvgValue = decimal.Parse(reader["MonthlyAvgValue"].ToString()); obj.ThreeMonthsAvgValue = decimal.Parse(reader["ThreeMonthsAvgValue"].ToString()); obj.OneYearAvgValue = decimal.Parse(reader["OneYearAvgValue"].ToString()); obj.FiveYearsAvgValue = decimal.Parse(reader["FiveYearsAvgValue"].ToString()); obj.SinceInceptionAvgValue = decimal.Parse(reader["SinceInceptionAvgValue"].ToString()); listFundDetails.Add(obj); } conn.Close(); } return(listFundDetails); } catch (Exception ex) { throw ex; } }
public Fund(FundDetails fundDetails) { this.Active = fundDetails.Active; this.CurrentUnitPrice = decimal.Round(fundDetails.CurrentUnitPrice, 2); this.FundManager = fundDetails.FundManager; this.Name = fundDetails.Name; this.Code = fundDetails.MarketCode; this.Active = fundDetails.Active; }
public static FundDetails GetVirtualFundDetails(int fundId) { IDalSession session = NHSessionFactory.CreateSession(); IVirtualFund fund = (IVirtualFund)InstrumentMapper.GetInstrument(session, fundId); FundDetails funddetails = new FundDetails(fund); session.Close(); return funddetails; }
public static FundViewModel FromFundDetails(FundDetails fundDetails) { return(new FundViewModel { Active = fundDetails.Active, CurrentUnitPrice = Math.Round(fundDetails.CurrentUnitPrice, 2), Code = fundDetails.MarketCode, FundManager = fundDetails.FundManager, Name = fundDetails.Name }); }
public void GetFund_MakesCallTo_FundsHelperGetFund() { // Arrange FundDetails fakeFund = new FundDetails() { Active = true, CurrentUnitPrice = 12.34m, Code = "FAKECODE", FundManager = "FakeManager", Name = "Fake Name" }; mockFundsHelper.Setup(mfh => mfh.GetFundByMarketCode("FAKECODE")).Returns(fakeFund); // Act var fund = controller.GetFundByMarketCode("FAKECODE"); // Assert that fundsHelper was called mockFundsHelper.Verify((mfh => mfh.GetFundByMarketCode("FAKECODE")), Times.Once); }
public IActionResult GetFundByMarketCode(string marketCode) { FundDetails fund = fundsHelper.GetFundByMarketCode(marketCode); return(Ok(fund)); }
public static FundDetails GetVirtualFundDetailsfromCalculation(int calculationId) { IDalSession session = NHSessionFactory.CreateSession(); INavCalculation calc = NavCalculationMapper.GetNavCalculation(session, calculationId); IVirtualFund fund = calc.Fund; FundDetails funddetails = new FundDetails(fund); session.Close(); return funddetails; }
public APIResponse Personal(int userId, int merchantId, string deviceId) { PersonalResultModel model = new PersonalResultModel(); var posMachine = CurrentDb.PosMachine.Where(m => m.DeviceId == deviceId).FirstOrDefault(); if (posMachine == null) { model.PosMachineStatus = Enumeration.MerchantPosMachineStatus.NotMatch; return(ResponseResult(ResultType.Failure, ResultCode.Failure, "设备ID不存在")); } var merchant = CurrentDb.Merchant.Where(m => m.Id == merchantId).FirstOrDefault(); var userAccount = CurrentDb.SysClientUser.Where(m => m.Id == userId).FirstOrDefault(); var merchantFund = CurrentDb.Fund.Where(m => m.UserId == merchant.UserId && m.MerchantId == merchant.Id).FirstOrDefault(); var merchantPosMachine = CurrentDb.MerchantPosMachine.Where(m => m.MerchantId == merchantId && m.PosMachineId == posMachine.Id).FirstOrDefault(); var merchantOrder = CurrentDb.Order.Where(m => m.UserId == merchant.UserId && m.MerchantId == merchant.Id && (m.Status == Enumeration.OrderStatus.Follow || m.Status == Enumeration.OrderStatus.WaitPay && ((int)m.ProductType).ToString().StartsWith("201"))).ToList(); //var Log.Info("测试通过1"); model.PosMachineStatus = merchantPosMachine.Status; PersonalInfo personalInfo = new PersonalInfo(); personalInfo.PhoneNumber = userAccount.PhoneNumber.NullToEmpty(); personalInfo.FullName = userAccount.FullName.NullToEmpty(); personalInfo.MerchantName = merchant.YYZZ_Name.NullToEmpty(); personalInfo.MerchantAddress = merchant.YYZZ_Address.NullToEmpty(); model.PersonalInfo = personalInfo; model.WithdrawRuleUrl = BizFactory.Withdraw.GetWithrawRuleUrl(); if (merchant != null) { //资金详细 if (merchantFund != null) { FundDetails fundDetails = new FundDetails(); fundDetails.Balance = merchantFund.Balance; fundDetails.Arrearage = merchantFund.Arrearage; model.Fund = fundDetails; } //订单数据 if (merchantOrder != null) { OrderStatusCount orderStatusCount = new OrderStatusCount(); orderStatusCount.Follow = merchantOrder.Where(m => m.Status == Enumeration.OrderStatus.Follow).Count(); orderStatusCount.WaitPay = merchantOrder.Where(m => m.Status == Enumeration.OrderStatus.WaitPay).Count(); model.OrderStatusCount = orderStatusCount; } Log.Info("测试通过2"); //租金 if (merchantPosMachine != null) { model.RentDue = BizFactory.Merchant.GetRentOrder(merchant.Id, posMachine.Id); } Log.Info("测试通过3"); //续保数量 DateTime periodEndMax = DateTime.Now.AddDays(-7); model.RenewalCount = CurrentDb.OrderToCarInsure.Where(m => m.MerchantId == merchant.Id && m.Status == Enumeration.OrderStatus.Completed && m.PeriodEnd >= periodEndMax).Count(); } model.CustomerPhone = "020-88888888"; APIResult result = new APIResult() { Result = ResultType.Success, Code = ResultCode.Success, Message = "获取成功", Data = model }; return(new APIResponse(result)); }