Exemplo n.º 1
0
        public void Write_Then_Read_Order()
        {
            var order = new ApiOrder()
            {
                OrderId         = 9998990005,
                MerchantOrderId = 12,
                Amount          = 29990,
                CurrencyCode    = "EUR",
                CountryCode     = "DK",
                LanguageCode    = "dn"
            };

            var sb = new StringBuilder();

            order.AddToStringBuilder(sb);
            var orderAsString = sb.ToString();

            var order2 = new ApiOrder(new ModifiedXmlDocument(orderAsString), string.Empty);

            Assert.AreEqual(order.OrderId, order2.OrderId);
            Assert.AreEqual(order.MerchantOrderId, order2.MerchantOrderId);
            Assert.AreEqual(order.Amount, order2.Amount);
            Assert.AreEqual(order.CurrencyCode, order2.CurrencyCode);
            Assert.AreEqual(order.CountryCode, order2.CountryCode);
            Assert.AreEqual(order.LanguageCode, order2.LanguageCode);
        }
Exemplo n.º 2
0
        public ApiOrder Add(ApiOrder apiOrder)
        {
            db.Orders.Add(Mapper.Map <ApiOrder, Order>(apiOrder));
            apiOrder.OrderID = db.SaveChanges();

            return(apiOrder);
        }
        public InsertOrderWithPayment()
            : base("INSERT_ORDERWITHPAYMENT")
        {
            Order   = new ApiOrder();
            Payment = new ApiPayment();

            Params.Parameters.Add(Order);
            Params.Parameters.Add(Payment);
        }
        public async Task <ApiResponseBase> Post([FromBody] ApiOrder product)
        {
            var user = await GetCurrentUserAsync().ConfigureAwait(false);

            var isAdmin = await _userManager.IsInRoleAsync(user, UserRole.Admin).ConfigureAwait(false);

            isAdmin = isAdmin || await _userManager.IsInRoleAsync(user, UserRole.AdminAssistant).ConfigureAwait(false);

            await _repo.UpdateAsync(user.Id, isAdmin, product);

            return(new ApiResponseBase());
        }
