예제 #1
0
        public async Task <IActionResult> EditBoxes(EditBoxesViewModel form)
        {
            if (this.ModelState.IsValid && await this.service.PageAlreadyExistsAsync(form.PageName))
            {
                await this.service.EditBoxesAsync(form);

                return(this.RedirectToAction("Success", "Blacksmith", new { message = "Successfully Edited Box" }));
            }

            return(this.View(form));
        }
        public async Task TestIfEditBoxesThrowsError()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);

            await Assert.ThrowsAsync <NullReferenceException>(async() =>
            {
                var form = new EditBoxesViewModel();

                await categoryPagesService.EditBoxesAsync(form);
            });
        }
        public async Task TestIfEditBoxesWorksAccordingly(string pageName, string href, string text,
                                                          string color)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);

            await context.Pages.AddAsync(new Page
            {
                PageName      = pageName,
                ColorfulBoxes = new List <ColorfulBox>(),
            });

            await context.SaveChangesAsync();

            var model = new AddBoxViewModel();

            model.Color    = color;
            model.Href     = href;
            model.Text     = text;
            model.PageName = pageName;

            await categoryPagesService.AddBoxAsync(model);

            var boxModel = new EditBoxesViewModel();

            boxModel.PageName = pageName;
            boxModel.Boxes    = new List <EditBoxViewModel>
            {
                new EditBoxViewModel
                {
                    Color = "edited",
                    Href  = "edited",
                    Text  = "edited",
                }
            };

            await categoryPagesService.EditBoxesAsync(boxModel);

            var result = await categoryPagesService.GetAllBoxesForPageAsync(pageName);

            Assert.NotEmpty(result);

            Assert.Contains(result, (x) => x.Href == "edited" && x.Color == "edited" && x.Text == "edited");
        }
        public async Task EditBoxesAsync(EditBoxesViewModel form)
        {
            var page = await this.context.Pages.FirstOrDefaultAsync(x => x.PageName == form.PageName);

            var boxes = page.ColorfulBoxes.Where(x => x.IsDeleted == false).ToList();

            for (int i = 0; i < form.Boxes.Count; i++)
            {
                var formBox = form.Boxes[i];

                var dbBox = boxes[i];

                dbBox.Href      = formBox.Href;
                dbBox.Color     = formBox.Color;
                dbBox.Text      = formBox.Text;
                dbBox.IsDeleted = formBox.IsDeleted;
            }

            await this.context.SaveChangesAsync();
        }
예제 #5
0
        public async Task <IActionResult> EditBoxes(string pageName)
        {
            var model = new EditBoxesViewModel();

            model.Pages = await this.service.GetAllPageNamesAsync();

            if (!string.IsNullOrEmpty(pageName) && await this.service.PageAlreadyExistsAsync(pageName))
            {
                model.PageName = pageName;
                var boxes = await this.service.GetAllBoxesForPageAsync(pageName);

                foreach (var box in boxes)
                {
                    model.Boxes.Add(new EditBoxViewModel
                    {
                        Color     = box.Color,
                        Text      = box.Text,
                        Href      = box.Href,
                        IsDeleted = box.IsDeleted
                    });
                }
            }
            return(this.View(model));
        }