/// <summary> /// Récupérer un Offer en base /// </summary> /// <param name="offerId">Id de l'Offer</param> /// <returns>Offer</returns> public Offer GetOffer(int offerId) { OfferQuery fq = new OfferQuery(_context); Offer o = fq.GetById(offerId); o.Status = this.GetStatus(o.StatusId); o.Postulations = this.GetPostulationsFromOffer(o); return(o); }
public void Post_order() { var data = service.GetPrices(false, false, new[] { "OriginalName" }, new[] { "*" }, new string[] { }, new string[] { }, 100, 0); Assert.That(data.Tables[0].Rows.Count, Is.GreaterThan(0), "предложений нет"); var coreId = Convert.ToUInt64(data.Tables[0].Rows[0]["OrderID"]); session.CreateSQLQuery(@" update farm.core0 set RequestRatio = 5, OrderCost = 10.5, MinOrderCount = 10 where id = :CoreId") .SetParameter("CoreId", coreId) .ExecuteUpdate(); var result = service.PostOrder(new[] { coreId }, new[] { 20u }, new[] { "это тестовый заказ" }, new[] { Convert.ToUInt32(data.Tables[0].Rows[0]["OrderCode1"]) }, new[] { Convert.ToUInt32(data.Tables[0].Rows[0]["OrderCode2"]) }, new[] { false }); Assert.That(result.Tables[0].Rows.Count, Is.EqualTo(1), "ни вернули ни одной записи"); Assert.That(result.Tables[0].Rows[0]["OriginalOrderID"], Is.EqualTo(coreId), "заказали что то не то, идентификатор из core не совпал"); var orderid = Convert.ToUInt32(result.Tables[0].Rows[0]["OrderId"]); session.BeginTransaction(); var offer = OfferQuery.GetById(session, user, coreId); var order = session.Load <Order>(orderid); var orderLine = (from orderItem in order.OrderItems where orderItem.CoreId == coreId select orderItem).Single(); Assert.That(offer.Id.CoreId, Is.EqualTo(orderLine.CoreId)); Assert.That(orderLine.RequestRatio, Is.EqualTo(offer.RequestRatio)); Assert.That(orderLine.MinOrderCount, Is.EqualTo(offer.MinOrderCount)); Assert.That(orderLine.OrderCost, Is.EqualTo(offer.OrderCost)); }
private static Order OrderParse(ISession session, uint userId, DataTable table) { var user = session.Load <User>(userId); Order order = null; if (table.Rows.Count == 0) { return(null); } var supplierDeliveryId = table.Rows[0]["PODRCD"].ToString(); uint id; unchecked { id = (uint)table.Rows[0]["NUMZ"].GetHashCode(); } var reject = new Reject { DepId = supplierDeliveryId, OrderId = id }; foreach (DataRow row in table.Rows) { uint qunatity; try { qunatity = Convert.ToUInt32(row["QNT"]); } catch (Exception) { qunatity = SafeConvert.ToUInt32(row["QNT"].ToString()); } var cost = Convert.ToDecimal(row["PRICE"]); var offerId = SafeConvert.ToUInt64(row["XCODE"].ToString()); var code = row["CODEPST"].ToString(); var name = row["NAME"].ToString(); reject.Items.Add(new RejectItem(id, code, qunatity, name, cost, offerId)); } var addressIds = Program.GetAddressId(session, supplierDeliveryId, null, Program.SupplierIdForCodeLookup, user); var address = session.Load <Address>(addressIds[0]); var rules = session.Load <OrderRules>(user.Client.Id); rules.Strict = false; rules.CheckAddressAccessibility = false; List <ActivePrice> activePrices; using (StorageProcedures.GetActivePrices((MySqlConnection)session.Connection, userId)) { activePrices = session.Query <ActivePrice>().ToList(); } var existOrder = session.Query <Order>().FirstOrDefault(o => o.UserId == userId && o.ClientOrderId == id && !o.Deleted); if (existOrder != null) { throw new UserFriendlyException( $"Дублирующий заказ {id}, существующий заказ {existOrder.RowId}", "Дублирующая заявка"); } var ordered = new List <RejectItem>(); foreach (var item in reject.Items) { try { var offer = OfferQuery.GetById(session, user, item.OfferId); if (offer == null) { var archiveOffer = session.Get <ArchiveOffer>(item.OfferId); if (archiveOffer == null) { throw new UserFriendlyException($"Не удалось найти предложение {item.OfferId} игнорирую строку", "Заявка сделана по неактуальному прайс-листу"); } offer = archiveOffer.ToOffer(activePrices, item.Price); if (offer == null) { throw new UserFriendlyException( $"Прайс {archiveOffer.PriceList.PriceCode} больше не доступен клиенту игнорирую строку", "Прайс-лист отключен"); } } if (order == null) { order = new Order(offer.PriceList, user, address, rules); order.ClientOrderId = id; } order.AddOrderItem(offer, item.Quantity); ordered.Add(item); } catch (OrderException e) { log.Warn($"Не удалось заказать позицию {item.Name} в количестве {item.Quantity}", e); } } foreach (var rejectItem in ordered) { reject.Items.Remove(rejectItem); } if (order != null && order.OrderItems.Count == 0) { return(null); } return(order); }
public Offer GetOfferById(int id) { OfferQuery oq = new OfferQuery(contexte); return(oq.GetById(id)); }
private static Order OrderParse(ISession session, uint userId, XDocument doc, List <Reject> rejects, TextWriter logForClient, out uint id) { var user = session.Load <User>(userId); id = 0; Order order = null; var packet = doc.XPathSelectElement("/PACKET"); if (packet == null) { return(null); } var type = (string)packet.Attribute("TYPE"); if (type == null) { return(null); } var predId = (string)packet.Attribute("PRED_ID"); var to = (string)packet.Attribute("TO"); var from = (string)packet.Attribute("FROM"); var depId = (string)doc.XPathSelectElement("/PACKET/ORDER/DEP_ID"); var orderElement = doc.XPathSelectElement("/PACKET/ORDER"); var clientOrderId = SafeConvert.ToUInt32((string)orderElement.XPathSelectElement("ORDER_ID")); id = clientOrderId; var reject = new Reject { To = to, From = @from, PredId = predId, DepId = depId, OrderId = clientOrderId }; var items = orderElement.XPathSelectElements("ITEMS/ITEM"); foreach (var item in items) { var qunatity = SafeConvert.ToUInt32((string)item.XPathSelectElement("QTTY")); var cost = Convert.ToDecimal((string)item.XPathSelectElement("PRICE")); var offerId = SafeConvert.ToUInt64((string)item.XPathSelectElement("XCODE")); var code = (string)item.XPathSelectElement("CODE"); var name = (string)item.XPathSelectElement("NAME"); reject.Items.Add(new RejectItem(clientOrderId, code, qunatity, name, cost, offerId)); } rejects.Add(reject); var addressIds = Program.GetAddressId(session, reject.DepId.Slice(-2, -1), reject.PredId, Program.SupplierIdForCodeLookup, user); var address = session.Load <Address>(addressIds[0]); var rules = session.Load <OrderRules>(user.Client.Id); rules.Strict = false; rules.CheckAddressAccessibility = false; List <ActivePrice> activePrices; using (StorageProcedures.GetActivePrices((MySqlConnection)session.Connection, userId)) { activePrices = session.Query <ActivePrice>().ToList(); } var comment = (string)orderElement.XPathSelectElement("COMMENT"); var existOrder = session.Query <Order>().FirstOrDefault(o => o.UserId == userId && o.ClientOrderId == clientOrderId && !o.Deleted); if (existOrder != null) { throw new UserFriendlyException( $"Дублирующий заказ {clientOrderId}, существующий заказ {existOrder.RowId}", "Дублирующая заявка"); } var ordered = new List <RejectItem>(); foreach (var item in reject.Items) { try { var offer = OfferQuery.GetById(session, user, item.OfferId); if (offer == null) { var archiveOffer = session.Get <ArchiveOffer>(item.OfferId); if (archiveOffer == null) { throw new UserFriendlyException($"Не удалось найти предложение {item.OfferId} игнорирую строку", "Заявка сделана по неактуальному прайс-листу"); } offer = archiveOffer.ToOffer(activePrices, item.Price); if (offer == null) { throw new UserFriendlyException( $"Прайс {archiveOffer.PriceList.PriceCode} больше не доступен клиенту игнорирую строку", "Прайс-лист отключен"); } } if (order == null) { order = new Order(offer.PriceList, user, address, rules); order.ClientAddition = comment; order.ClientOrderId = clientOrderId; } order.AddOrderItem(offer, item.Quantity); ordered.Add(item); } catch (OrderException e) { var message = Utils.TryGetUserFriendlyMessage(e); log.Warn($"Не удалось заказать позицию {item.Name} в количестве {item.Quantity}", e); logForClient.WriteLine("Не удалось заказать позицию {0} по заявке {3} в количестве {1}: {2}", item.Name, item.Quantity, message, clientOrderId); } } foreach (var rejectItem in ordered) { reject.Items.Remove(rejectItem); } if (reject.Items.Count == 0) { rejects.Remove(reject); } if (order != null && order.OrderItems.Count == 0) { return(null); } return(order); }