public async Task <JsonResult> Get(int pageIndex,
                                           int pageSize,
                                           string pageOrder,
                                           string userName,
                                           int?orderID,
                                           int?fromPrice,
                                           int?toPrice,
                                           string fromDate,
                                           string toDate,
                                           sbyte cartStatus,
                                           SendMethodType?sendMethodType,
                                           PaymentMethodType?paymentMethodType)
        {
            DateTime?sDate = null,
                    eDate  = null;

            CartStatus?crtStatus = null;

            if (!String.IsNullOrWhiteSpace(fromDate))
            {
                sDate = Utilities.ToEnglishDate(fromDate).Date;
            }

            if (!String.IsNullOrWhiteSpace(toDate))
            {
                eDate = Utilities.ToEnglishDate(toDate).Date;
            }

            if (cartStatus != -1)
            {
                crtStatus = (CartStatus)cartStatus;
            }

            var list = Carts.Get(pageIndex,
                                 pageSize,
                                 pageOrder,
                                 orderID,
                                 fromPrice,
                                 toPrice,
                                 sDate,
                                 eDate,
                                 crtStatus,
                                 null,
                                 sendMethodType,
                                 paymentMethodType,
                                 "",
                                 OrderStatus.Unsuccessful);

            foreach (var item in list)
            {
                var user = (await UserManager.FindByIdAsync(item.UserID));
                if (user != null)
                {
                    item.UserName  = user.UserName;
                    item.Firstname = user.Firstname;
                    item.Lastname  = user.Lastname;
                }
            }

            int total = Carts.Count(orderID,
                                    fromPrice,
                                    toPrice,
                                    sDate,
                                    eDate,
                                    crtStatus,
                                    null,
                                    sendMethodType,
                                    paymentMethodType,
                                    "",
                                    OrderStatus.Unsuccessful);

            int totalPage = (int)Math.Ceiling((decimal)total / pageSize);

            if (pageSize > total)
            {
                pageSize = total;
            }

            if (list.Count < pageSize)
            {
                pageSize = list.Count;
            }

            JsonResult result = new JsonResult()
            {
                Data = new
                {
                    TotalPages = totalPage,
                    PageIndex  = pageIndex,
                    PageSize   = pageSize,
                    Rows       = list
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            return(result);
        }
Ejemplo n.º 2
0
        public string SolvePart2(string input, IProgress <string> progress = null)
        {
            Parse(input);
            while (true)
            {
                if (Carts.Count(c => !c.Crashed) == 1)
                {
                    var cart = Carts.First(c => !c.Crashed);
                    return((cart.X, cart.Y).ToString());
                }

                foreach (var cart in Carts.OrderBy(c => c.Y).ThenBy(c => c.X))
                {
                    if (cart.Crashed)
                    {
                        continue;
                    }

                    var next      = cart.GetNextLocation();
                    var otherCart = Carts.FirstOrDefault(c => !c.Crashed && c.X == next.x && c.Y == next.y);
                    if (otherCart != null)
                    {
                        cart.Crashed      = true;
                        otherCart.Crashed = true;
                    }

                    char track = LookAhead(cart);
                    switch (cart.Direction)
                    {
                    case Direction.Up:
                        cart.Y--;
                        switch (track)
                        {
                        case '\\':
                            cart.Direction = Direction.Left;
                            break;

                        case '/':
                            cart.Direction = Direction.Right;
                            break;

                        case '+':
                            IntersectionTurn(cart);
                            break;
                        }
                        break;

                    case Direction.Down:
                        cart.Y++;
                        switch (track)
                        {
                        case '\\':
                            cart.Direction = Direction.Right;
                            break;

                        case '/':
                            cart.Direction = Direction.Left;
                            break;

                        case '+':
                            IntersectionTurn(cart);
                            break;
                        }
                        break;

                    case Direction.Left:
                        cart.X--;
                        switch (track)
                        {
                        case '\\':
                            cart.Direction = Direction.Up;
                            break;

                        case '/':
                            cart.Direction = Direction.Down;
                            break;

                        case '+':
                            IntersectionTurn(cart);
                            break;
                        }
                        break;

                    case Direction.Right:
                        cart.X++;
                        switch (track)
                        {
                        case '\\':
                            cart.Direction = Direction.Down;
                            break;

                        case '/':
                            cart.Direction = Direction.Up;
                            break;

                        case '+':
                            IntersectionTurn(cart);
                            break;
                        }
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
        }