Пример #1
0
        public IActionResult getOrders(string firstDate, string seconedDate)
        {
            var UserOrder = new UserOrders();

            var UserOrdersList = new List <UserOrders>();

            try
            {
                if (firstDate != null && seconedDate != null)
                {
                    var first     = Convert.ToDateTime(firstDate);
                    var Seconed   = Convert.ToDateTime(seconedDate);
                    var Checkouts = db.Checkouts
                                    .Where(x => x.CheckoutDate >= first && x.CheckoutDate <= Seconed)
                                    .Include(x => x.User).ToList();
                    var data = from chcekout in Checkouts
                               group chcekout by chcekout.UserId into Amounts
                               select new
                    {
                        useId        = Amounts.Key,
                        AverageScore = Amounts.Average(x => x.TotalAmount),
                        totalOrders  = Amounts.Count(),
                        totlAmount   = Amounts.Sum(v => v.TotalAmount),
                    };
                    var dat1 = data.ToList();

                    foreach (var item in dat1)
                    {
                        UserOrder                  = new UserOrders();
                        UserOrder.AvgOrderAmt      = item.AverageScore;
                        UserOrder.NoOfOrders       = item.totalOrders;
                        UserOrder.TotalOrderAmount = item.totlAmount;
                        if (item.useId > 0)
                        {
                            var username = db.Users.Where(x => x.Id == item.useId).FirstOrDefault().FirstName;
                            if (username != null)
                            {
                                UserOrder.UserName = username;
                            }
                            UserOrder.period = first.Date.ToShortDateString() + " to " + Seconed.Date.ToShortDateString();
                        }
                        UserOrdersList.Add(UserOrder);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(Ok(UserOrdersList));
        }
Пример #2
0
        public IActionResult getOrdersDOY(string DOY)
        {
            var UserOrder      = new UserOrders();
            var Checkouts      = new List <Checkout>();
            var UserOrdersList = new List <UserOrders>();

            try
            {
                if (DOY != null)
                {
                    if (DOY.ToLower() == "day")
                    {
                        Checkouts = db.Checkouts
                                    .Where(x => x.CheckoutDate.Day == DateTime.Now.Date.Day)
                                    .Include(x => x.User).ToList();
                    }
                    else if (DOY.ToLower() == "month")
                    {
                        Checkouts = db.Checkouts
                                    .Where(x => x.CheckoutDate.Month == DateTime.Now.Date.Month)
                                    .Include(x => x.User).ToList();
                    }
                    else if (DOY.ToLower() == "year")
                    {
                        Checkouts = db.Checkouts
                                    .Where(x => x.CheckoutDate.Year == DateTime.Now.Date.Year)
                                    .Include(x => x.User).ToList();
                    }

                    var data = from chcekout in Checkouts
                               group chcekout by chcekout.UserId into Amounts
                               select new
                    {
                        useId        = Amounts.Key,
                        AverageScore = Amounts.Average(x => x.TotalAmount),
                        totalOrders  = Amounts.Count(),
                        totlAmount   = Amounts.Sum(v => v.TotalAmount),
                    };
                    var dat1 = data.ToList();

                    foreach (var item in dat1)
                    {
                        UserOrder                  = new UserOrders();
                        UserOrder.AvgOrderAmt      = item.AverageScore;
                        UserOrder.NoOfOrders       = item.totalOrders;
                        UserOrder.TotalOrderAmount = item.totlAmount;
                        if (item.useId > 0)
                        {
                            var username = db.Users.Where(x => x.Id == item.useId).FirstOrDefault().FirstName;
                            if (username != null)
                            {
                                UserOrder.UserName = username;
                            }
                            if (DOY.ToLower() == "day")
                            {
                                UserOrder.period = DateTime.Now.Day + "/" + DateTime.Now.Year;
                            }
                            else if (DOY.ToLower() == "month")
                            {
                                UserOrder.period = DateTime.Now.Month + "/" + DateTime.Now.Year;
                            }
                            else if (DOY.ToLower() == "year")
                            {
                                UserOrder.period = DateTime.Now.Year.ToString();
                            }
                        }
                        UserOrdersList.Add(UserOrder);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(Ok(UserOrdersList));
        }