public override async Task <PricesResponse> GetPrices(PricesRequest request, ServerCallContext context) { var entities = _pricesReader.Get(PriceEntity.GetPk()); List <PriceUpdate> result; if (entities.Any()) { result = _mapper.Map <List <PriceUpdate> >(entities); } else { var marketData = await _marketDataClient.GetMarketDataAsync(new Empty()); result = _mapper.Map <List <PriceUpdate> >(marketData.Items.ToList()); } if (request.AssetPairIds.Any()) { result = result.Where(x => request.AssetPairIds.Contains(x.AssetPairId, StringComparer.InvariantCultureIgnoreCase)) .ToList(); } var response = new PricesResponse(); response.Payload.AddRange(result); return(response); }
public override async Task GetPriceUpdates(PriceUpdatesRequest request, IServerStreamWriter <PriceUpdate> responseStream, ServerCallContext context) { Console.WriteLine($"New price stream connect. peer:{context.Peer}"); var entities = _pricesReader.Get(PriceEntity.GetPk()); var prices = _mapper.Map <List <PriceUpdate> >(entities); if (request.AssetPairIds.Any()) { prices = prices.Where(x => request.AssetPairIds.Contains(x.AssetPairId)).ToList(); } var streamInfo = new StreamInfo <PriceUpdate> { Stream = responseStream, CancelationToken = context.CancellationToken, Peer = context.Peer, Keys = request.AssetPairIds.ToArray() }; var task = await _priceStreamService.RegisterStreamAsync(streamInfo, prices); await task; }
public async Task <IActionResult> GetPrices([FromQuery] string[] assetPairIds) { var entities = _pricesReader.Get(PriceEntity.GetPk()); List <PriceModel> result; if (entities.Any()) { result = _mapper.Map <List <PriceModel> >(entities); } else { var marketData = await _marketDataClient.GetMarketDataAsync(new Empty()); result = _mapper.Map <List <PriceModel> >(marketData.Items.ToList()); } if (assetPairIds.Any()) { result = result.Where(x => assetPairIds.Contains(x.AssetPairId, StringComparer.InvariantCultureIgnoreCase)) .ToList(); } return(Ok(ResponseModel <IReadOnlyCollection <PriceModel> > .Ok(result))); }
public List <PriceEntity> GetAllPrices() { SqlConnection conn = new SqlConnection("Server = mssql.fhict.local; Database = dbi346272; User Id = dbi346272; Password = Test123"); List <PriceEntity> entities = new List <PriceEntity>(); try { using (conn) { conn.Open(); using (var cmd = new SqlCommand("SELECT * FROM Prijs ORDER BY Tournament_ID", conn)) { using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { PriceEntity entity = new PriceEntity(); entity.ID = reader.GetInt32(reader.GetOrdinal("ID")); entity.TournamentID = reader.GetInt32(reader.GetOrdinal("Tournament_ID")); entity.Pricestring = reader.GetString(reader.GetOrdinal("Regel")); entities.Add(entity); } } } conn.Close(); } } catch (SqlException) { } return(entities); }
public override Task <PricesResponse> GetPrices(PricesRequest request, ServerCallContext context) { var entities = _pricesReader.Get(PriceEntity.GetPk()); var result = new List <PriceUpdate>(); if (entities.Any()) { result = _mapper.Map <List <PriceUpdate> >(entities); } if (request.AssetPairIds.Any()) { result = result.Where(x => request.AssetPairIds.Contains(x.AssetPairId, StringComparer.InvariantCultureIgnoreCase)) .ToList(); } var response = new PricesResponse { Body = new PricesResponse.Types.Body() }; response.Body.Prices.AddRange(result); return(Task.FromResult(response)); }
public override void Patch(PriceEntity target) { base.Patch(target); var priceExEntity = (PriceExEntity)target; priceExEntity.BasePrice = BasePrice; }
public static Price PriceEntityToPrice(this PriceEntity price, CurrencyEntity currency) { return(new Price { List = Convert.ToDecimal(price.List), Sale = Convert.ToDecimal(price.Sale), Currency = currency.EntitiesToModel() }); }
public static string GetPrice(this PriceEntity p) { if (p.value == NO_ACCESS) { string call = Translation.GetTranslation(Translation.SECTION.PRODUCT, 354); return(call); } return(FormatCurrency(p.value, p.currency)); }
public static PriceEntity Divide(PriceEntity p, int divisor) { if (!p.IsEligible()) { return(CALL_PRICING); } return(new PriceEntity() { value = p.value / divisor, currency = p.currency }); }
public static PriceEntity Multiply(PriceEntity p, decimal multiplier) { if (!p.IsEligible()) { return(CALL_PRICING); } return(new PriceEntity() { value = p.value * multiplier, currency = p.currency }); }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, PriceEntity entity) { try { service.SaveForm(keyValue, entity); } catch (Exception) { throw; } }
private decimal GetSum(ApplyBillEntity apply, PriceEntity price) { if (apply.appUnit == price.unit) { return(Math.Round((apply.appNum ?? 0) * (price.price ?? 0), 2)); } else { return(Math.Round((apply.viceNum ?? 0) * (price.price ?? 0), 2)); } }
public void SubmitForm(PriceEntity priceEntity, List <PriceBaseEntity> basesList, List <PriceDetailsEntity> detailsList, string keyValue) { if (basesList.Count == 1) { priceEntity.F_UnitPrice = (basesList.First().F_PriceValue + detailsList.Sum(x => x.F_Price)).ToString(CultureInfo.InvariantCulture); } else { priceEntity.F_UnitPrice = (basesList.OrderBy(x => x.F_PriceValue).First().F_PriceValue + detailsList.Sum(x => x.F_Price)).ToString(CultureInfo.InvariantCulture) + "-" + (basesList.OrderBy(x => x.F_PriceValue).Last().F_PriceValue + detailsList.Sum(x => x.F_Price)).ToString(CultureInfo.InvariantCulture); } _service.SubmitForm(priceEntity, basesList, detailsList, keyValue); }
public async Task <JsonResult> ApiUpdatePriceForTicker(string listId) { try { CoinMarketCapClient _client = new CoinMarketCapClient(); IDictionary <string, CyproPriceEntity> coinmaketresult = await _client.GetListPriceCyptoItemAsync(listId); foreach (CyproPriceEntity Item in coinmaketresult.Values) { CyptoItemPriceViewModel objCyptoItemPrice = new CyptoItemPriceViewModel(); objCyptoItemPrice.id = Item.id; objCyptoItemPrice.name = Item.name; objCyptoItemPrice.symbol = Item.symbol; objCyptoItemPrice.slug = Item.slug; objCyptoItemPrice.CyptoItemPriceUpdate = DateTime.Now; objCyptoItemPrice.is_active = true; objCyptoItemPrice.cmc_rank = Item.cmc_rank; objCyptoItemPrice.num_market_pairs = Item.num_market_pairs; objCyptoItemPrice.circulating_supply = Item.circulating_supply; objCyptoItemPrice.total_supply = Item.total_supply; objCyptoItemPrice.max_supply = Item.max_supply ?? 0; try { objCyptoItemPrice.last_updated = DateTime.Parse(Item.last_updated); } catch { objCyptoItemPrice.last_updated = DateTime.Now; } PriceEntity USD = Item.quote.Values.First(); objCyptoItemPrice.USD_price = USD.price; objCyptoItemPrice.USD_volume_24h = USD.volume_24h; objCyptoItemPrice.USD_percent_change_1h = USD.percent_change_1h; objCyptoItemPrice.USD_percent_change_7d = USD.percent_change_7d; objCyptoItemPrice.USD_market_cap = USD.market_cap; CyptoItemPrice modelmain = objCyptoItemPrice._MainObj; await cms_db.CreateCyptoItemPrice(objCyptoItemPrice._MainObj); } HttpContext.Application["LastTimePriceUpdate"] = DateTime.Now.ToString(); return(Json(coinmaketresult, JsonRequestBehavior.AllowGet)); } catch (Exception e) { cms_db.AddToExceptionLog("ApiUpdatePriceForTicker", "Member", e.ToString()); return(Json(e, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Method that convert a PriceEntity(Database) into Price /// </summary> /// <param name="price">PriceEntity</param> /// <returns>Price</returns> public Price convertToEntity(PriceEntity price) { try { Price p = new Price(); p.Id = price.Id; p.Prices = price.Price1; p.Description = price.Description; return(p); } catch (Exception ex) { throw ex; } }
public async Task InsertPrice(string sku, InsertPrice price) { if (price == null) { throw new Exception("Cannot add price, because price is null"); } var entity = new PriceEntity { Active = price.Active, ItemSku = sku.ToUpper(), Price = decimal.Parse(price.Price) }; await _context.Prices.AddAsync(entity); }
public static PriceEntity Subtract(PriceEntity p, PriceEntity sub) { if (!p.IsEligible() && !sub.IsEligible()) { return(CALL_PRICING); } if (p.currency != sub.currency) { // currency mismatch return(p); } return(new PriceEntity() { value = p.value - sub.value, currency = p.currency }); }
public static PriceEntity Add(PriceEntity p, PriceEntity add) { if (!p.IsEligible() && !add.IsEligible()) { return(CALL_PRICING); } if (p.currency != add.currency) { // currency mismatch return(p); } return(new PriceEntity() { value = p.value + add.value, currency = p.currency }); }
public ActionResult SubmitForm(PriceEntity priceEntity, string keyValue) { var keys = Request.Form.AllKeys.OrderBy(x => x).ToList(); List <PriceBaseEntity> bases; var details = (from item in keys where item.Contains("F_DetailName") let index = int.Parse(item.Replace("F_DetailName", "")) select new PriceDetailsEntity { F_DetailName = Request.Form[item], F_Price = decimal.Parse(!string.IsNullOrEmpty(Request.Form["F_Price" + index]) ? Request.Form["F_Price" + index] : "0"), F_SortNumber = index }).Where(x => !string.IsNullOrEmpty(x.F_DetailName)).ToList(); if (priceEntity.F_PriceType == "1") { bases = new List <PriceBaseEntity>() { new PriceBaseEntity { F_PriceName = Request.Form["F_PriceName" + 0], F_PriceValue = decimal.Parse(!string.IsNullOrEmpty(Request.Form["F_PriceValue" + 0]) ? Request.Form["F_PriceValue" + 0] : "0"), F_SortNumber = 0 } }; } else { bases = (from item in keys where item.Contains("F_PriceName") && item != "F_PriceName" && item != "F_PriceName0" let index = int.Parse(item.Replace("F_PriceName", "")) select new PriceBaseEntity { F_PriceName = Request.Form[item], F_PriceValue = decimal.Parse(!string.IsNullOrEmpty(Request.Form["F_PriceValue" + index]) ? Request.Form["F_PriceValue" + index] : "0"), F_SortNumber = index }).Where(x => !string.IsNullOrEmpty(x.F_PriceName)).ToList(); } priceEntity.F_StartTime = priceEntity.F_StartTime == DateTime.MinValue ? DateTime.Now : priceEntity.F_StartTime; priceEntity.F_Cycle = priceEntity.F_Cycle ?? 0; _priceApp.SubmitForm(priceEntity, bases, details, keyValue); return(Success("操作成功。")); }
public void SubmitForm(PriceEntity priceEntity, string keyValue) { try { if (!string.IsNullOrEmpty(keyValue)) { priceEntity.priNO = keyValue; service.Update(priceEntity); } else { priceEntity.chkTag = "T"; service.Insert(priceEntity); } } catch (Exception ex) { throw; } }
public ActionResult GetFormDetail(int keyValue) { ApplyBillEntity applyBillEntity = applyBillApp.GetForm(keyValue); if (!string.IsNullOrEmpty(applyBillEntity.priNO)) { PriceEntity price = priceApp.GetFormJson(applyBillEntity.priNO); return(Json(new { prdName = price.prdName, spc = price.spc, mat = applyBillEntity.mat, orderNo = price.orderNo, appUnit = applyBillEntity.appUnit, viceNum = applyBillEntity.viceNum }, JsonRequestBehavior.AllowGet)); } else { return(Content(applyBillEntity.ToJson())); } }
public async Task <ActionResult> GetPriceOfCyptoItem() { string lstCyptoid = "1,1027"; IDictionary <string, CyproPriceEntity> coinmaketresult = await _client.GetListPriceCyptoItemAsync(lstCyptoid); foreach (CyproPriceEntity Item in coinmaketresult.Values) { CyptoItemPrice objCyptoItemPrice = new CyptoItemPrice(); objCyptoItemPrice.id = Item.id; objCyptoItemPrice.name = Item.name; objCyptoItemPrice.symbol = Item.symbol; objCyptoItemPrice.slug = Item.slug; objCyptoItemPrice.CyptoItemPriceUpdate = DateTime.Now; objCyptoItemPrice.is_active = true; objCyptoItemPrice.cmc_rank = Item.cmc_rank; objCyptoItemPrice.num_market_pairs = Item.num_market_pairs; objCyptoItemPrice.circulating_supply = Item.circulating_supply; objCyptoItemPrice.total_supply = Item.total_supply; objCyptoItemPrice.max_supply = Item.max_supply ?? 0; try { objCyptoItemPrice.last_updated = DateTime.Parse(Item.last_updated); } catch { objCyptoItemPrice.last_updated = DateTime.Now; } PriceEntity USD = Item.quote.Values.First(); objCyptoItemPrice.USD_price = USD.price; objCyptoItemPrice.USD_volume_24h = USD.volume_24h; objCyptoItemPrice.USD_percent_change_1h = USD.percent_change_1h; objCyptoItemPrice.USD_percent_change_7d = USD.percent_change_7d; objCyptoItemPrice.USD_market_cap = USD.market_cap; await cms_db.CreateCyptoItemPrice(objCyptoItemPrice); } return(View()); }
public ActionResult SubmitForm(PriceEntity priceEntity, string keyValue) { if (string.IsNullOrEmpty(keyValue)) { priceEntity.priNO = priceApp.ProducePriNO(); priceEntity.unit = priceEntity.unit.Trim().ToUpper(); priceEntity.principal = priceEntity.principal / 100; priceApp.SubmitForm(priceEntity, keyValue); } else { var price = priceApp.GetFormJson(keyValue); price.endDD = priceEntity.endDD; price.tel = priceEntity.tel; price.fax = priceEntity.fax; price.quoter = priceEntity.quoter; price.rem = priceEntity.rem; price.conMan = priceEntity.conMan; priceApp.SubmitForm(price, keyValue); } return(Success("操作成功。")); }
/// <summary> /// /// </summary> /// <param name="PS_ID"></param> /// <param name="billNo"></param> /// <param name="WH"></param> /// <param name="ITM"></param> /// <param name="NAME"></param> /// <param name="applyBillEntity"></param> /// <param name="billEntity"></param> /// <param name="priceEntity"></param> /// <returns></returns> public TF_PSSEntity SubmitForm(string PS_ID, string billNo, string WH, BillEntity bill, string NAME, ApplyBillEntity applyBillEntity, BillEntity billEntity, PriceEntity priceEntity) { try { TF_PSSEntity tF_PSSEntity = new TF_PSSEntity(); TF_PSSEntity entity = null; TF_PSSEntity entity1 = null; if (applyBillEntity.WAREWAY == 0)//工具仓 { entity = service.TOOLIQueryable(t => t.PS_NO.Equals(billNo)).OrderByDescending(t => t.ITM).FirstOrDefault(); entity1 = service.TOOLIQueryable(t => t.PS_NO.Equals(billNo)).OrderByDescending(t => t.PRE_ITM).FirstOrDefault(); } else { entity = service.G_WSIQueryable(t => t.PS_NO.Equals(billNo)).OrderByDescending(t => t.ITM).FirstOrDefault(); entity1 = service.G_WSIQueryable(t => t.PS_NO.Equals(billNo)).OrderByDescending(t => t.PRE_ITM).FirstOrDefault(); } if (entity != null) { tF_PSSEntity.ITM = entity.ITM + 1; } else { tF_PSSEntity.ITM = 1; } if (entity1 != null) { tF_PSSEntity.PRE_ITM = entity1.PRE_ITM + 1; } else { tF_PSSEntity.PRE_ITM = 1; } tF_PSSEntity.PS_ID = PS_ID; tF_PSSEntity.PS_NO = billNo; tF_PSSEntity.PS_DD = DateTime.Now.Date; tF_PSSEntity.WH = WH; tF_PSSEntity.PRD_NO = applyBillEntity.prdNo; tF_PSSEntity.PRD_NAME = NAME; tF_PSSEntity.PRD_MARK = ""; tF_PSSEntity.UNIT = "1"; tF_PSSEntity.QTY = Math.Abs(billEntity.num ?? 0); #region 单位及数量转换 if (priceEntity.unit == applyBillEntity.appUnit) { tF_PSSEntity.UP = priceEntity.price; tF_PSSEntity.AMT = decimal.Round(applyBillEntity.purPrice.Value * Math.Abs(billEntity.num.Value), 2); tF_PSSEntity.AMTN_NET = decimal.Round((applyBillEntity.purPrice.Value * Math.Abs(billEntity.num.Value)) / (1 + priceEntity.principal.Value), 2); tF_PSSEntity.CSTN_SAL = tF_PSSEntity.AMTN_NET; tF_PSSEntity.TAX = tF_PSSEntity.AMT - tF_PSSEntity.AMTN_NET; } else { var up = Math.Round((billEntity.viceNum ?? 0) * (priceEntity.price ?? 0) / (Math.Abs(billEntity.num ?? 0)), 2); tF_PSSEntity.UP = up; if (PS_ID.Equals("PB")) { tF_PSSEntity.UP_QTY1 = billEntity.num; } tF_PSSEntity.AMT = decimal.Round(up * Math.Abs(billEntity.num.Value), 2); tF_PSSEntity.AMTN_NET = decimal.Round((up * Math.Abs(billEntity.num.Value)) / (1 + priceEntity.principal.Value), 2); tF_PSSEntity.CSTN_SAL = tF_PSSEntity.AMTN_NET; tF_PSSEntity.TAX = tF_PSSEntity.AMT - tF_PSSEntity.AMTN_NET; } #endregion if (PS_ID.Equals("PB")) //退货单 { tF_PSSEntity.OS_ID = "PC"; //来源单ID tF_PSSEntity.OS_NO = bill.billNo; tF_PSSEntity.OTH_ITM = bill.erpItm; tF_PSSEntity.CUS_OS_NO = applyBillEntity.purNo; tF_PSSEntity.SL_ITM = 0; tF_PSSEntity.BL_OS_ITM = 0; } else if (PS_ID.Equals("PC")) { tF_PSSEntity.FREE_ID_DEF = "F"; } tF_PSSEntity.TAX_RTO = priceEntity.principal * 100; tF_PSSEntity.QTY1 = billEntity.viceNum; tF_PSSEntity.REM = billEntity.remark; tF_PSSEntity.PAK_WEIGHT_UNIT = applyBillEntity.viceUnit; tF_PSSEntity.CUS_OS_NO = applyBillEntity.purNo; if (applyBillEntity.WAREWAY == 0) { service.TOOLInsert(tF_PSSEntity); } else { service.G_WSInsert(tF_PSSEntity); } return(tF_PSSEntity); } catch (Exception ex) { new ErrorLogApp().SubmitForm(ex); return(null); } }
public ActionResult SaveForm(string keyValue, PriceEntity entity) { pricebll.SaveForm(keyValue, entity); return(Success("操作成功。")); }
public bool SavePrice(PriceEntity price) { return((_connection.Table <PriceEntity>().FirstOrDefault(x => x.Id == price.Id) == null ? _connection.Insert(price) : _connection.Update(price)) != -1); }
public void Get_document_changes_from_multiple_data_sources() { var mockOperationsLogs = new[] { new OperationLogEntity { ModifiedDate = new DateTime(2018, 11, 01), ObjectId = "1", ObjectType = nameof(PriceEntity) }, new OperationLogEntity { ModifiedDate = new DateTime(2018, 11, 01), ObjectId = "2", ObjectType = nameof(PriceEntity) }, new OperationLogEntity { ModifiedDate = new DateTime(2018, 11, 01), ObjectId = "3", ObjectType = nameof(PriceEntity) }, }; var mockPrices = new PriceEntity[] { //Without from/till dates (unbounded) new PriceEntity { Id = "1", ProductId = "1" }, //Without from date (unbounded) new PriceEntity { Id = "2", ProductId = "2", EndDate = new DateTime(2018, 06, 01) }, //Without till date (bounded) new PriceEntity { Id = "3", ProductId = "3", StartDate = new DateTime(2018, 06, 01) }, //with from/till dates (bounded) new PriceEntity { Id = "4", ProductId = "4", StartDate = new DateTime(2018, 06, 01), EndDate = new DateTime(2018, 12, 01) } }.AsQueryable().BuildMock(); var mockPricingRepository = new Mock <IPricingRepository>(); mockPricingRepository.SetupGet(x => x.Prices).Returns(mockPrices.Object); mockPricingRepository.Setup(x => x.GetPricesByIdsAsync(It.IsAny <string[]>())).ReturnsAsync(mockPrices.Object.ToArray()); var mockPlatformRepository = new Mock <IPlatformRepository>(); mockPlatformRepository.SetupGet(x => x.OperationLogs).Returns(mockOperationsLogs.AsQueryable()); var mockSettingManager = new Mock <ISettingsManager>(); mockSettingManager.Setup(s => s.GetObjectSettingAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(new ObjectSettingEntry() { Value = DateTime.MinValue }); var mockChangeLogSearchService = new Mock <IChangeLogSearchService>(); mockChangeLogSearchService.Setup(x => x.SearchAsync(It.IsAny <ChangeLogSearchCriteria>())) .ReturnsAsync(new ChangeLogSearchResult { Results = mockOperationsLogs.Select(o => o.ToModel(AbstractTypeFactory <OperationLog> .TryCreateInstance())).ToList() }); var changesProvider = new ProductPriceDocumentChangesProvider(mockChangeLogSearchService.Object, mockSettingManager.Object, () => mockPricingRepository.Object); var startDate = new DateTime(2018, 06, 01); var endDate = new DateTime(2018, 12, 01); var totalCount = changesProvider.GetTotalChangesCountAsync(startDate, endDate).GetAwaiter().GetResult(); var changes = changesProvider.GetChangesAsync(startDate, endDate, 0, 5).GetAwaiter().GetResult(); Assert.Equal(5, totalCount); Assert.Equal(new[] { "1", "2", "3", "3", "4" }, changes.Select(x => x.DocumentId)); //Do not return calendar changes for not determined date interval changes = changesProvider.GetChangesAsync(startDate, null, 0, 5).GetAwaiter().GetResult(); Assert.Equal(new[] { "1", "2", "3" }, changes.Select(x => x.DocumentId)); mockSettingManager.Setup(s => s.GetObjectSettingAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(new ObjectSettingEntry() { Value = DateTime.MinValue }); //Paginated request for multiple data sources (skip 2 from OperationLogEntity and take 3 from both data sources (OperationLogEntity, CalendarChanges)) changes = changesProvider.GetChangesAsync(startDate, endDate, 2, 3).GetAwaiter().GetResult(); Assert.Equal(new[] { "3", "3", "4" }, changes.Select(x => x.DocumentId)); }
public void Can_return_price_from_many_prices_with_start_and_end_date() { var evalContext = new PriceEvaluationContext { ProductIds = new[] { "ProductId" }, PricelistIds = new[] { "List1" } }; var mockPrices = new PriceEntity[] { // Unbounded past. new PriceEntity { Id = "1", List = 1, EndDate = new DateTime(2018, 09, 10), PricelistId = "List1", ProductId = "ProductId" }, // Bounded past. new PriceEntity { Id = "2", List = 2, StartDate = new DateTime(2018, 09, 15), EndDate = new DateTime(2018, 09, 17), PricelistId = "List1", ProductId = "ProductId" }, // Bounded future. new PriceEntity { Id = "3", List = 3, StartDate = new DateTime(2018, 09, 26), EndDate = new DateTime(2018, 09, 29), PricelistId = "List1", ProductId = "ProductId" }, // Unbounded future. new PriceEntity { Id = "4", List = 4, StartDate = new DateTime(2018, 10, 1), PricelistId = "List1", ProductId = "ProductId" }, // Default unfiltered price. new PriceEntity { Id = "10", List = 10, PricelistId = "List1", ProductId = "ProductId" }, }.AsQueryable().BuildMock(); var mockRepository = new Mock <IPricingRepository>(); mockRepository.SetupGet(x => x.Prices).Returns(mockPrices.Object); var service = new PricingServiceImpl(() => mockRepository.Object, null, null, null, null, new DefaultPricingPriorityFilterPolicy()); // Eval with date and no matches, this should result in default price. evalContext.CertainDate = new DateTime(2018, 09, 20); var prices = service.EvaluateProductPricesAsync(evalContext).GetAwaiter().GetResult(); Assert.Equal(10, prices.Single().List); // Eval with date falling in bounded future. evalContext.CertainDate = new DateTime(2018, 09, 27); prices = service.EvaluateProductPricesAsync(evalContext).GetAwaiter().GetResult(); Assert.Equal(3, prices.Single().List); // Eval with date falling in unbounded future. evalContext.CertainDate = new DateTime(2118, 10, 2); prices = service.EvaluateProductPricesAsync(evalContext).GetAwaiter().GetResult(); Assert.Equal(4, prices.Single().List); // Eval with date falling in bounded past. evalContext.CertainDate = new DateTime(2018, 9, 16); prices = service.EvaluateProductPricesAsync(evalContext).GetAwaiter().GetResult(); Assert.Equal(2, prices.Single().List); // Eval with date falling in unbounded past. evalContext.CertainDate = new DateTime(2018, 8, 1); prices = service.EvaluateProductPricesAsync(evalContext).GetAwaiter().GetResult(); Assert.Equal(1, prices.Single().List); // Eval with current date, should result in unbounded future price. evalContext.CertainDate = DateTime.UtcNow; prices = service.EvaluateProductPricesAsync(evalContext).GetAwaiter().GetResult(); Assert.Equal(4, prices.Single().List); // Eval without date, should result in unbounded future price. // This is also a backwards compatibilty test. // CertainDate was not used in previous price evaluation. Default to 'now' behaviour. evalContext.CertainDate = null; prices = service.EvaluateProductPricesAsync(evalContext).GetAwaiter().GetResult(); Assert.Equal(4, prices.Single().List); }
public IHttpActionResult GetProductDetailPage(int id) { int userID = 5; // get from User.Identity Product currentProduct = db.Products.Find(id); PriceEntity _price = new PriceEntity() { price = currentProduct.price, offeredPrice = currentProduct.Offers.LastOrDefault()?.price, offpercent = currentProduct.Offers.LastOrDefault()?.offPercent }; List <CommentEntity> productComments = db.Comments.Where(a => a.productID == id).Select(c => new CommentEntity { productID = c.productID, commentID = c.commentID, text = c.commentText, name = c.User.name, positive = c.positive, negative = c.negative, rate = c.rate }).ToList(); List <ProductImageEntity> productImage = db.ProductImages.Where(a => a.productID == id) .Select(c => new ProductImageEntity() { productImageID = c.productImageID }).ToList(); var productattributes = productattr(); ProductEntity productdetails = db.Products.Where(c => c.productID == id) .Select(c => new ProductEntity { isFavorite = c.Favorites.Any(r => r.userID == userID), productID = c.productID, name = c.name, shortDescription = c.shortDescription, description = c.description, category = new Models.ApiEntity.ProductCategoryEntity() { categoryName = c.ProductCategory.categoryName }, brand = new Models.ApiEntity.BrandCategory() { brandName = c.Brand.brandName }, state = new Models.ApiEntity.StateCategory() { state = c.ProductState.state } }).FirstOrDefault(); productdetails.images = productImage; productdetails.comments = productComments; productdetails.attributes = productattributes; productdetails.price = _price; List <ProductEntity> sameProducts = db.Products.Where(a => a.categoryID == id) .Select(c => new ProductEntity { productID = c.productID, name = c.name, price = new Models.ApiEntity.PriceEntity() { price = c.price, offpercent = c.Offers.OrderByDescending(w => w.offerID).FirstOrDefault().offPercent, offeredPrice = c.Offers.OrderByDescending(w => w.offerID).FirstOrDefault().price }, shortDescription = c.shortDescription, description = c.description, category = new Models.ApiEntity.ProductCategoryEntity() { categoryName = c.ProductCategory.categoryName }, brand = new Models.ApiEntity.BrandCategory() { brandName = c.Brand.brandName }, state = new Models.ApiEntity.StateCategory() { state = c.ProductState.state }, existingCount = 0 }).ToList(); sameProducts.ForEach(a => a.price = new PriceEntity() { }); var result = new { productdetail = productdetails, sameProduct = sameProducts }; return(Ok(result)); }
public ActionResult SubmitCheckPurchaseForm(ApplyBillEntity applyBillEntity, string keyValue) { try { string[] Ids = keyValue.Split(','); List <string> authList = new List <string>(); List <string> purList = new List <string>(); foreach (var Id in Ids) { int ID = Convert.ToInt32(Id); var apply = applyBillApp.GetForm(ID); apply.purExaDate = DateTime.Now; apply.purExaIdea = applyBillEntity.purExaIdea; PriceEntity price = priceApp.GetFormJson(apply.priNO); decimal sumMoney = 0; if (price.unit == apply.appUnit) { sumMoney = (price.price ?? 0) * (apply.appNum ?? 0); } else { sumMoney = (price.price ?? 0) * (apply.viceNum ?? 0); } if (applyBillEntity.purExaTag == "T")//审核通过 { apply.purExaTag = applyBillEntity.purExaTag; if (sumMoney <= 3000) { apply.purAuthMan = apply.purExaMan; apply.purAuthTag = "T"; apply.purAuthDate = DateTime.Now; applyBillApp.SubmitForm(apply, ID); } else { if (!authList.Contains(apply.purAuthMan)) { authList.Add(apply.purAuthMan); } applyBillApp.SubmitForm(apply, ID); } } else { apply.purExaTag = applyBillEntity.purExaTag; if (!purList.Contains(apply.purMan)) { purList.Add(apply.purMan); } applyBillApp.SubmitForm(apply, ID); } } if (applyBillEntity.purExaTag == "T") { foreach (var item in authList) { var user = userApp.GetFormByName(item); if (!string.IsNullOrEmpty(user.F_Email)) { mHelper.MailServer = "10.110.120.2"; mHelper.Send(user.F_Email, "采购单审批", "你好,有采购单需要你登录OA去做审批,请点击链接<a>http://10.110.120.6:8090/</a>"); } } } else { foreach (var item in purList) { var user = userApp.GetFormByName(item); if (!string.IsNullOrEmpty(user.F_Email)) { mHelper.MailServer = "10.110.120.2"; mHelper.Send(user.F_Email, "采购单审核不通过", "你好,你的采购单审核不通过,详情查看请点击链接<a>http://10.110.120.6:8090/</a>"); } } } return(Success("操作成功。")); } catch (Exception ex) { return(Error("操作失败。")); } }