public ActionResult GetDashboardValues(long placeId, long industryId, Data.UserData.BusinessAttribute attributes) { dynamic obj = new System.Dynamic.ExpandoObject(); string key = string.Format("dv-{0}-{1}", placeId, industryId); //var cookie = Request.Cookies[key] != null ? Request.Cookies[key] : SizeUp.Core.Web.CookieFactory.Create(key); Data.Analytics.BusinessAttribute attr = new Data.Analytics.BusinessAttribute(); if (User.Identity.IsAuthenticated) { using (var context = ContextFactory.AnalyticsContext) { var user = Membership.GetUser(User.Identity.Name); Guid userid = (Guid)user.ProviderUserKey; attr = context.BusinessAttributes.Where(i => i.UserId == userid && i.PlaceId == placeId && i.IndustryId == industryId).OrderByDescending(i => i.Id).FirstOrDefault(); if (attr == null) { attr = new Data.Analytics.BusinessAttribute(); } } } if (!string.IsNullOrEmpty(attr.BusinessSize)) { obj.businessSize = attr.BusinessSize; } if (!string.IsNullOrEmpty(attr.BusinessType)) { obj.businessType = attr.BusinessType; } if (attr.Employees.HasValue) { obj.employees = attr.Employees; } if (attr.HealthcareCost.HasValue) { obj.healthcareCost = attr.HealthcareCost; } if (attr.Revenue.HasValue) { obj.revenue = attr.Revenue; } if (attr.AverageSalary.HasValue) { obj.salary = attr.AverageSalary; } if (attr.WorkersComp.HasValue) { obj.workersComp = attr.WorkersComp; } if (attr.YearStarted.HasValue) { obj.yearStarted = attr.YearStarted; } //if (cookie.Values.AllKeys.Contains("businessSize") && User.Identity.IsAuthenticated) //{ // obj.businessSize = cookie.Values["businessSize"]; //} //if (cookie.Values.AllKeys.Contains("businessType")) //{ // obj.businessType = cookie.Values["businessType"]; //} //if (cookie.Values.AllKeys.Contains("employees") && User.Identity.IsAuthenticated) //{ // obj.employees = cookie.Values["employees"]; //} //if (cookie.Values.AllKeys.Contains("healthcareCost") && User.Identity.IsAuthenticated) //{ // obj.healthcareCost = cookie.Values["healthcareCost"]; //} //if (cookie.Values.AllKeys.Contains("revenue")) //{ // obj.revenue = cookie.Values["revenue"]; //} //if (cookie.Values.AllKeys.Contains("salary")) //{ // obj.salary = cookie.Values["salary"]; //} //if (cookie.Values.AllKeys.Contains("workersComp") && User.Identity.IsAuthenticated) //{ // obj.workersComp = cookie.Values["workersComp"]; //} //if (cookie.Values.AllKeys.Contains("yearStarted")) //{ // obj.yearStarted = cookie.Values["yearStarted"]; //} object output = ((ExpandoObject)obj).ToDictionary(item => item.Key, item => item.Value); return(Json(output, JsonRequestBehavior.AllowGet)); }
public ActionResult SetDashboardValues(long placeId, long industryId, long stateId) { string key = string.Format("dv-{0}-{1}", placeId, industryId); //HttpCookie cookie = SizeUp.Core.Web.CookieFactory.Create(key); Data.UserData.BusinessAttribute attr = new Data.UserData.BusinessAttribute(); Data.Analytics.BusinessAttribute analyticsAttr = new Data.Analytics.BusinessAttribute(); attr.PlaceId = placeId; attr.IndustryId = industryId; analyticsAttr.PlaceId = placeId; analyticsAttr.IndustryId = industryId; using (var context = ContextFactory.SizeUpContext) { var geo = stateId; // defaults to california if (Request.Form.AllKeys.Contains("businessSize")) { //cookie.Values.Add("businessSize", Request["businessSize"]); attr.BusinessSize = Request["businessSize"]; } if (Request.Form.AllKeys.Contains("businessType")) { //cookie.Values.Add("businessType", Request["businessType"]); attr.BusinessType = Request["businessType"]; } if (Request.Form.AllKeys.Contains("employees")) { //cookie.Values.Add("employees", Request["employees"]); //attr.Employees = int.Parse(Request["employees"] ?? ""); long outVar; if (long.TryParse(Request["employees"], out outVar)) { attr.Employees = outVar; var percentileItem = Core.DataLayer.AverageEmployees.Percentile(context, industryId, geo, attr.Employees ?? 0); if (percentileItem != null) { analyticsAttr.EmployeesPercentile = percentileItem.Percentile; } } } if (Request.Form.AllKeys.Contains("healthcareCost")) { //cookie.Values.Add("healthcareCost", Request["healthcareCost"]); attr.HealthcareCost = int.Parse(Request["healthcareCost"] ?? ""); var percentileItem = Core.DataLayer.Healthcare.Percentage(context, industryId, geo, attr.HealthcareCost ?? 0); if (percentileItem != null) { analyticsAttr.HealthCareCostPercentage = percentileItem.Percentage; } } if (Request.Form.AllKeys.Contains("revenue")) { //cookie.Values.Add("revenue", Request["revenue"]); attr.Revenue = int.Parse(Request["revenue"] ?? ""); var percentileItem = Core.DataLayer.AverageRevenue.Percentile(context, industryId, geo, attr.Revenue ?? 0); if (percentileItem != null) { analyticsAttr.RevenuePercentile = percentileItem.Percentile; } } if (Request.Form.AllKeys.Contains("salary")) { //cookie.Values.Add("salary", Request["salary"]); attr.AverageSalary = int.Parse(Request["salary"] ?? ""); var percentileItem = Core.DataLayer.AverageSalary.Percentage(context, industryId, geo, attr.AverageSalary ?? 0); if (percentileItem != null) { analyticsAttr.AverageSalaryPercentage = percentileItem.Percentage; } } if (Request.Form.AllKeys.Contains("workersComp")) { //cookie.Values.Add("workersComp", Request["workersComp"]); attr.WorkersComp = decimal.Parse(Request["workersComp"] ?? ""); var percentileItem = Core.DataLayer.WorkersComp.Percentage(context, industryId, geo, (double)attr.WorkersComp); if (percentileItem != null) { analyticsAttr.WorkersCompPercentage = percentileItem.Percentage; } } if (Request.Form.AllKeys.Contains("yearStarted")) { //cookie.Values.Add("yearStarted", Request["yearStarted"]); attr.YearStarted = int.Parse(Request["yearStarted"] ?? ""); var percentileItem = Core.DataLayer.YearStarted.Percentile(context, industryId, geo, attr.YearStarted ?? 0); if (percentileItem != null) { analyticsAttr.YearStartedPercentile = percentileItem.Percentile; } } } if (User.Identity.IsAuthenticated) { using (var context = ContextFactory.UserDataContext) { var user = Membership.GetUser(User.Identity.Name); Guid userid = (Guid)user.ProviderUserKey; attr.UserId = userid; analyticsAttr.UserId = userid; var item = context.BusinessAttributes.Where(i => i.UserId == userid && i.PlaceId == placeId && i.IndustryId == industryId).FirstOrDefault(); if (item != null) { //test for changes... update if there are and then insert into analytics else ignore if (item.AverageSalary != attr.AverageSalary || item.BusinessSize != attr.BusinessSize || item.BusinessType != attr.BusinessType || item.Employees != attr.Employees || item.HealthcareCost != attr.HealthcareCost || item.Revenue != attr.Revenue || item.WorkersComp != attr.WorkersComp || item.YearStarted != attr.YearStarted) { item.AverageSalary = attr.AverageSalary; item.BusinessSize = attr.BusinessSize; item.BusinessType = attr.BusinessType; item.Employees = attr.Employees; item.HealthcareCost = attr.HealthcareCost; item.Revenue = attr.Revenue; item.WorkersComp = attr.WorkersComp; item.YearStarted = attr.YearStarted; context.SaveChanges(); } } else { context.BusinessAttributes.AddObject(attr); context.SaveChanges(); } } } analyticsAttr.AverageSalary = attr.AverageSalary; analyticsAttr.BusinessSize = attr.BusinessSize; analyticsAttr.BusinessType = attr.BusinessType; analyticsAttr.Employees = attr.Employees; analyticsAttr.HealthcareCost = attr.HealthcareCost; analyticsAttr.Revenue = attr.Revenue; analyticsAttr.WorkersComp = attr.WorkersComp; analyticsAttr.YearStarted = attr.YearStarted; Singleton <Tracker> .Instance.BusinessAttribute(analyticsAttr); //Response.Cookies.Add(cookie); return(Json(true, JsonRequestBehavior.AllowGet)); }