Пример #1
0
        public ActionResult Index(AddBoxViewModel model)
        {
            if (model.BoxVideos == null || model.BoxVideos.Count == 0 || model.BoxVideos.First().VideoUrl == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Please add at least one video url."));
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            model.BoxVideos.RemoveAll(x => String.IsNullOrEmpty(x.VideoUrl));


            var response = AsyncHelpers.RunSync <JObject>(() => ApiCall.CallApi("api/Admin/AddBox", User, model));

            if (response is Error)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, (response as Error).ErrorMessage));
            }

            if (model.Id > 0)
            {
                TempData["SuccessMessage"] = "The box has been updated successfully.";
            }
            else
            {
                TempData["SuccessMessage"] = "The box has been added successfully.";
            }

            return(Json("Success"));
        }
        public async Task TestIfGetAllBoxesForPageWorksAccordingly(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 result = await categoryPagesService.GetAllBoxesForPageAsync(pageName);

            Assert.NotEmpty(result);

            Assert.Contains(result, x => x.Href == href && x.Text == text && x.Color == color);
        }
Пример #3
0
        public async Task <IActionResult> AddBox()
        {
            var model = new AddBoxViewModel();

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

            return(this.View(model));
        }
Пример #4
0
        public async Task AddBoxAsync(AddBoxViewModel form)
        {
            var page = await this.context.Pages.FirstOrDefaultAsync(x => x.PageName == "Index");

            page.ColorfulBoxes.Add(new ColorfulBox {
                Color = form.Color, Href = form.Href, Text = form.Text, CreatedOn = DateTime.UtcNow, ModificationDate = DateTime.UtcNow
            });

            await this.context.SaveChangesAsync();
        }
Пример #5
0
        public async Task <IActionResult> AddBox(AddBoxViewModel form)
        {
            if (this.ModelState.IsValid && await this.service.PageAlreadyExistsAsync(form.PageName))
            {
                await this.service.AddBoxAsync(form);

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

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

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

            await Assert.ThrowsAsync <NullReferenceException>(async() =>
            {
                var model = new AddBoxViewModel();
                await categoryPagesService.AddBoxAsync(model);
            });
        }