コード例 #1
0
        //share widget to selected users
        public ActionResult SaveWidgetShare(string[] sharedUsers, string widgetID)
        {
            using (var dbContext = new DashBoardDBEntities())
            {
                foreach (string user in sharedUsers)
                {
                    //dbContext.WidgetUserMaps.Remove
                    var currentMap = dbContext.WidgetUserMaps.Where(c => c.UserName == user && c.WidgetID.ToString() == widgetID && c.IsOwner != true).FirstOrDefault();
                    if (currentMap != null)
                    {
                        dbContext.WidgetUserMaps.Remove(currentMap);
                    }

                    WidgetUserMap userMap = new WidgetUserMap();
                    userMap.UserName = user;
                    userMap.WidgetID = Convert.ToInt32(widgetID);
                    dbContext.WidgetUserMaps.Add(userMap);
                }

                dbContext.SaveChanges();
            }
            return(Json(""));
        }
コード例 #2
0
        //Save widget details passed from main screen
        public ActionResult SaveApiWidget(WidgetModel model)
        {
            bool flgNewWidget = false;

            using (var dbContext = new DashBoardDBEntities())
            {
                var        widget     = dbContext.Widgets.Where(t => t.WidgetID == model.WidgetID).FirstOrDefault();
                var        widgetType = dbContext.WidgetTypes.Where(t => t.WidgetTypeID == model.WidgetTypeID).FirstOrDefault();
                DataSource dataSource = dbContext.DataSources.Where(t => t.DataSourceType == model.DataSourceName).FirstOrDefault();
                if (model.ApiChart != null)
                {
                    if (widget == null)
                    {
                        widget = CreateWidgetObject(model.ApiChart.title.text);
                        dbContext.Entry(widget).State = EntityState.Added;
                        flgNewWidget = true;
                    }

                    dbContext.DataSources.Attach(dataSource);
                    widget.DataSource = dataSource;

                    widget.WidgetType   = widgetType;
                    widget.WidgetTypeID = widgetType.WidgetTypeID;
                    widget.WidgetTypeInputParamValues = JsonConvert.SerializeObject(model.ApiChart);
                    WidgetSchemaMapper widgetSchemaMapper = new WidgetSchemaMapper(widget);
                    string             widgetSchema       = widgetSchemaMapper.GetSchema();
                    widget.WidgetTypeInputParamValues = widgetSchema;
                    dbContext.SaveChanges();
                }
                if (model.DonutChart != null && widgetType.WidgetTypeID == 4)
                {
                    if (widget == null)
                    {
                        widget = CreateWidgetObject(model.DonutChart.title.text);
                        dbContext.Entry(widget).State = EntityState.Added;
                        flgNewWidget = true;
                    }

                    dbContext.DataSources.Attach(dataSource);
                    widget.DataSource = dataSource;


                    widget.WidgetType   = widgetType;
                    widget.WidgetTypeID = widgetType.WidgetTypeID;
                    widget.WidgetTypeInputParamValues = JsonConvert.SerializeObject(model.DonutChart);
                    WidgetSchemaMapper widgetSchemaMapper = new WidgetSchemaMapper(widget);
                    string             widgetSchema       = widgetSchemaMapper.GetSchema();
                    widget.WidgetTypeInputParamValues = widgetSchema;
                    dbContext.SaveChanges();
                }
                //user mapping for new widget
                if (flgNewWidget)
                {
                    WidgetUserMap userMap = new WidgetUserMap();
                    userMap.UserName = User.Identity.Name;
                    userMap.WidgetID = Convert.ToInt32(widget.WidgetID);
                    userMap.IsOwner  = true;
                    userMap.IsRead   = true;
                    dbContext.WidgetUserMaps.Add(userMap);
                    dbContext.SaveChanges();
                }
            }
            return(Json(new { Data = "Successfully saved" }));
        }