public ActionResult Get(string pk) { try { const string ViewName = "MyCharts"; View view = GetView(ViewName); if (view == null) { Exception exception = new DuradosException(string.Format("Could not find {0} view in configuration", ViewName)); return(new UnexpectedApiHttpException(exception, Response)); } if (!string.IsNullOrEmpty(pk)) { var item = RestHelper.Get(view, pk, true, view_BeforeSelect, view_AfterSelect); if (item == null) { return(new DashboardNotFoundApiHttpException(pk, Response)); } Response.StatusCode = (int)HttpStatusCode.OK; return(Json(item, JsonRequestBehavior.AllowGet)); } else { int rowCount = 0; var items = RestHelper.Get(view, false, false, 1, 1000, null, null, null, out rowCount, false, view_BeforeSelect, view_AfterSelect); Response.StatusCode = (int)HttpStatusCode.OK; return(Json(items, JsonRequestBehavior.AllowGet)); } } catch (Exception exception) { return(new UnexpectedApiHttpException(exception, Response)); } }
public ActionResult Widget() { string id = GetIdFromParameters(); PlugInType plugInType = PlugInType; //string userId = GetUserID(); //if (string.IsNullOrEmpty(userId)) //{ // userId = Maps.Instance.DuradosMap.Database.CreatePlugInUser(id, plugInType, GetPlugInUserGuid()); //} //if (string.IsNullOrEmpty(userId)) // return RedirectToAction(EmptyWidgetActionName); DataRow instanceRow = Maps.Instance.DuradosMap.Database.GetSelectedInstanceRow(id, plugInType); if (instanceRow == null) { int?sampleAppId = null; if (string.IsNullOrEmpty(Request.QueryString[SampleAppIdInQueryString])) { sampleAppId = Maps.Instance.DuradosMap.Database.GetFirstSampleId(plugInType); } else { sampleAppId = (int?)Convert.ToInt32(Request.QueryString[SampleAppIdInQueryString]); } instanceRow = Maps.Instance.DuradosMap.Database.CreateSampleInstanceRow(id, plugInType, sampleAppId, GetPlugInUserId()); if (instanceRow == null) { new AppsGenerator().Generate(sampleAppId.Value, Maps.PlugInSampleGenerationCount); instanceRow = Maps.Instance.DuradosMap.Database.CreateSampleInstanceRow(id, plugInType, sampleAppId, GetPlugInUserId()); } if (instanceRow == null) { Exception exception = new DuradosException("Could not create sample instance"); Map.Logger.Log(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "username: "******", id: " + this.Request.QueryString["id"], exception, 78, "url: " + System.Web.HttpContext.Current.Request.Url.ToString()); return(RedirectToAction(EmptyWidgetActionName)); } } //int appId = Maps.Instance.DuradosMap.Database.GetAppId(id, plugInType, instanceRow, userId); //(int)instanceRow["AppId"]; int appId = (int)instanceRow["AppId"]; string viewName = (string)instanceRow["ViewName"]; string appName = Maps.Instance.GetAppRow(appId).Name; if (string.IsNullOrEmpty(appName)) { Exception exception = new DuradosException("No app name for id:" + appId); Map.Logger.Log(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "username: "******", id: " + this.Request.QueryString["id"], exception, 78, "url: " + System.Web.HttpContext.Current.Request.Url.ToString() + ", appName: " + appName + ", viewName: " + viewName); return(RedirectToAction(EmptyWidgetActionName)); } //bool isSampleApp = !instanceRow.IsNull("SampleAppId"); //string paremeters = string.Empty; //if (isSampleApp) //{ // string creatorGuid = GetCreatorGuid(appId); // paremeters = "&id=" + creatorGuid; //} Map map = Maps.Instance.GetMap(appName); if (!IsAuthorized(map)) { Exception exception = new DuradosException("Not authorized for app " + appName); Map.Logger.Log(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "username: "******", id: " + this.Request.QueryString["id"], exception, 78, "url: " + System.Web.HttpContext.Current.Request.Url.ToString() + ", appName: " + appName + ", viewName: " + viewName); return(RedirectToAction(EmptyWidgetActionName)); } Durados.View view = map.Database.Views.ContainsKey(viewName) ? map.Database.Views[viewName] : null; if (view == null || !IsAuthorized(view)) { Exception exception = new DuradosException("Could not find view " + viewName + " check that configuration files exist"); Map.Logger.Log(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "username: "******", id: " + this.Request.QueryString["id"], exception, 78, "url: " + System.Web.HttpContext.Current.Request.Url.ToString() + ", appName: " + appName + ", viewName: " + viewName); return(RedirectToAction(EmptyWidgetActionName)); } string url = GetViewUrl(map, viewName) + GetPublicParameter(); //string url = GetViewUrl(map, viewName) + GetUserIdParameterForLogin(instanceRow, appId) + GetPublicParameter(); //if (!IsSignedIn(Maps.Instance.DuradosMap.Database.GetCreatorUsername(appId))) //{ // SignOut(); // SignIn(Maps.Instance.DuradosMap.Database.GetCreatorUsername(appId)); // return Redirect(url); //} UpdatePlan(instanceRow); ViewData["url"] = url; ViewData["signOutUrl"] = Url.Action("SignOut") + "?" + GetParameters(); //map.Url + "/Account/LogOff"; Map.Logger.Log(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "username: "******", id: " + this.Request.QueryString["id"], null, 77, "url: " + System.Web.HttpContext.Current.Request.Url.ToString() + ", redirect: " + url + ", appName: " + appName + ", viewName: " + viewName); return(View()); //return Redirect(url); }