private Color GetColorPoint(double value) { decimal pct = (decimal)(value * 100 / options); Test test = new TestsServices().GetById(test_id); if (test.ClimateScale_Id.HasValue) { ClimateRange range = test.ClimateScale.ClimateRanges.Where(r => r.MinValue <= pct && r.MaxValue >= pct).OrderBy(r => r.MaxValue).FirstOrDefault(); return(System.Drawing.ColorTranslator.FromHtml(range.Color)); } else { if (pct > 80) { return(Color.Green); } else if (pct > 60 && pct <= 80) { return(Color.Yellow); } else { return(Color.Red); } } }
public string GetColourByClimate(double pctClimate) { if (Test.ClimateScale_Id.HasValue) { ClimateRange range = Test.ClimateScale.ClimateRanges.Where(r => r.MinValue <= (decimal)pctClimate && r.MaxValue >= (decimal)pctClimate).OrderBy(r => r.MaxValue).FirstOrDefault(); //return System.Drawing.ColorTranslator.FromHtml(range.Color); return(range.Color); } else { if (pctClimate <= 60) { return(DictionaryColours["Red"]); } else if (pctClimate > 60 && pctClimate <= 80) { return(DictionaryColours["Amber"]); } else if (pctClimate > 80) { return(DictionaryColours["Green"]); } else { return(""); } } }
public string GetColourByClimate(double avg) { //double pct = ((double)(avg * 100)) / Test.GetOptionsByTest().Count();//.Questionnaire.Options.Count; double pct = Test.ResultBasedOn100 ? avg : ((double)(avg * 100)) / optionsByTest; if (Test.ClimateScale_Id.HasValue) { ClimateRange range = Test.ClimateScale.ClimateRanges.Where(r => r.MinValue <= (decimal)pct && r.MaxValue >= (decimal)pct).OrderBy(r => r.MaxValue).FirstOrDefault(); return(range.Color); } else { if (pct <= 60) { return("#FF004C"); } else if (pct > 60 && pct <= 80) { return("#FECE00"); } else if (pct > 80) { return("#00B386"); } else { return(""); } } }
private void InitializeViews(int?climateRange_id, int?climateScale_id) { ClimateRange ClimateRange; SelectList climateScalesList; User user = new UsersServices().GetByUserName(User.Identity.Name.ToString()); if (climateRange_id != null) { ClimateRange = _climateRangeService.GetById(climateRange_id.Value); ClimateRange.ClimateScale = new ClimateScalesServices().GetById(ClimateRange.ClimateScale_Id); climateScalesList = new SelectList(new ClimateScalesServices().GetClimateScalesForDropDownListByCompany(user.Company_Id), "Key", "Value", ClimateRange.ClimateScale_Id); } else { ClimateRange = new ClimateRange(); if (climateScale_id != null) { ClimateRange.ClimateScale_Id = (int)climateScale_id; climateScalesList = new SelectList(new ClimateScalesServices().GetClimateScalesForDropDownListByCompany(user.Company_Id), "Key", "Value", ClimateRange.ClimateScale_Id); } else { climateScalesList = new SelectList(new ClimateScalesServices().GetClimateScalesForDropDownListByCompany(user.Company_Id), "Key", "Value"); } } _climateRangeViewModel = new ClimateRangeViewModel(ClimateRange, climateScalesList); }
public ActionResult Create(ClimateRange climateRange) { ValidateClimateRangeModel(climateRange); if (ModelState.IsValid) { if (_climateRangeService.Add(climateRange)) { return(RedirectToAction("Index", new { @climateScale_id = climateRange.ClimateScale_Id })); } } InitializeViews(null, null); return(View(_climateRangeViewModel)); }
private void ValidateClimateRangeModel(ClimateRange climateRange) { if (_climateRangeService.IsValueDuplicated(climateRange.ClimateScale_Id, climateRange.MinValue)) { ModelState.AddModelError(ViewRes.Controllers.ClimateRanges.MinValue, ViewRes.Controllers.ClimateRanges.MinValueText); } if (_climateRangeService.IsValueDuplicated(climateRange.ClimateScale_Id, climateRange.MaxValue)) { ModelState.AddModelError(ViewRes.Controllers.ClimateRanges.MaxValue, ViewRes.Controllers.ClimateRanges.MaxValueText); } if (_climateRangeService.IsNameDuplicated(climateRange.ClimateScale_Id, climateRange.Name)) { ModelState.AddModelError(ViewRes.Controllers.Shared.Name, ViewRes.Controllers.Shared.NameText); } if (_climateRangeService.IsColorDuplicated(climateRange.ClimateScale_Id, climateRange.Color)) { ModelState.AddModelError(ViewRes.Controllers.ClimateRanges.Color, ViewRes.Controllers.ClimateRanges.ColorText); } }
public ActionResult Edit(int id, FormCollection collection) { if (GetAuthorization(_climateRangeService.GetById(id))) { try { ClimateRange ClimateRange = _climateRangeService.GetById(id); UpdateModel(ClimateRange, "ClimateRange"); _climateRangeService.SaveChanges(); return(RedirectToAction("Index", new { @climateScale_id = ClimateRange.ClimateScale_Id })); } catch { InitializeViews(id, null); return(View(_climateRangeViewModel)); } } else { return(RedirectToLogOn()); } }
public ClimateRangeViewModel(ClimateRange ClimateRange, SelectList ClimateScalesList) { this.ClimateRange = ClimateRange; this.ClimateScalesList = ClimateScalesList; }
private bool GetAuthorization(ClimateRange climateRange) { return(new SharedAdminAuthorization(new UsersServices().GetByUserName(User.Identity.Name), new CompaniesServices().GetById(climateRange.ClimateScale.Company_Id)).isAuthorizated()); }