public async Task <ActionResult <Widget> > CreateWidget([FromBody] Widget widget)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _context.Add(widget);
            await _context.SaveChangesAsync();

            return(widget);
        }
Esempio n. 2
0
        public async Task <int> Create()
        {
            var widget = new WidgetVariation
            {
                Name   = "Demo widget",
                States = new List <WidgetState>
                {
                    new WidgetState
                    {
                        Name             = "Widget state 1",
                        WidgetContainers = new List <WidgetContainer>
                        {
                            new WidgetContainer
                            {
                                Name             = "Widget container 1.1",
                                WidgetComponents = new List <WidgetComponent>
                                {
                                    new WidgetComponent
                                    {
                                        Name = "Widget component 1.1.1",
                                    },
                                    new WidgetComponent
                                    {
                                        Name = "Widget component 1.1.2",
                                    }
                                }
                            },
                            new WidgetContainer
                            {
                                Name             = "Widget container 1.2",
                                WidgetComponents = new List <WidgetComponent>
                                {
                                    new WidgetComponent
                                    {
                                        Name = "Widget component 1.2.1",
                                    },
                                    new WidgetComponent
                                    {
                                        Name = "Widget component 1.2.2",
                                    }
                                }
                            }
                        }
                    },
                    new WidgetState
                    {
                        Name             = "Widget state 2",
                        WidgetContainers = new List <WidgetContainer>
                        {
                            new WidgetContainer
                            {
                                Name             = "Widget container 2.1",
                                WidgetComponents = new List <WidgetComponent>
                                {
                                    new WidgetComponent
                                    {
                                        Name = "Widget component 2.1.1",
                                    },
                                    new WidgetComponent
                                    {
                                        Name = "Widget component 2.1.2",
                                    }
                                }
                            },
                            new WidgetContainer
                            {
                                Name             = "Widget container 1.2",
                                WidgetComponents = new List <WidgetComponent>
                                {
                                    new WidgetComponent
                                    {
                                        Name = "Widget component 2.2.1",
                                    },
                                    new WidgetComponent
                                    {
                                        Name = "Widget component 2.2.2",
                                    }
                                }
                            }
                        }
                    },
                },
                Audiences = new List <WidgetAudience>
                {
                    new WidgetAudience
                    {
                        Name = "Widget audience 1"
                    },
                    new WidgetAudience
                    {
                        Name = "Widget audience 2"
                    }
                }
            };

            await _widgetsContext.WidgetVariations.AddAsync(widget);

            await _widgetsContext.SaveChangesAsync();

            return(widget.Id);
        }
Esempio n. 3
0
 public Task Save()
 {
     return(_widgetsContext.SaveChangesAsync());
 }