public JsonResult Upload() { for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase file = Request.Files[i]; //Uploaded file int fileSize = file.ContentLength; string fileName = file.FileName; string mimeType = file.ContentType; System.IO.Stream fileContent = file.InputStream; //To save file, use SaveAs method file.SaveAs(Server.MapPath("~/Images/Banners/") + fileName); int order = 0; var allBanners = BannerService.GetAllBanners(); if (allBanners != null && allBanners.Any()) { order = allBanners.Count; } BannerService.AddBanner(new Banner { FileName = fileName, ShowOrder = order + 1, Status = false }); } return(Json("Uploaded " + Request.Files.Count + " files")); }
public void GetAllBannersTest() { BannerContext context = new BannerContext(new DbContextOptionsBuilder <BannerContext>().UseInMemoryDatabase(databaseName: "BannerItemsTest3").Options); var testBanners = TestBanners(); context.Banners.AddRange(testBanners); context.SaveChanges(); var bannerService = new BannerService(context); var actual = bannerService.GetAllBanners(); var expected = testBanners; Assert.NotNull(actual); Assert.Equal(expected, actual); }
public void DeleteBannerTest() { BannerContext context = new BannerContext(new DbContextOptionsBuilder <BannerContext>().UseInMemoryDatabase(databaseName: "BannerItemsTest4").Options); var testBanners = TestBanners(); context.Banners.AddRange(testBanners); context.SaveChanges(); var bannerService = new BannerService(context); bannerService.DeleteBanner(2); var actual = bannerService.GetAllBanners(); testBanners.Remove(testBanners.Find(x => x.Id == 2)); var expected = testBanners; Assert.Equal(expected, actual); }
public ActionResult ListView() { //var baseUrl = Server.MapPath("~/Images/Banners/"); //string[] images = Directory.GetFiles(baseUrl, "*") // .Select(Path.GetFileName) // .ToArray(); var images = new List <BannerModel>(); var fullImages = BannerService.GetAllBanners(); if (fullImages != null && fullImages.Any()) { images = fullImages.Select(img => new BannerModel { Id = img.Id, FileName = img.FileName, ShowOrder = img.ShowOrder, Status = img.Status }).ToList(); } return(View(images)); }
public void UpdateBannerTest() { var updateBanner = new Banner() { Id = 2, Html = "<body>UpdateBanner<body/>", Created = DateTime.Now, Modified = DateTime.Now }; BannerContext context = new BannerContext(new DbContextOptionsBuilder <BannerContext>().UseInMemoryDatabase(databaseName: "BannerItemsTest5").Options); var testBanners = TestBanners(); context.Banners.AddRange(testBanners); context.SaveChanges(); var bannerService = new BannerService(context); bannerService.UpdateBanner(updateBanner); var actual = bannerService.GetAllBanners(); var index = testBanners.FindIndex(x => x.Id == updateBanner.Id); testBanners.RemoveAt(index); testBanners.Insert(index, updateBanner); var expected = testBanners; CollectionAssert.AreEqual(expected, actual); }
public IActionResult GetAllBanner() { var list = bnservice.GetAllBanners(); return(Ok(list)); }