Exemple #1
0
        private void CompareToAdjustTransactionColor(CompareViewModel compareViewModel)
        {
            var oldTransactions = compareViewModel.TransactionsToCompare.First();

            foreach (var actualTransactions in compareViewModel.TransactionsToCompare.Skip(1))
            {
                foreach (var transactionToCompared in oldTransactions.Transactions)
                {
                    var comparedTransaction = actualTransactions.Transactions.FirstOrDefault(t => t.Category.Name.Equals(transactionToCompared.Category.Name));

                    if (comparedTransaction != null)
                    {
                        if (comparedTransaction.Amount == transactionToCompared.Amount)
                        {
                            comparedTransaction.Color = "info";
                        }
                        else if (comparedTransaction.Amount < transactionToCompared.Amount)
                        {
                            comparedTransaction.Color = "success";
                        }
                        else
                        {
                            comparedTransaction.Color = "danger";
                        }
                    }
                }
                oldTransactions = actualTransactions;
            }
        }
Exemple #2
0
        public ActionResult Index(JsonFileViewModel _viewModel)
        {
            string s = "";

            using (StreamReader sr = new StreamReader(Server.MapPath("~/UserData/") + "tmp.txt"))
            {
                while ((s = sr.ReadLine()) != null)
                {
                    _fileName = s;
                }
            }
            string Json = System.IO.File.ReadAllText(_fileName);
            JavaScriptSerializer ser       = new JavaScriptSerializer();
            JsonFileViewModel    viewModel = new JsonFileViewModel();
            List <CcorrectModel> ldbModel  = ConvertJsonToModel(ser.Deserialize <List <CRFID> >(Json));

            CorrectJsonData(ldbModel);

            string json = JsonConvert.SerializeObject(ConvertModelToJson(ldbModel).ToArray(), Formatting.Indented);

            System.IO.File.WriteAllText(_fileName.Insert(_fileName.Length - 5, "_correct"), json);

            CompareViewModel compareViewModel = new CompareViewModel
            {
                _oldModel = ConvertJsonToModel(ser.Deserialize <List <CRFID> >(Json)),
                _newModel = ldbModel
            };

            return(View("Compare", compareViewModel));
        }
Exemple #3
0
        public ActionResult removeItem(int id)
        {
            string name = "matches";
            int    _cnt = Convert.ToInt32(Session["cnt"]);

            int lim = Convert.ToInt32(Session["lim"]);

            List <CompareViewModel> model = new List <CompareViewModel>();

            for (int i = 1; i <= _cnt; i++)
            {
                if ((Session[name + i.ToString()]).ToString() == "none")
                {
                    continue;
                }
                CompareViewModel p = (CompareViewModel)Session[name + i.ToString()];
                if (p.PlaceId == id)
                {
                    Session[name + i.ToString()] = "none";
                    lim--; Session["lim"]        = lim.ToString();
                    continue;
                }
                model.Add(p);
            }
            //return View("compare", model);
            return(RedirectToAction("compare", "users"));
        }
Exemple #4
0
        public IActionResult Compare()
        {
            var items = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = "Days", Value = "1", Selected = true
                },
                new SelectListItem()
                {
                    Text = "Weeks", Value = "2"
                },
                new SelectListItem()
                {
                    Text = "Months", Value = "3"
                },
            };
            var model = new CompareViewModel
            {
                PaybackDurationType  = 1,
                PaybackDurationTypes = items
            };

            return(View(model));
        }
