Ejemplo n.º 1
0
        private void CreateImage(AddEditPageViewMode model,
                                 Page page)
        {
            for (int i = 0;
                 i < model.Images.Length;
                 i++)
            {
                var image = model.Images[i];
                if (page.Content.Images.Count >= i + 1 && page.Content.Images.Count > 0)
                {
                    page.Content.Images.ToArray()[i]
                    .Base64 = image.Base64;
                }
                else
                {
                    var entityImage = new Image
                    {
                        Base64   = image.Base64,
                        Content  = page.Content,
                        Position = i,
                    };

                    _context.Images.Add(entityImage);
                }
            }
        }
Ejemplo n.º 2
0
        private void CreateTab(AddEditPageViewMode model,
                               Page page)
        {
            foreach (var tab in model.Tabs)
            {
                var tabEntity = new Tab
                {
                    Content = page.Content,
                    Text    = tab.Text,
                    Name    = tab.Name
                };
                _context.Tabs.Add(tabEntity);

                foreach (var tabImage in tab.Images)
                {
                    var imageEntity = new Image
                    {
                        Base64 = tabImage,
                        Tab    = tabEntity,
                    };
                    _context.Images.Add(imageEntity);
                }
            }

            _context.SaveChanges();
        }
Ejemplo n.º 3
0
        public AddEditPageViewMode GetByAlias(string alias)
        {
            var page = _context.Pages.FirstOrDefault(p => p.Alias.ToLower() == alias.ToLower());

            var model = new AddEditPageViewMode
            {
                PageId   = page.Id,
                PageName = page.Name,
                Contents = page.Content.TextFields.Select(c => c.Text)
                           .ToArray(),
                Images = page.Content.Images.Select(i => new ImageViewModel
                {
                    Id     = i.Id,
                    Base64 = i.Base64
                })
                         .ToArray(),
                Tabs = page.Type == (PageType)2 ? page.Content.Tabs.Select(tab => new AddEditTabViewModel
                {
                    Id     = tab.Id,
                    Name   = tab.Name,
                    Text   = tab.Text,
                    Images = tab.Images.Select(i => i.Base64).ToArray()
                }).ToArray() : null
            };

            return(model);
        }
Ejemplo n.º 4
0
        public IActionResult AddEditPage(AddEditPageViewMode model)
        {
            var response = _pageService.CreatePage(model);

            if (response == null)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Ejemplo n.º 5
0
 private static void EditTextFields(AddEditPageViewMode model,
                                    Page page)
 {
     for (int i = 0;
          i < model.Contents.Length;
          i++)
     {
         var input = model.Contents[i];
         page.Content.TextFields.ToArray()[i]
         .Text = input ?? "";
     }
 }
Ejemplo n.º 6
0
        private void CreateTextFields(AddEditPageViewMode model,
                                      string contentId)
        {
            foreach (var content in model.Contents)
            {
                var entity = new TextField
                {
                    ContentId = contentId,
                    Text      = content ?? ""
                };

                _context.TextFields.Add(entity);
            }
        }
Ejemplo n.º 7
0
        public AddEditPageViewMode CreatePage(AddEditPageViewMode model)
        {
            var page = _context.Pages.Find(model.PageId);

            if (page == null)
            {
                return(null);
            }

            if (page.Content == null)
            {
                CreateContent(page);
            }

            //if (page.Type == PageType.Tabs)
            //{
            //    CreateTab(model,
            //        page);
            //}

            var contentId = page.ContentId;

            if (page.Content.TextFields.Count == 0)
            {
                CreateTextFields(model,
                                 contentId);
            }
            else
            {
                EditTextFields(model,
                               page);
            }


            if (model.Images.Length > 0)
            {
                CreateImage(model,
                            page);
            }

            _context.SaveChanges();

            return(model);
        }
Ejemplo n.º 8
0
        public AddEditPageViewMode Get(string id)
        {
            var page = _context.Pages.Find(id);

            if (page == null || page.IsActive == false)
            {
                page = _context.Pages.FirstOrDefault(x => x.Alias == id);
            }

            if (page == null || page.IsActive == false)
            {
                return(null);
            }

            var model = new AddEditPageViewMode
            {
                PageId   = page.Id,
                PageName = page.Name,
                Contents = page.Content.TextFields.Select(c => c.Text)
                           .ToArray(),
                Images = page.Content.Images.Select(i => new ImageViewModel
                {
                    Id     = i.Id,
                    Base64 = i.Base64
                })
                         .ToArray(),
                Type      = (int)page.Type,
                ContentId = page.ContentId,
                Tabs      = page.Content.Tabs.Select(tab => new AddEditTabViewModel
                {
                    Id     = tab.Id,
                    Images = tab.Images.Select(i => i.Base64).ToArray(),
                    Name   = tab.Name,
                    Text   = tab.Text
                }).ToArray()
            };

            return(model);
        }