Exemplo n.º 1
0
        public IHttpActionResult AddNewWidgetToDashboard([FromBody] AddWidgetDTO model)
        {
            UnitOfWorkManager uowManager = new UnitOfWorkManager();

            widgetManager = new WidgetManager(uowManager);
            itemManager   = new ItemManager(uowManager);

            Dashboard dash = widgetManager.GetDashboard(User.Identity.GetUserId());

            List <PropertyTag> propertyTags = new List <PropertyTag> {
                new PropertyTag()
                {
                    Name = model.PropertyTag
                }
            };

            List <Item> items = itemManager.GetAllItems().Where(i => model.ItemIds.Contains(i.ItemId)).ToList();

            if (string.IsNullOrEmpty(model.Title))
            {
                model.Title = Resources.Title;
            }

            widgetManager.AddWidget(WidgetType.GraphType, model.Title, 0,
                                    0, propertyTags, graphType: model.GraphType, dashboardId: dash.DashboardId, items: items);

            uowManager.Save();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        /// <summary>
        ///Reads all widgets for a user dashboard and returns them
        /// </summary>
        public IHttpActionResult GetUserWidgets()
        {
            widgetManager = new WidgetManager();
            Dashboard dash = widgetManager.GetDashboard(User.Identity.GetUserId());

            try {
                List <UserWidget> widgets = widgetManager.GetWidgetsForDashboard(dash.DashboardId).ToList();

                if (widgets == null || widgets.Count() == 0)
                {
                    return(StatusCode(HttpStatusCode.NoContent));
                }

                return(Ok(Mapper.Map(widgets, new List <UserWidgetDTO>())));
            } catch (Exception e) {
                return(BadRequest(e.Message));
            }
        }