Exemple #5
0
        public async Task <IActionResult> AddToCart(CompareViewModel CompareObject)
        {
            if (ModelState.IsValid)
            {
                var claimsIdentity = (ClaimsIdentity)this.User.Identity;
                var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

                ShoppingCart shop       = new ShoppingCart();
                ShoppingCart cartFromDb = await _db.ShoppingCart.Where(c => c.ApplicationUserId == claim.Value && c.MenuItemId == CompareObject.Compare.MenuItemId).FirstOrDefaultAsync();

                if (cartFromDb == null)
                {
                    var mn = await _db.MenuItem.FirstOrDefaultAsync(m => m.Id == CompareObject.Compare.MenuItemId);

                    shop.ApplicationUserId = claim.Value;
                    shop.Count             = 1;
                    shop.MenuItemId        = mn.Id;
                    await _db.ShoppingCart.AddAsync(shop);
                }
                else
                {
                    return(RedirectToAction("Index", "Cart"));
                }
                await _db.SaveChangesAsync();

                var count = _db.ShoppingCart.Where(c => c.ApplicationUserId == shop.ApplicationUserId).ToList().Count();
                HttpContext.Session.SetInt32("ssCartCount", count);

                return(RedirectToAction("Index", "Cart"));
            }
            else
            {
                return(View());
            }
        }
        public ActionResult RemoveFromCompare(int productId)
        {
            CompareManager compareManager = new CompareManager(this.sessionCompare, this.db);
            int            itemCount      = compareManager.RemoveFromCompare(productId);

            db.SaveChanges();

            var compareItems = compareManager.GetCompare();

            //ilosc elem aktualnie w koszyku

            // Return JSON to process it in JavaScript
            //struktura
            //ktora ma zostac zwrocona po wcisniecie remove
            //var result = new CompareRemoveViewModel
            //{
            //    RemoveItemId = productId,
            //    RemovedItemCount = itemCount,
            //};


            CompareViewModel compareVM = new CompareViewModel()
            {
                CompareItems = compareItems
            };

            return(Json(compareVM));
            //return Json(result, JsonRequestBehavior.AllowGet);
        }
        public SelectDocumentsWindow(IActiveDocument activeDocument)
        {
            InitializeComponent();
            this.PreviewKeyDown += HandleEscapeKey;
            DataContext = new CompareViewModel(activeDocument);

            ResetVersionsComboBoxText();
        }
Exemple #8
0
 private void Compare()
 {
     if (null == compareController)
     {
         compareController = container.Resolve <CompareController>();
         CompareViewModel vm = compareController.Initalise();
     }
     popupController.AddWindow(compareController.ViewModel.View, "Compare");
 }
Exemple #9
0
        public async Task <ActionResult> Compare(List <CsvFileViewModel> csvFiles)
        {
            var compareTransactionList = new CompareViewModel();

            var selectedCsvFiles = csvFiles.Where(c => c.IsChecked).ToList();

            if (selectedCsvFiles == null)
            {
                ViewBag.Error = _localizer["EmptySelectedCsvFileError"];
                return(View(compareTransactionList));
            }

            if (selectedCsvFiles.Count < 2 || selectedCsvFiles.Count > 4)
            {
                ViewBag.Error = _localizer["BadNumberOfCsv"];
                return(View(compareTransactionList));
            }
            var transactionsToCompare = new List <TransactionsViewModel>();

            foreach (var selectedFile in selectedCsvFiles)
            {
                var filePath = GetFullFilePath(selectedFile.FileName);
                try
                {
                    var transactions        = _transactionServices.GetTransactions(filePath);
                    var groupedTransactions = _transactionServices.GetGroupedTransactionsByCategory(transactions);
                    if (groupedTransactions == null || !groupedTransactions.Any())
                    {
                        ViewBag.Error = _localizer["EmptyTransactionList"];
                        return(View(compareTransactionList));
                    }

                    var transactionViewModels = GetTransactionViewModels(groupedTransactions);

                    transactionViewModels = await AppendMissingCategoryTransactions(transactionViewModels);

                    var transactionsViewModelOrdered = transactionViewModels.OrderBy(t => t.Category.Name.ToString()).AsEnumerable();

                    transactionsViewModelOrdered = UnsignAmount(transactionsViewModelOrdered);

                    var transactionsViewModel = GetTransactionsViewModel(transactionsViewModelOrdered);

                    transactionsToCompare.Add(transactionsViewModel);
                }
                catch (Exception ex)
                {
                    ViewBag.Error = ex.Message;
                    return(View(compareTransactionList));
                }
            }
            compareTransactionList.TransactionsToCompare = OrderedTransactionsByDate(transactionsToCompare);
            CompareToAdjustTransactionColor(compareTransactionList);

            return(View(compareTransactionList));
        }
Exemple #10
0
        public IActionResult Index()
        {
            var claimsIdentity           = (ClaimsIdentity)User.Identity;
            var claim                    = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
            CompareViewModel compareList = new CompareViewModel()
            {
                CompareList = _db.Compare.Include(m => m.MenuItem.Category).Where(c => c.ApplicationUserId == claim.Value).ToList(),
            };

            return(View(compareList));
        }
