public IActionResult ViewDashboard(int id)
 {
     try
     {
         DashboardsInfo dashboardInfo  = _dashboardInfoRepository.GetDashboardInfo(id);
         int            widgetsCount   = _dashboardInfoRepository.GetWidgetsCount(dashboardInfo.TemplateId).Value;
         var            linked_widgets = _dashboardInfoRepository.GetLinkedWidgets(id);
         for (int i = 1; i <= widgetsCount; i++)
         {
             var widget = linked_widgets.Where(x => x.Placement == i.ToString());
             if (widget.Any())
             {
                 ViewData["Widget" + i] = "../Widgets/Widget" + widget.First().WidgetId + ".cshtml";
             }
             else
             {
                 ViewData["Widget" + i] = "../Widgets/Default.cshtml";
             }
         }
         ViewData["dashboardId"] = id;
         return(View("Templates/Template" + dashboardInfo.TemplateId));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(new EmptyResult());
     }
 }
 public string CreateDashboard(DashboardsInfo dashboard)
 {
     try
     {
         return(_dashboardInfoRepository.CreateDashboard(dashboard));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return("False");
     }
 }
        public string Createdashboard(DashboardsInfo dashboard)
        {
            try
            {
                db.DashboardsInfo.Add(dashboard);
                db.SaveChanges();

                return(dashboard.Id.ToString());
            }
            catch (System.Exception)
            {
                return("False");
            }
        }
        public string CreateDashboard(DashboardsInfo dashboard)
        {
            string query = @"insert into Dashboards_Info(Name, TemplateId) values(@Name, @TemplateId)";

            try
            {
                var sqlParamList = new object[] { new SqlParameter("@Name", dashboard.Name), new SqlParameter("@TemplateId", dashboard.TemplateId) };
                int count        = _context.Database.ExecuteSqlRaw(query, sqlParamList);
                if (count > 0)
                {
                    dashboard = _context.DashboardsInfos.Where(x => x.Name.Equals(dashboard.Name)).FirstOrDefault();
                }
                return(dashboard.Id.ToString());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return("False");
            }
        }
        public IActionResult Dashboard(int id)
        {
            DashboardsInfo dashboard = db.DashboardsInfo.Where(s => s.Id == id).FirstOrDefault();
            int elementsCount = (int)db.Templates.Where(s=>s.Id == dashboard.TemplateId).Select(s=>s.ElementsCount).FirstOrDefault();

            var linked_elements  = db.DashboardLinkedElements.Where(s=>s.DashboardId == id).ToList();
            for (int i = 1; i <= elementsCount; i++)
            {
                var element = linked_elements.Where(s=>s.Placement == i.ToString());
                if(element.Any()){
                    ViewData["Element"+i] = "../Elements/Element"+element.First().ElementId+".cshtml";
                }
                else{
                    ViewData["Element"+i] = "../Elements/Default.cshtml";
                }
            }

            ViewData["dashboardId"] = id;
            return View("Templates/Template"+dashboard.TemplateId);
        }