Пример #1
0
        public async Task Update(int id, WidgetVariation model)
        {
            var widget = await _widgetsContext.WidgetVariations.FindAsync(id);

            if (widget == null)
            {
                return;
            }

            model.Id = 0;

            foreach (var item in model.Audiences)
            {
                item.Id = 0;
            }

            foreach (var state in model.States)
            {
                state.Id = 0;

                foreach (var container in state.WidgetContainers)
                {
                    container.Id = 0;

                    foreach (var component in container.WidgetComponents)
                    {
                        component.Id = 0;
                    }
                }
            }

            _widgetsContext.Remove(widget);
            _widgetsContext.Add(model);
            await _widgetsContext.SaveChangesAsync();
        }
Пример #2
0
        public async Task <IActionResult> Update([FromRoute] int id, [FromBody] WidgetVariation model)
        {
            await _widgetsService.Update(id, model);

            await _unitOfWork.Save();

            return(NoContent());
        }
Пример #3
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);
        }