Exemple #11
0
 public void LoadCompareViewModel(CompareViewModel viewModel)
 {
     viewModel.Headline    = GetStringValue(_languageCurrent.COMPARE_HEADLINE, "COMPARE_HEADLINE");
     viewModel.Lede        = GetStringValue(_languageCurrent.COMPARE_COPY, "COMPARE_COPY");
     viewModel.Legal       = GetStringValue(_languageCurrent.COMPARE_LEGAL, "COMPARE_LEGAL");
     viewModel.ProTitle    = GetStringValue(_languageCurrent.COMPARE_DEVICE_ONE_TITLE, "COMPARE_DEVICE_ONE_TITLE");
     viewModel.BookTitle   = GetStringValue(_languageCurrent.COMPARE_DEVICE_TWO_TITLE, "COMPARE_DEVICE_TWO_TITLE");
     viewModel.StudioTitle = GetStringValue(_languageCurrent.COMPARE_DEVICE_THREE_TITLE, "COMPARE_DEVICE_THREE_TITLE");
     viewModel.LaptopTitle = GetStringValue(_languageCurrent.COMPARE_DEVICE_FOUR_TITLE, "COMPARE_DEVICE_FOUR_TITLE");
     viewModel.GoTitle     = GetStringValue(_languageCurrent.COMPARE_DEVICE_FIVE_TITLE, "COMPARE_DEVICE_FIVE_TITLE");
 }
Exemple #12
0
        public static bool GetShouldShowRow(DisplayMode mode, CompareViewModel viewModel)
        {
            bool result = false;

            switch (mode)
            {
            case DisplayMode.Same:
                result = (viewModel.ContentsComparison == 0 && viewModel.RelPathComparison == 0 && viewModel.LastWriteComparison == 0 && viewModel.SizeComparison == 0);
                break;

            case DisplayMode.LeftOnly:
                result = (viewModel.RightItem is null);
                break;

            case DisplayMode.RightOnly:
                result = (viewModel.LeftItem is null);
                break;

            case DisplayMode.Different:
                result = (viewModel.RightItem is null || viewModel.LeftItem is null || viewModel.ContentsComparison != 0 || viewModel.RelPathComparison != 0 || viewModel.LastWriteComparison != 0 || viewModel.SizeComparison != 0);
                break;

            case DisplayMode.Moved:
                result = (viewModel.ContentsComparison == 0 && viewModel.RelPathComparison != 0);
                break;

            case DisplayMode.Modified:
                result = (viewModel.RightItem != null && viewModel.LeftItem != null && viewModel.LastWriteComparison != 0);
                break;

            case DisplayMode.Size:
                result = (viewModel.RightItem != null && viewModel.LeftItem != null && viewModel.SizeComparison != 0);
                break;

            case DisplayMode.Corrupt:
                result = (viewModel.ContentsComparison != 0 && viewModel.RelPathComparison == 0 && viewModel.LastWriteComparison == 0 && viewModel.SizeComparison == 0);
                break;

            case DisplayMode.All:
                result = true;
                break;

            case DisplayMode.None:
            default:
                break;
            }

            return(result);
        }
        public ActionResult Compare()
        {
            //sesja i kontekst jako param.
            CompareManager compareManager = new CompareManager(this.sessionCompare, this.db);
            //zwraca liste cartItem ktora w tym momencie jest zapisana w sesji
            //pobieramy stan koszyka
            var compareItems = compareManager.GetCompare();

            //ustawiany na to co pobralismy
            CompareViewModel compareVM = new CompareViewModel()
            {
                CompareItems = compareItems
            };

            return(View(compareVM));
            // return Json(compareVM);
        }
Exemple #14
0
        //Newly Added..
        public ActionResult Search(int id)
        {
            PlaceService service = new PlaceService();
            ParkingPlace matches = new ParkingPlace();

            FacilityService fs = new FacilityService();

            string dsc = fs.getFacility(id);

            matches = service.getPlaceInfo(id);
            ReviewService    rs   = new ReviewService();
            CompareViewModel data = new CompareViewModel()
            {
                Name       = matches.SpotName,
                PlaceId    = matches.ID,
                Price      = matches.PricePerHour,
                Rating     = rs.getRating(id),
                Facilities = dsc
            };

            string name = "matches";
            int    _cnt = Convert.ToInt32(Session["cnt"]);

            int lim = Convert.ToInt32(Session["lim"]);

            if (lim >= 4)
            {
                return(RedirectToAction("compare", "users"));
            }

            _cnt++; Session["cnt"] = _cnt.ToString();

            lim++; Session["lim"] = lim.ToString();

            Session[name + _cnt.ToString()] = data;

            //List<ParkingPlace> model = new List<ParkingPlace>();
            //for(int i=1;i<=_cnt;i++)
            //{
            //    if ((Session[name + i.ToString()]).ToString() == "none") continue;
            //    ParkingPlace p = (ParkingPlace)Session[name + i.ToString()];
            //    model.Add(p);
            //}
            //return View("compare", model);
            return(RedirectToAction("compare", "users"));
        }
        public ActionResult Compare(int id, int competitorId)
        {
            CWFuneralHome cwYourHome  = db.CWFuneralHomes.Find(id);
            CWFuneralHome cwTheirHome = db.CWFuneralHomes.Find(competitorId);

            //DateTime old = DateTime.Now.AddYears(-10);
            //CWObituary toDelete = db.CWObituary.Where(d => d.DeathDate < old).FirstOrDefault();
            //db.Entry(toDelete).State = System.Data.Entity.EntityState.Deleted;
            //db.SaveChanges();
            CompareViewModel cvm = new CompareViewModel();

            if (cwYourHome != null && cwTheirHome != null)
            {
                cvm.AvgAge           = cwYourHome.CWObituary.Where(o => o.Age != 0).Average(o => o.Age);
                cvm.CompetitorAvgAge = cwTheirHome.CWObituary.Where(o => o.Age != 0).Average(o => o.Age);
                CompetitorWatchHelper.GenerateCompetiveLineChart(cwYourHome, cwTheirHome, ref cvm);
            }
            return(View(cvm));
        }
Exemple #16
0
        List <CompareViewModel> GetCompareViewModelByHourValueList(List <HourValue> todayList, List <HourValue> yesterdayList)
        {
            List <CompareViewModel> compareViewModels = new List <CompareViewModel>();

            foreach (var item in todayList)
            {
                CompareViewModel compareViewModel = compareViewModels.Find(delegate(CompareViewModel compare) { return(compare.EnergyItemCode == item.EnergyItemCode); });
                HourValue        yesterdayValue   = yesterdayList.Find(delegate(HourValue hour) { return(hour.EnergyItemCode == item.EnergyItemCode && hour.ValueTime.Hour == item.ValueTime.Hour); });
                if (compareViewModel == null)
                {
                    compareViewModels.Add(new CompareViewModel(item.EnergyItemCode, context.GetEnergyItemByCode(item.EnergyItemCode).EnergyItemName,
                                                               item.Value, yesterdayValue == null ? 0 : yesterdayValue.Value));
                }
                else
                {
                    compareViewModel.TodayValue     += item.Value;
                    compareViewModel.YesterdayValue += (yesterdayValue == null ? 0 : yesterdayValue.Value);
                }
            }

            return(compareViewModels);
        }
        public async Task <IActionResult> Details(int?id)
        {
            CompareViewModel compareviewmodel = new CompareViewModel();


            if (id == null)
            {
                return(NotFound());
            }
            if (User.IsInRole("Admin"))
            {
                var player = await _context.Player
                             .SingleOrDefaultAsync(m => m.PlayerId == id);

                if (player == null)
                {
                    return(NotFound());
                }

                return(View(player));
            }
            else
            {
                var use     = _userManager.GetUserId(User);
                var details = "SELECT * FROM [Team] AS [p] JOIN [Player] AS [q] ON [p].[Players_ID] = [q].[Player_ID] WHERE [p].[User_ID] = '" + use + "' AND[q].[Player_ID] = " + id;

                var qu = await _context.Player
                         .FromSql(details)
                         .AsNoTracking()
                         .SingleOrDefaultAsync();

                if (qu == null)
                {
                    return(NotFound());
                }

                return(View(qu));
            }
        }
Exemple #18
0
        public IActionResult Compare(CompareViewModel model)
        {
            var values = scoreProductSuitability.Score(repository.Products, new LoanConstraints()
            {
                Amount = model.LoanAmount,
                RepaymentPeriodInDays = model.PaybackDuration
            });

            var viewModel = values.Join(repository.Vendors, c => c.Product.VendorId, v => v.Id, (c, d) =>
                                        new CompareResultViewModel
            {
                VendorId                 = d.Id,
                VendorName               = d.Name,
                ProductId                = c.Product.Id,
                ProductShortDesc         = c.Product.ShortDesc,
                LoanAmount               = model.LoanAmount,
                RepayableAmount          = c.Product.GetRepayableAmount(model.LoanAmount),
                Score                    = c.Score,
                MaxRepaymentPeriodInDays = c.Product.RepaymentPeriodInDays
            });

            return(PartialView("PartialCompare", viewModel));
        }
Exemple #19
0
        public ActionResult Compare()
        {
            if (Session["type"].ToString() == "1")
            {
                string name = "matches";
                int    _cnt = Convert.ToInt32(Session["cnt"]);

                List <CompareViewModel> model = new List <CompareViewModel>();
                for (int i = 1; i <= _cnt; i++)
                {
                    if ((Session[name + i.ToString()]).ToString() == "none")
                    {
                        continue;
                    }
                    CompareViewModel p = (CompareViewModel)Session[name + i.ToString()];
                    model.Add(p);
                }
                return(View("compare", model));
            }
            else
            {
                return(RedirectToAction("index", "Login"));
            }
        }
Exemple #20
0
 public CompareController(IContainer c)
 {
     viewModel = c.Resolve <CompareViewModel>();
     model     = c.Resolve <Model>();
 }
        public async Task <IActionResult> Compare(string userName1, string userName2)
        {
            if (string.IsNullOrEmpty(userName1) ||
                string.IsNullOrEmpty(userName2))
            {
                this.ViewBag.ErrorMessage = "Two users are required to compare.";
                return(this.View("Error"));
            }

            var user1 = await this.userManager.FindByNameAsync(userName1);

            if (user1 == null)
            {
                this.ViewBag.ErrorMessage = $"User does not exist: {userName1}.";
                return(this.View("Error"));
            }

            var user2 = await this.userManager.FindByNameAsync(userName2);

            if (user2 == null)
            {
                this.ViewBag.ErrorMessage = $"User does not exist: {userName2}.";
                return(this.View("Error"));
            }

            var userId      = this.userManager.GetUserId(this.User);
            var userIsAdmin = this.User.IsInRole("Admin");

            var userId1 = await this.userManager.GetUserIdAsync(user1);

            var userId2 = await this.userManager.GetUserIdAsync(user2);

            // Normalize the user names
            userName1 = await this.userManager.GetUserNameAsync(user1);

            userName2 = await this.userManager.GetUserNameAsync(user2);

            if (!userIsAdmin)
            {
                var userSettings1 = this.userSettingsProvider.Get(userId1);
                if (!userId1.Equals(userId, StringComparison.OrdinalIgnoreCase) && !userSettings1.AreUploadsPublic)
                {
                    this.ViewBag.ErrorMessage = $"{userName1}'s data is private and may not be viewed";
                    return(this.View("Error"));
                }

                var userSettings2 = this.userSettingsProvider.Get(userId2);
                if (!userId2.Equals(userId, StringComparison.OrdinalIgnoreCase) && !userSettings2.AreUploadsPublic)
                {
                    this.ViewBag.ErrorMessage = $"{userName2}'s data is private and may not be viewed";
                    return(this.View("Error"));
                }
            }

            var range = this.Request.Query["range"];
            var model = new CompareViewModel(
                this.gameData,
                this.telemetryClient,
                this.databaseCommandFactory,
                this.userSettingsProvider.Get(userId),
                userId1,
                userName1,
                userId2,
                userName2,
                range);

            if (!model.IsValid)
            {
                this.ViewBag.ErrorMessage = "There was a problem comparing your data to that user. Make sure both you and them have upload data to compare.";
                return(this.View("Error"));
            }

            return(this.View(model));
        }
        public async Task<ActionResult> Comparison(int? totalComparelistItems, string ComparelistItems)
        {
            ViewBag.Message = "Property Comparison";

            string selectedPIDItems = null;

            if (ComparelistItems == null || ComparelistItems == "")
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                return RedirectToAction("Index", "FrontEnd");

            string last = ComparelistItems.Split(new[] { ',' }).Last();
            foreach (var item in ComparelistItems.Split(new[] { ',' }))
            {
                if (item.Equals(last))
                {
                    selectedPIDItems += "ID = " + item;
                }
                else
                {
                    selectedPIDItems += "ID = " + item + " OR ";
                }
            }

            CompareViewModel viewModel = new CompareViewModel();

            IEnumerable<Property> allProperties = null;

            if (!String.IsNullOrEmpty(selectedPIDItems))
            {
                allProperties = await db.Properties.SqlQuery("SELECT * FROM Property WHERE " + selectedPIDItems).ToListAsync();
                List<ComparePropertyReviewsViewModel> allPropertyPhotoReview = new List<ComparePropertyReviewsViewModel>();
                foreach (var property in allProperties)
                {
                    ComparePropertyReviewsViewModel model = new ComparePropertyReviewsViewModel();
                    model.Property = property;
                    model.Photo = await db.Photos.Where(ph => ph.PropertyId == property.Id).OrderBy(ph => ph.Id).Take(1).SingleOrDefaultAsync();
                    //model.Products = db.Photos.Where(ph => ph.PropertyID == property.ID).ToList();

                    var subType = await db.OfSubTypes.Where(s => s.ID == model.Property.OfSubType).FirstOrDefaultAsync();
                    model.SubType = subType.Title;

                    DetailsAgentProfile ReviewsCount = await db.Reviews.Where(r => r.PropertyID == model.Property.Id)
                         .GroupBy(r => r.Property.AgentId)
                         .Select(r => new DetailsAgentProfile
                         {
                             Count = r.Count()
                         }).FirstOrDefaultAsync();
                    model.ReviewsCount = (ReviewsCount != null) ?  ReviewsCount.Count : 0;

                    // Find all Reviews with number of items count
                    var allReviewsC = await db.Reviews.Where(r => r.PropertyID == model.Property.Id)
                         .GroupBy(r => r.ID)
                         .Select(p => new DetailsPropertyRatingViewModel
                         {
                             SumRatings = p.Sum(r => r.Rating),
                             Total = p.Count()
                         }).FirstOrDefaultAsync();
                    int results = (allReviewsC != null) ? (allReviewsC.SumRatings / allReviewsC.Total) : 0;
                    model.PropertyRating = results;

                    allPropertyPhotoReview.Add(model);
                }
                viewModel.PropertyPhotoReview = allPropertyPhotoReview.ToList();

            }

            return View(viewModel);
        }
Exemple #23
0
 public CompareController(IContainer c)
 {
     viewModel = c.Resolve<CompareViewModel>();
     model = c.Resolve<Model>();
 }
Exemple #24
0
        public async Task OnGetAsync()
        {
            var userName = this.User.Identity.Name;

            CompareViewModel = await _comparePageService.GetCompare(userName);
        }
        public ComparePage()
        {
            InitializeComponent();

            BindingContext = _viewModel = new CompareViewModel();
        }
Exemple #26
0
 public ComparePage(CompareViewModel viewModel)
 {
     InitializeComponent();
     BindingContext = ViewModel = viewModel;
 }
Exemple #27
0
 public ComparePage()
 {
     InitializeComponent();
     BindingContext         = ViewModel = new CompareViewModel();
     CompareTitleLabel.Text = CompareTitleLabelText;
 }
        public static void GenerateCompetiveLineChart(CWFuneralHome ourHome, CWFuneralHome TheirHome, ref CompareViewModel cvm)
        {
            DateTime?SmallestMonth            = ourHome.CWObituary.Min(o => o.DeathDate);
            DateTime?competetiorSmallestMonth = TheirHome.CWObituary.Min(o => o.DeathDate);

            if (SmallestMonth != null && competetiorSmallestMonth != null)
            {
                DateTime earliestMonth = new DateTime();
                if (SmallestMonth < competetiorSmallestMonth)
                {
                    earliestMonth = (DateTime)SmallestMonth;
                }
                else
                {
                    earliestMonth = (DateTime)competetiorSmallestMonth;
                }
                int             monthsAgo            = ((DateTime.Now.Year - earliestMonth.Year) * 12) + DateTime.Now.Month - earliestMonth.Month;
                List <DateTime> monthTimeRange       = new List <DateTime>();
                List <int>      montServices         = new List <int>();
                StringBuilder   monthTimeRangeString = new StringBuilder();
                monthTimeRangeString.Append("[");
                DateTime   workingMonth          = earliestMonth;
                List <int> OurServicesPerMonth   = new List <int>();
                List <int> TheirServicesPerMonth = new List <int>();
                for (int i = 0; i < monthsAgo; i++)
                {
                    int ourServiceCount   = ourHome.CWObituary.Where(o => o.DeathDate != null && o.DeathDate.Value.Month == workingMonth.Month && o.DeathDate.Value.Year == workingMonth.Year).Count();
                    int theirServiceCount = TheirHome.CWObituary.Where(o => o.DeathDate != null && o.DeathDate.Value.Month == workingMonth.Month && o.DeathDate.Value.Year == workingMonth.Year).Count();
                    monthTimeRange.Add(workingMonth);
                    workingMonth = workingMonth.AddMonths(1);
                    OurServicesPerMonth.Add(ourServiceCount);
                    TheirServicesPerMonth.Add(theirServiceCount);
                }
                string seriesData = "[";
                seriesData = seriesData + WijmoSeriesBuilder.StringfyDateTimeLineChartSeries(ourHome.Name, true, monthTimeRange, OurServicesPerMonth, true, "circle");
                seriesData = seriesData + ", " + WijmoSeriesBuilder.StringfyDateTimeLineChartSeries(TheirHome.Name, true, monthTimeRange, TheirServicesPerMonth, true, "circle");
                seriesData = seriesData + "]";
                //Calculate averages for our Home
                int     sum    = OurServicesPerMonth.Sum();
                decimal result = (decimal)sum / OurServicesPerMonth.Count();
                cvm.AvgMonthlyCalls = result;
                //Calculate averages for their home
                int     sum1    = TheirServicesPerMonth.Sum();
                decimal result1 = (decimal)sum1 / TheirServicesPerMonth.Count();
                cvm.CompetitorMonthlyCalls    = result1;
                cvm.CompetiveLineChartMonthly = seriesData;
            }
        }
        public async Task <IActionResult> Compare(int?id, int?id2, string user2, int?id3, string user3, int?id4, string user4)
        {
            var viewModel = new CompareViewModel();

            viewModel.AspNetUsers = await _context.AspNetUsers
                                    .ToListAsync();

            if (user2 != null)
            {
                var details = "SELECT * FROM [Team] AS [p] JOIN [Player] AS [q] ON [p].[Players_ID] = [q].[Player_ID] WHERE [p].[User_ID] = '" + user2 + "'";

                var qu = await _context.Player
                         .FromSql(details)
                         .AsNoTracking()
                         .ToListAsync();

                viewModel.Player2 = qu;
            }

            if (user3 != null)
            {
                var details = "SELECT * FROM [Team] AS [p] JOIN [Player] AS [q] ON [p].[Players_ID] = [q].[Player_ID] WHERE [p].[User_ID] = '" + user3 + "'";

                var qu = await _context.Player
                         .FromSql(details)
                         .AsNoTracking()
                         .ToListAsync();

                viewModel.Player3 = qu;
            }

            if (user4 != null)
            {
                var details = "SELECT * FROM [Team] AS [p] JOIN [Player] AS [q] ON [p].[Players_ID] = [q].[Player_ID] WHERE [p].[User_ID] = '" + user4 + "'";

                var qu = await _context.Player
                         .FromSql(details)
                         .AsNoTracking()
                         .ToListAsync();

                viewModel.Player4 = qu;
            }


            if (id != null)
            {
                if (User.IsInRole("Admin"))
                {
                    var use     = _userManager.GetUserId(User);
                    var details = "SELECT * FROM [Team] AS [p] JOIN [Player] AS [q] ON [p].[Players_ID] = [q].[Player_ID] WHERE [q].[Player_ID] = " + id;

                    var qu = await _context.Player
                             .FromSql(details)
                             .AsNoTracking()
                             .ToListAsync();

                    viewModel.Player = qu;
                }
                else
                {
                    {
                        var use     = _userManager.GetUserId(User);
                        var details = "SELECT * FROM [Team] AS [p] JOIN [Player] AS [q] ON [p].[Players_ID] = [q].[Player_ID] WHERE [p].[User_ID] = '" + use + "' AND[q].[Player_ID] = " + id;

                        var qu = await _context.Player
                                 .FromSql(details)
                                 .AsNoTracking()
                                 .ToListAsync();

                        viewModel.Player = qu;
                    }
                }
            }
            if (id2 != null)
            {
                var details = "SELECT * FROM [Team] AS [p] JOIN [Player] AS [q] ON [p].[Players_ID] = [q].[Player_ID] WHERE [q].[Player_ID] = " + id2;

                var qu = await _context.Player
                         .FromSql(details)
                         .AsNoTracking()
                         .ToListAsync();

                viewModel.Player2display = qu;
            }

            if (id3 != null)
            {
                var details = "SELECT * FROM [Team] AS [p] JOIN [Player] AS [q] ON [p].[Players_ID] = [q].[Player_ID] WHERE [q].[Player_ID] = " + id3;

                var qu = await _context.Player
                         .FromSql(details)
                         .AsNoTracking()
                         .ToListAsync();

                viewModel.Player3display = qu;
            }

            if (id4 != null)
            {
                var details = "SELECT * FROM [Team] AS [p] JOIN [Player] AS [q] ON [p].[Players_ID] = [q].[Player_ID] WHERE [q].[Player_ID] = " + id4;

                var qu = await _context.Player
                         .FromSql(details)
                         .AsNoTracking()
                         .ToListAsync();

                viewModel.Player4display = qu;
            }

            return(View(viewModel));
        }
        public ActionResult Index()
        {
            var items = (from i in _context.Items
                         //join sg in _context.CompareGroups on i.CompareGroupId equals sg.Id
                         //where sg.LinkName == "processeur"
                         join ib in _context.ItemCompares on i.Id equals ib.ItemId
                         where ib.SessionId == Session.SessionID
                         select i).ToArray();

            CompareViewModel CompareViewModel = new CompareViewModel();

            if (items.Count() > 0)
            {
                var compareGroupId = items.First().CompareGroupId;
                var compareGroup   = _context.CompareGroups.Single(c => c.Id == compareGroupId);
                var specifications = (from s in _context.Specifications
                                      join cs in _context.CompareGroupSpecifications on s.Id equals cs.SpecificationId
                                      where cs.CompareGroupId == compareGroup.Id
                                      select s).ToArray();

                var groupIds            = specifications.Select(s => s.SpecificationGroupId).Distinct().ToArray();
                var specificationGroups = (from g in _context.SpecificationGroups
                                           where groupIds.Contains(g.Id)
                                           select g).ToArray();

                var itemIds = items.Select(i => i.Id).ToArray();

                var itemSpecifications = (from ispec in _context.ItemSpecifications
                                          where itemIds.Contains(ispec.ItemId)
                                          select ispec).ToArray();


                var columns = new List <ColumCompareViewModel>();
                foreach (var item in items)
                {
                    var column = new ColumCompareViewModel();
                    column.Item = item;
                    columns.Add(column);
                }
                CompareViewModel.Columns = columns;

                var lines = new List <LineCompareViewModel>();
                foreach (var specificationGroup in specificationGroups)
                {
                    var groupLine = new LineCompareViewModel();
                    groupLine.Type         = LineCompareViewModelType.Group;
                    groupLine.CompareGroup = specificationGroup;
                    var groupCells = new List <CellCompareViewModel>();
                    foreach (var item in items)
                    {
                        var groupCell = new CellCompareViewModel();
                        groupCell.Value = "";
                        groupCells.Add(groupCell);
                    }
                    groupLine.Cells = groupCells;
                    lines.Add(groupLine);

                    foreach (var specification in specifications.Where(s => s.SpecificationGroupId == specificationGroup.Id))
                    {
                        var line = new LineCompareViewModel();
                        line.Type          = LineCompareViewModelType.Specification;
                        line.Specification = specification;
                        var cells = new List <CellCompareViewModel>();
                        foreach (var item in items)
                        {
                            var cell = new CellCompareViewModel();
                            var itemSpecification = itemSpecifications.SingleOrDefault(ispec => ispec.ItemId == item.Id && ispec.SpecificationId == specification.Id);
                            cell.Value = GetCellValue(specification, itemSpecification);
                            cells.Add(cell);
                        }
                        line.Cells = cells;
                        lines.Add(line);
                    }
                }
                CompareViewModel.Lines = lines;
            }
            else
            {
            }

            return(View("Index", CompareViewModel));
        }