Example #1
0
        public ActionResult AddNewCategory(CategoryVM newCategory)
        {
            if (ModelState.IsValid == false)
            {
                return(View(newCategory));
            }


            //string filename = Path.GetFileName(newCategory.ImageFile.FileName);
            //filename = Path.Combine(Server.MapPath("/Content/"), filename);
            //newCategory.image = filename;
            //newCategory.ImageFile.SaveAs(filename);

            HttpPostedFileBase file = newCategory.ImageFile;

            if (file != null && file.ContentLength > 0)
            {
                var f = System.IO.Path.GetFileName(file.FileName);//file is null
                file.SaveAs(Server.MapPath("~/Content/" + f));
                newCategory.image = f;
            }

            categoryAppService.SaveNewCategory(newCategory);
            return(RedirectToAction("Index"));
        }
Example #2
0
        public void Test_Save_New_Category()
        {
            //Act
            var result = cat.SaveNewCategory(cat2);

            //Assert
            Assert.AreEqual(result, true);
        }