Exemplo n.º 5
0
 public ApiOrder Post([FromBody] ApiOrder apiOrder)
 {
     try
     {
         apiOrder = service.Add(apiOrder);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(apiOrder);
 }
Exemplo n.º 6
0
        public void Read_Order()
        {
            var doc   = new ModifiedXmlDocument(OrderText);
            var order = new ApiOrder(doc, string.Empty);

            Assert.AreEqual(9998990005, order.OrderId);
            Assert.AreEqual(29990, order.Amount);
            Assert.AreEqual("EUR", order.CurrencyCode);
            Assert.AreEqual("NL", order.CountryCode);
            Assert.AreEqual("nl", order.LanguageCode);
            Assert.IsFalse(order.MerchantOrderId.HasValue);
        }
Exemplo n.º 7
0
 public ApiOrder Put([FromBody] ApiOrder apiOrder)
 {
     try
     {
         int?id = apiOrder.OrderID;
         apiOrder = service.Update(id, apiOrder);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(new ApiOrder());
 }
Exemplo n.º 8
0
        public void Can_Add_Extra_Data_To_Order()
        {
            // Arrange
            var order = new ApiOrder {
                OrderId = 123, LanguageCode = "da", MerchantReference = "JustMyLuck"
            };

            // Act
            order.AddExtraData("Ucommerce", "ECOM");
            var text = ConvertApiDataPartToString(order);

            // Assert
            Assert.IsTrue(text.Contains("<ECOM>Ucommerce</ECOM>"));
        }
Exemplo n.º 9
0
        public ApiOrder Update(int?id, ApiOrder apiOrder)
        {
            var orderInDB = db.Orders.Where(o => o.OrderID == id).FirstOrDefault();

            if (orderInDB != null)
            {
                apiOrder.OrderID          = orderInDB.OrderID;
                orderInDB                 = Mapper.Map <ApiOrder, Order>(apiOrder);
                db.Entry(orderInDB).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }

            return(apiOrder);
        }
Exemplo n.º 10
0
        public ApiOrder GetSingle(int?id)
        {
            ApiOrder apiOrder = new ApiOrder();

            try
            {
                apiOrder = service.GetSingle(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(apiOrder);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Orderings the apply.
        /// </summary>
        /// <param name="swaggerDoc">The swagger document.</param>
        /// <param name="schemaRegistry">The schema registry.</param>
        /// <param name="apiExplorer">The API explorer.</param>
        internal static void OrderingApply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer)
        {
            var paths = swaggerDoc.paths;

            if (paths == null || !paths.Any())
            {
                return;
            }

            var tagGroups = new Dictionary <string, IList <ApiOrder> >();

            foreach (var path in paths)
            {
                var key      = GetInvokeMethod(path.Value, out var tag);
                var apiKey   = $"{key}{path.Key.TrimStart('/')}";
                var apiFound = apiExplorer.ApiDescriptions.FirstOrDefault(c => c.ID.StartsWith(apiKey));

                if (!tagGroups.ContainsKey(tag))
                {
                    tagGroups.Add(tag, new List <ApiOrder>());
                }

                var item = new ApiOrder
                {
                    Order         = GetApiOrder(apiFound),
                    PathKey       = path.Key,
                    PathValue     = path.Value,
                    OperationName = tag
                };

                tagGroups[tag].Add(item);
                tagGroups[tag] = tagGroups[tag].OrderBy(c => c.Order).ToList();
            }

            var list = new List <ApiOrder>();

            foreach (var tagGroup in tagGroups)
            {
                list.AddRange(tagGroup.Value);
            }

            swaggerDoc.paths = list.OrderBy(c => c.OperationName).ToDictionary(c => c.PathKey, c => c.PathValue);
        }
Exemplo n.º 12
0
        public async Task <ActionResult <ApiOrder> > GetOrder(int id)
        {
            ApiOrder apiOrder = new ApiOrder();

            using (_context)
            {
                //Gets the overview of the order with the select id.
                apiOrder.order = await _context.OrderOverview.FindAsync(id);

                //Gets all items associated with the order.
                var orderQuery = from item in _context.OrderItem where item.OrderId == id select item;
                apiOrder.items = orderQuery.ToList();
            }

            if (apiOrder.order == null)
            {
                return(NotFound());
            }
            //Returns the apiOrder - which includes the orderoverview and order items.
            return(apiOrder);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Processes the item method ordering.
        /// </summary>
        /// <param name="group">The group.</param>
        /// <param name="apiExplorer">The API explorer.</param>
        /// <returns>IDictionary&lt;System.String, PathItem&gt;.</returns>
        private static IDictionary <string, PathItem> ProcessItemMethodOrdering(IDictionary <string, PathItem> group,
                                                                                IApiExplorer apiExplorer)
        {
            var tagGroups = new Dictionary <string, IList <ApiOrder> >();

            foreach (var path in group)
            {
                var key      = GetInvokeMethod(path.Value, out var tag);
                var apiKey   = $"{key}{path.Key.TrimStart('/')}";
                var apiFound = apiExplorer.ApiDescriptions.FirstOrDefault(c => c.ID.StartsWith(apiKey));

                if (!tagGroups.ContainsKey(tag))
                {
                    tagGroups.Add(tag, new List <ApiOrder>());
                }

                var item = new ApiOrder
                {
                    Order         = GetApiOrder(apiFound),
                    PathKey       = path.Key,
                    PathValue     = path.Value,
                    OperationName = tag
                };

                tagGroups[tag].Add(item);
                tagGroups[tag] = tagGroups[tag].OrderBy(c => c.Order).ToList();
            }

            var list = new List <ApiOrder>();

            foreach (var tagGroup in tagGroups)
            {
                list.AddRange(tagGroup.Value);
            }

            return(list.OrderBy(c => c.OperationName).ToDictionary(c => c.PathKey, c => c.PathValue));
        }
Exemplo n.º 14
0
 public ApiOrder Post([FromBody] ApiOrder apiorder)
 {
     return(apiorder);
 }
Exemplo n.º 15
0
 public ApiOrder Update(int?id, ApiOrder order)
 {
     return(factory.OrderDAO.Update(id, order));
 }
Exemplo n.º 16
0
 public GetOrderStatus() : base("GET_ORDERSTATUS")
 {
     Order = new ApiOrder();
     Params.Parameters.Add(Order);
 }
 private static Order MapOrder(ApiOrder apiOrder)
 => Order.Create(apiOrder.Id, apiOrder.Lines.Select(MapOrderLine).ToList());
Exemplo n.º 18
0
 public ApiOrder Add(ApiOrder order)
 {
     return(factory.OrderDAO.Add(order));
 }
 public GetOrder()
     : base("GET_ORDER")
 {
     Order = new ApiOrder();
     Params.Parameters.Add(Order);
 }
Exemplo n.º 20
0
 protected OrderAdapter(ApiMarketGateway marketGateway, ApiOrder apiOrder)
 {
     this.apiOrder      = apiOrder;
     this.MarketGateway = marketGateway;
 }
Exemplo n.º 21
0
        public async Task UpdateAsync(string userId, bool isAdmin, ApiOrder it)
        {
            await using var context = _di.GetRequiredService <ApplicationDbContext>();
            var order = await context.Orders.FindAsync(it.Id);

            if (order != null)
            {
                if (order.Status == OrderStatus.Canceled)
                {
                    throw new ArgumentException("Замовлення скасоване і не може редагуватися");
                }
                order.ClientName    = it.ClientName;
                order.ClientAddress = it.ClientAddress;
                order.ClientPhone   = it.ClientPhone;
                order.OrderNumber   = it.OrderNumber;
                order.Other         = it.Other;
                order.Status        = it.Status ?? OrderStatus.Open;
                order.Payment       = it.Payment;
                if (it.Status == OrderStatus.Delivered && order.CloseDate == null)
                {
                    order.CloseDate = DateTime.UtcNow;
                }
                if (it.Status == OrderStatus.Canceled && order.CanceledDate == null)
                {
                    order.CanceledDate     = DateTime.UtcNow;
                    order.CanceledByUserId = userId;
                }

                var note      = order.ResponsibleUserId != userId ? "Відредаговано іншим продавцем" : null;
                var operation = OrderOperation.Created;
                if (order.Id != 0)
                {
                    switch (order.Status)
                    {
                    case OrderStatus.Canceled: operation = OrderOperation.Canceled; break;

                    case OrderStatus.Delivered: operation = OrderOperation.Closed; break;

                    default: operation = OrderOperation.Updated; break;
                    }
                }

                order.OrderEditions = new List <OrderAction>(new[] {
                    new OrderAction {
                        Date      = DateTime.UtcNow,
                        OrderId   = order.Id,
                        UserId    = userId,
                        Note      = note,
                        Operation = operation,
                        OrderJson = JsonConvert.SerializeObject(it)
                    }
                });

                it.Products = null; // we do not want to sent this back to the client.
                await Informer.OrderChangedAsync(new[] { new ApiOrderDetailsChange
                                                         {
                                                             OrderId    = order.Id,
                                                             Order      = it,
                                                             ChangeTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
                                                         } }).ConfigureAwait(false);
            }
            await context.SaveChangesAsync().ConfigureAwait(false);
        }
 public CancelOrder()
     : base("CANCEL_ORDER")
 {
     Order = new ApiOrder();
     Params.Parameters.Add(Order);
 }
Exemplo n.º 23
0
 public ApiOrder Put(int?id, [FromBody] ApiOrder apiorder)
 {
     return(apiorder);
 }