Beispiel #1
0
        public async Task <HttpResponseMessage> BeeCommHook([FromBody] BeeComm.OrderHook model)
        {
            try
            {
                LoggerSingleton.Instance.Info("BeeCommHook", $"Order Arrived");

                /* DUMP */
                try
                {
                    var payload = "";
                    using (var stream = await Request.Content.ReadAsStreamAsync())
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                        using (var sr = new StreamReader(stream))
                            payload = sr.ReadToEnd();
                    }
                    File.AppendAllText($"{AppDomain.CurrentDomain.BaseDirectory}OrdersBK\\payload_{Guid.NewGuid()}.txt", payload);
                }
                catch { }

                if (model.Details.SenderCompanyId == ConfigSingleton.Instance.BeecommSenderCompanyId) // MNEW
                {
                    return(Request.CreateResponse(HttpStatusCode.OK));
                }

                if (string.IsNullOrEmpty(model.CustomerId))
                {
                    model.CustomerId = "5fc517cb898f9173dbf4adc6"; // TODO ->> Temporary
                }
                var order = await OrdersBLL.BeeCommOrder2Order(model);

                var orderId = await new OrdersBLL().Create(order, false);
                LoggerSingleton.Instance.Info("BeeCommHook", $"Order {orderId} has created", new List <string> {
                    JsonConvert.SerializeObject(model)
                });

                File.AppendAllText($"{AppDomain.CurrentDomain.BaseDirectory}OrdersBK\\order_{Guid.NewGuid()}.txt", JsonConvert.SerializeObject(model));

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                LoggerSingleton.Instance.Error("BeeCommHook", ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }