Example #1
0
        private void BuildOtherTrustsLines(TrustComparisonListModel comparisonList, List <ChartViewModel> benchmarkCharts, StringBuilder csv)
        {
            var otherTrusts = comparisonList.Trusts.Where(b => b.CompanyNo != comparisonList.DefaultTrustCompanyNo);

            foreach (var trust in otherTrusts)
            {
                var valuesLine = new StringBuilder();
                var data       = benchmarkCharts.First().BenchmarkData.Find(d => d.Urn == trust.CompanyNo.ToString());
                var term       = benchmarkCharts.First().BenchmarkData.Find(d => d.Urn == trust.CompanyNo.ToString()).Term;
                valuesLine.Append($"\"{trust.Name}\",{data.Urn},{term},{data.PupilCount},{data.TeacherCount},");

                foreach (var chart in benchmarkCharts.Where(bc => bc.Downloadable))
                {
                    var amount = chart.BenchmarkData.Find(d => d.Urn == trust.CompanyNo.ToString()).Amount;
                    valuesLine.Append(amount == null ? "N/A" : amount.ToString());
                    valuesLine.Append(",");
                    if (chart.TableColumns != null)
                    {
                        foreach (var col in chart.TableColumns)
                        {
                            var colAmount = col.BenchmarkData.Find(d => d.Urn == trust.CompanyNo.ToString()).Amount;
                            valuesLine.Append(colAmount == null ? "N/A" : colAmount.ToString());
                            valuesLine.Append(",");
                        }
                    }
                }

                csv.AppendLine(valuesLine.ToString().TrimEnd(','));
            }
        }
Example #2
0
        public string BuildCSVContentForTrusts(TrustComparisonListModel comparisonList, List <ChartViewModel> benchmarkCharts)
        {
            var csv = new StringBuilder();

            BuildHeaderLine(benchmarkCharts, csv, EstablishmentType.MAT);

            BuildDefaultTrustLine(comparisonList, benchmarkCharts, csv);

            BuildOtherTrustsLines(comparisonList, benchmarkCharts, csv);

            return(csv.ToString());
        }
Example #3
0
        public TrustComparisonListModel ExtractTrustComparisonListFromCookie()
        {
            var comparisonList = new TrustComparisonListModel();;
            var cookie         = HttpContext.Current.Request.Cookies[CookieNames.COMPARISON_LIST_MAT];

            if (cookie != null)
            {
                comparisonList = JsonConvert.DeserializeObject <TrustComparisonListModel>(cookie.Value, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
            }
            return(comparisonList);
        }
Example #4
0
        public TrustComparisonListModel UpdateTrustComparisonListCookie(CookieActions withAction, int?companyNo = null, string matName = null)
        {
            TrustComparisonListModel comparisonList = null;
            HttpCookie cookie = HttpContext.Current.Request.Cookies[CookieNames.COMPARISON_LIST_MAT];

            switch (withAction)
            {
            case CookieActions.SetDefault:
                if (cookie is null)
                {
                    cookie         = new HttpCookie(CookieNames.COMPARISON_LIST_MAT);
                    comparisonList = new TrustComparisonListModel(companyNo.GetValueOrDefault(), matName)
                    {
                        Trusts = new List <BenchmarkTrustModel> {
                            new BenchmarkTrustModel(companyNo.GetValueOrDefault(), matName)
                        }
                    };
                }
                else
                {
                    comparisonList = JsonConvert.DeserializeObject <TrustComparisonListModel>(cookie.Value, new JsonSerializerSettings()
                    {
                        StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                    });
                    comparisonList.DefaultTrustCompanyNo = companyNo.GetValueOrDefault();
                    comparisonList.DefaultTrustName      = matName;
                    if (comparisonList.Trusts.All(s => s.CompanyNo != companyNo))
                    {
                        comparisonList.Trusts.Add(new BenchmarkTrustModel(companyNo.GetValueOrDefault(), matName));
                    }
                }
                break;

            case CookieActions.Add:
                if (cookie == null)
                {
                    cookie         = new HttpCookie(CookieNames.COMPARISON_LIST_MAT);
                    comparisonList = new TrustComparisonListModel(companyNo.GetValueOrDefault(), matName)
                    {
                        Trusts = new List <BenchmarkTrustModel> {
                            new BenchmarkTrustModel(companyNo.GetValueOrDefault(), matName)
                        }
                    };
                }
                else
                {
                    comparisonList = JsonConvert.DeserializeObject <TrustComparisonListModel>(cookie.Value, new JsonSerializerSettings()
                    {
                        StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                    });
                    if (comparisonList.Trusts.Any(s => s.CompanyNo == companyNo))
                    {
                        throw new ApplicationException(ErrorMessages.DuplicateTrust);
                    }
                    else
                    {
                        comparisonList.Trusts.Add(new BenchmarkTrustModel(companyNo.GetValueOrDefault(), matName));
                    }
                }
                break;

            case CookieActions.Remove:
                comparisonList = JsonConvert.DeserializeObject <TrustComparisonListModel>(cookie.Value, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
                comparisonList.Trusts.Remove(new BenchmarkTrustModel(companyNo.GetValueOrDefault()));
                break;

            case CookieActions.RemoveAll:
                if (cookie != null)
                {
                    comparisonList = JsonConvert.DeserializeObject <TrustComparisonListModel>(cookie.Value, new JsonSerializerSettings()
                    {
                        StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                    });
                    comparisonList.Trusts.Clear();
                }
                break;

            case CookieActions.AddDefaultToList:
                comparisonList = JsonConvert.DeserializeObject <TrustComparisonListModel>(cookie.Value, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
                if (comparisonList.Trusts.All(s => comparisonList.DefaultTrustCompanyNo != companyNo))
                {
                    comparisonList.Trusts.Add(new BenchmarkTrustModel(comparisonList.DefaultTrustCompanyNo, comparisonList.DefaultTrustName));
                }
                break;
            }

            if (cookie != null)
            {
                cookie.Value = JsonConvert.SerializeObject(comparisonList, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
                cookie.Expires  = DateTime.MaxValue;
                cookie.HttpOnly = false;
                cookie.Secure   = HttpContext.Current.Request.IsSecureConnection;
                HttpContext.Current.Response.Cookies.Add(cookie);
                return(comparisonList);
            }

            return(null);
        }
 public TrustSelectionViewModel(TrustViewModel trust, TrustComparisonListModel trustComparisonList)
 {
     this.TrustComparisonList = trustComparisonList;
     this.BenchmarkTrust      = trust;
 }