public string AddWidget(DashboardLinkedWidgets widget) { try { _dashboardInfoRepository.RemoveWidgets(widget); return(_dashboardInfoRepository.AddWidget(widget).Equals(true) ? "True" : "False"); } catch (Exception ex) { _logger.LogError(ex.Message); return(ex.Message); } }
public bool AddWidget(DashboardLinkedWidgets widget) { string query = @"insert into DashboardLinkedWidgets(DashboardId, WidgetId, Placement) values(@DashboardId, @WidgetId, @Placement)"; try { var sqlParamList = new object[] { new SqlParameter("@DashboardId", widget.DashboardId), new SqlParameter("@WidgetId", widget.WidgetId), new SqlParameter("@Placement", widget.Placement) }; return(_context.Database.ExecuteSqlRaw(query, sqlParamList) > 0); } catch (Exception ex) { _logger.LogError(ex.Message); return(false); } }
public bool RemoveWidgets(DashboardLinkedWidgets widget) { try { var oldWidgets = _context.DashboardLinkedWidgets.Where(x => x.DashboardId == widget.DashboardId && x.Placement == widget.Placement).ToList(); if (oldWidgets != null) { oldWidgets.ForEach(x => _context.DashboardLinkedWidgets.Remove(x)); _context.SaveChanges(); return(true); } else { return(false); } } catch (Exception ex) { _logger.LogError(ex.Message); return(false); } }