public IActionResult DeleteLayoutRow(string id)
        {
            var userId = TuxConfiguration.DefaultUser;

            TuxViewMessage message = null;

            var dashboard = _service.GetDashboardFor(userId);
            var layout    = dashboard.GetLayoutByLayoutRow(id);

            var canDelete = true;

            var row = layout.LayoutRows.FirstOrDefault(t => t.LayoutRowId == id);

            if (row != null)
            {
                var widgetsExist = row.RowContainsWidgets();
                if (widgetsExist)
                {
                    message = new TuxViewMessage(
                        "Row contains widgets and cannot be deleted.",
                        TuxMessageType.Danger, false, row.LayoutRowId);
                    canDelete = false;
                }
            }

            var oneRowExists = layout.ContainsOneRow();

            if (oneRowExists && message == null)
            {
                message = new TuxViewMessage(
                    "You cannot delete the only row on the dashboard.",
                    TuxMessageType.Danger, false);
                canDelete = false;
            }

            if (canDelete)
            {
                message = new TuxViewMessage(
                    "Row can be removed.",
                    TuxMessageType.Success, true);
            }

            return(Ok(message));
        }
Beispiel #2
0
        public async Task <IActionResult> OnPostDeleteLayoutRow([FromBody] PostData data)
        {
            var userId = GetCurrentUser();

            var id = data.LayoutRowId;

            TuxViewMessage message = null;

            var dashboard = string.IsNullOrEmpty(userId)
                ? await _service.GetDashboardAsync(_config)
                : await _service.GetDashboardForAsync(_config, userId);

            var layout = dashboard.GetLayoutByLayoutRow(id);

            var canDelete = true;

            if (layout.RowContainsWidgets(id))
            {
                message = new TuxViewMessage(
                    "Row contains widgets and cannot be deleted.",
                    TuxMessageType.Danger, false, id);
                canDelete = false;
            }

            var oneRowExists = layout.ContainsOneRow();

            if (oneRowExists && message == null)
            {
                message = new TuxViewMessage(
                    "You cannot delete the only row on the dashboard.",
                    TuxMessageType.Danger, false);
                canDelete = false;
            }

            if (canDelete)
            {
                message = new TuxViewMessage(
                    "Row can be removed.",
                    TuxMessageType.Success, true);
            }

            return(new OkObjectResult(message));
        }
Beispiel #3
0
        public IActionResult DeleteLayoutRow(string id)
        {
            var userId = GetCurrentUser();

            TuxViewMessage message = null;

            var dashboard = _service.GetDashboardFor(_config, userId);
            var layout    = dashboard.GetLayoutByLayoutRow(id);

            var canDelete = true;

            if (layout.RowContainsWidgets(id))
            {
                message = new TuxViewMessage(
                    "Row contains widgets and cannot be deleted.",
                    TuxMessageType.Danger, false, id);
                canDelete = false;
            }

            var oneRowExists = layout.ContainsOneRow();

            if (oneRowExists && message == null)
            {
                message = new TuxViewMessage(
                    "You cannot delete the only row on the dashboard.",
                    TuxMessageType.Danger, false);
                canDelete = false;
            }

            if (canDelete)
            {
                message = new TuxViewMessage(
                    "Row can be removed.",
                    TuxMessageType.Success, true);
            }

            return(Ok(message));
        }