Exemplo n.º 1
0
 public JsonResult UpdateNotifications()
 {
     using (var dbContext = new DashBoardDBEntities())
     {
         var widgets = dbContext.WidgetUserMaps.Where(t => t.UserName == User.Identity.Name).ToList();
         foreach (WidgetUserMap widget in widgets)
         {
             widget.IsRead = true;
         }
         dbContext.SaveChanges();
     }
     //return Json("");
     return(Json("", JsonRequestBehavior.AllowGet));
 }
Exemplo n.º 2
0
 //Retain position of widget
 public JsonResult RepositionWidget(int WidgetID, int Column, int Row)
 {
     using (var dbContext = new DashBoardDBEntities())
     {
         var widget = dbContext.Widgets.Where(t => t.WidgetID == WidgetID).FirstOrDefault();
         if (widget != null)
         {
             widget.Column = Column;
             widget.Row    = Row;
         }
         dbContext.SaveChanges();
     }
     return(Json(new { Data = "Updated" }));
 }
Exemplo n.º 3
0
        //Retaining size of widget

        public JsonResult ResizeWidget(int WidgetID, int Width, int Height)
        {
            using (var dbContext = new DashBoardDBEntities())
            {
                var widget = dbContext.Widgets.Where(t => t.WidgetID == WidgetID).FirstOrDefault();
                if (widget != null)
                {
                    widget.Height = Height;
                    widget.Width  = Width;
                }
                dbContext.SaveChanges();
            }
            return(Json(new { Data = "Updated" }));
        }
Exemplo n.º 4
0
        public JsonResult DeleteWidget(int WidgetID)
        {
            using (var dbContext = new DashBoardDBEntities())
            {
                var widget = dbContext.Widgets.Where(t => t.WidgetID == WidgetID).FirstOrDefault();
                dbContext.Widgets.Remove(widget);

                //remove existing mapping
                var currentMaps = dbContext.WidgetUserMaps.Where(c => c.WidgetID == WidgetID);
                if (currentMaps != null)
                {
                    dbContext.WidgetUserMaps.RemoveRange(currentMaps);
                }

                dbContext.SaveChanges();
            }
            return(Json(new { Data = "Updated" }));
        }
Exemplo n.º 5
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(""));
        }
Exemplo n.º 6
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" }));
        }