コード例 #1
0
        public List <Tuple <string, decimal> > GetTourByMonthBenefitStatistic(StatisticBindingModel model, int _OperatorID)
        {
            var listTours = new List <TourViewModel>();

            if (_OperatorID != 0)
            {
                listTours = implementer.GetTourByMonthStatistic(model, _OperatorID);
            }
            else
            {
                listTours = implementer.GetAllTourByMonthStatistic(model);
            }

            var tours = listTours.OrderByDescending(rec => rec.Price).GroupBy(rec => rec.Country, rec => rec.Price)
                        .Select(rec => new Tuple <string, decimal>(rec.Key, rec.Sum())).ToList().OrderByDescending(rec => rec.Item2).ToList();

            var result = listTours.OrderByDescending(rec => rec.Price).GroupBy(rec => rec.Country, rec => rec.Price)
                         .Select(rec => new Tuple <string, decimal>(rec.Key, rec.Sum())).Take(5).ToList().OrderByDescending(rec => rec.Item2).ToList();

            if (tours.Count > 5)
            {
                decimal sumprice = 0;
                for (int i = 4; i < tours.Count - 1; i++)
                {
                    sumprice += tours[i].Item2;
                }
                result.Add(new Tuple <string, decimal>("Другие", sumprice));
            }
            return(result);
        }
コード例 #2
0
        public List <Tuple <string, int> > GetTourByMonthStatistic(StatisticBindingModel model, int _OperatorID)
        {
            var listTours = new List <TourViewModel>();

            if (_OperatorID != 0)
            {
                listTours = implementer.GetTourByMonthStatistic(model, _OperatorID);
            }
            else
            {
                listTours = implementer.GetAllTourByMonthStatistic(model);
            }

            var countTours = listTours.OrderBy(rec => rec.Country).GroupBy(rec => new { rec.Country })
                             .Select(rec => new Tuple <string, int>(rec.Key.Country, rec.Count())).ToList().OrderByDescending(rec => rec.Item2).ToList();

            var result = new List <Tuple <string, int> >();

            if (countTours.Count > 5)
            {
                int sumcount = 0;
                for (int i = 4; i < countTours.Count - 1; i++)
                {
                    sumcount += countTours[i].Item2;
                }
                result.Add(new Tuple <string, int>("Другие", sumcount));
            }

            return(countTours);
        }
コード例 #3
0
 public List <TourViewModel> GetAllTourByMonthStatistic(StatisticBindingModel model)
 {
     using (var context = new TourFirmDatabase())
     {
         var tours = from tour in context.Tours
                     join travelTours in context.TravelTours
                     on tour.ID equals travelTours.TourID
                     join travel in context.Travels
                     on travelTours.TravelID equals travel.ID
                     where travel.DateStart.Month == model.month
                     select new TourViewModel
         {
             Country = tour.Country,
             Price   = tour.Price
         };
         return(tours.ToList());
     }
 }
コード例 #4
0
 public void Steps([Bind(Include = "Date,Steps")] StatisticBindingModel bindingModel, string username)
 {
     if (ModelState.IsValid)
     {
         ApplicationUser user = context.Users.FirstOrDefault(u => u.UserName == username);
         if (user == null)
         {
             throw new ArgumentException("The username is invalid");
         }
         Statistic statistic = new Statistic()
         {
             Date  = bindingModel.Date,
             Steps = bindingModel.Steps
         };
         user.Statistics.Add(statistic);
         context.SaveChanges();
     }
 }