public ActionResult Create(BlogViewModel blogViewModel)
        {
            ViewBag.Title = "Tạo mới blog";
            if (ModelState.IsValid)
            {
                string fileName      = Path.GetFileName(blogViewModel.ImageFile.FileName);
                string fileExtension = Path.GetExtension(blogViewModel.ImageFile.FileName);
                fileName = Slug.CreateSlug(blogViewModel.Title) + fileExtension;

                string path = Path.Combine(Server.MapPath(Constants.BLOG_IMAGE_PATH), fileName);
                blogViewModel.ImageFile.SaveAs(path);
                var  empployeeId = db.Employees.Where(e => e.UserName.Equals(User.Identity.Name)).Select(e => e.Id).SingleOrDefault();
                Blog blog        = new Blog()
                {
                    Title       = blogViewModel.Title,
                    Description = blogViewModel.Description,
                    Priority    = blogViewModel.Priority,
                    Avatar      = Constants.BLOG_IMAGE_PATH + fileName,
                    View        = 1,
                    DatePost    = DateTime.Now,
                    EmployeeId  = empployeeId
                };
                db.Blogs.Add(blog);
                db.SaveChanges();
                return(RedirectToAction("AllBlog", "Blogs", new { area = "Admin" }));
            }
            return(View(blogViewModel));
        }
Example #2
0
            public void Slug_Should_Be_Normalized(string name)
            {
                // Given

                var page = new FakePage
                {
                    Metadata =
                    {
                        Name = name
                    }
                };

                // When

                var result = Slug.CreateSlug(page);

                //Then

                Assert.NotNull(result);
                Assert.DoesNotContain(" ", result);
                Assert.DoesNotContain("--", result);
                Assert.DoesNotContain("å", result);
                Assert.DoesNotContain("ä", result);
                Assert.DoesNotContain("ö", result);
                Assert.DoesNotContain("/", result);
            }
        public ActionResult Create(ProductViewModelAdmin productViewModel)
        {
            ViewBag.Title = "Tạo mới sản phẩm";
            if (ModelState.IsValid)
            {
                string fileName      = Path.GetFileNameWithoutExtension(productViewModel.ImageFile.FileName);
                string fileExtension = Path.GetExtension(productViewModel.ImageFile.FileName);

                fileName = Slug.CreateSlug(productViewModel.Name) + fileExtension;

                string path = Path.Combine(Server.MapPath(Constants.PRODUCT_IMAGE_PATH), fileName);
                productViewModel.ImageFile.SaveAs(path);

                Product product = new Product()
                {
                    Name          = productViewModel.Name,
                    CategoryId    = productViewModel.CategoryId,
                    Price         = productViewModel.Price,
                    Description   = productViewModel.Description,
                    StockQuantity = productViewModel.StockQuantity,
                    Views         = productViewModel.Views,
                    Priority      = productViewModel.Priority,
                    Discount      = productViewModel.Discount,
                    Status        = productViewModel.Status,
                    Avatar        = Constants.PRODUCT_IMAGE_PATH + fileName
                };

                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("AllProduct", "Products", new { area = "Admin" }));
            }
            return(View(productViewModel));
        }
        public ActionResult Edit(ProductViewModelAdmin productViewModel, int page)
        {
            var product = db.Products.Find(productViewModel.Id);

            product.Name          = productViewModel.Name;
            product.Price         = productViewModel.Price;
            product.Description   = productViewModel.Description;
            product.StockQuantity = productViewModel.StockQuantity;
            product.Views         = productViewModel.Views;
            product.Priority      = productViewModel.Priority;
            product.Discount      = productViewModel.Discount;
            product.Status        = productViewModel.Status;
            product.CategoryId    = productViewModel.CategoryId;
            if (productViewModel.ImageFile != null)
            {
                string fileName      = Path.GetFileNameWithoutExtension(productViewModel.ImageFile.FileName);
                string fileExtension = Path.GetExtension(productViewModel.ImageFile.FileName);
                fileName = Slug.CreateSlug(productViewModel.Name) + fileExtension;

                string path = Path.Combine(Server.MapPath(Constants.PRODUCT_IMAGE_PATH), fileName);
                productViewModel.ImageFile.SaveAs(path);

                product.Avatar = Constants.PRODUCT_IMAGE_PATH + fileName;
            }
            db.SaveChanges();
            return(RedirectToAction("AllProduct", "Products", new { area = "Admin", page }));
        }
Example #5
0
        public ActionResult Edit(CategoryViewModel categoryViewModel, int page)
        {
            var category = db.Categories.Find(categoryViewModel.Id);

            category.Name = categoryViewModel.Name;
            if (categoryViewModel.ImageFile != null)
            {
                string fileName      = Path.GetFileNameWithoutExtension(categoryViewModel.ImageFile.FileName);
                string fileExtension = Path.GetExtension(categoryViewModel.ImageFile.FileName);
                fileName = Slug.CreateSlug(categoryViewModel.Name) + fileExtension;

                string path = Path.Combine(Server.MapPath(Constants.CATEGORY_ICON_PATH), fileName);
                categoryViewModel.ImageFile.SaveAs(path);

                category.Avatar = Constants.CATEGORY_ICON_PATH + fileName;
            }
            db.SaveChanges();
            return(RedirectToAction("AllCategory", "Categories", new { area = "Admin" }));
        }
        public ActionResult Edit(BlogViewModel blogViewModel, int page)
        {
            var blog = db.Blogs.Find(blogViewModel.Id);

            blog.Title       = blogViewModel.Title;
            blog.Priority    = blogViewModel.Priority;
            blog.Description = blogViewModel.Description;
            if (blogViewModel.ImageFile != null)
            {
                string fileName      = Path.GetFileNameWithoutExtension(blogViewModel.ImageFile.FileName);
                string fileExtension = Path.GetExtension(blogViewModel.ImageFile.FileName);
                fileName = Slug.CreateSlug(blogViewModel.Title) + fileExtension;

                string path = Path.Combine(Server.MapPath(Constants.BLOG_IMAGE_PATH), fileName);
                blogViewModel.ImageFile.SaveAs(path);

                blog.Avatar = Constants.BLOG_IMAGE_PATH + fileName;
            }
            db.SaveChanges();
            return(RedirectToAction("AllBlog", "Blogs", new { area = "Admin", page }));
        }
Example #7
0
        public ActionResult Create(CategoryViewModel categoryViewModel)
        {
            ViewBag.Title = "Tạo mới danh mục";
            if (ModelState.IsValid)
            {
                string fileName      = Path.GetFileNameWithoutExtension(categoryViewModel.ImageFile.FileName);
                string fileExtension = Path.GetExtension(categoryViewModel.ImageFile.FileName);
                fileName = Slug.CreateSlug(categoryViewModel.Name) + fileExtension;

                string path = Path.Combine(Server.MapPath(Constants.CATEGORY_ICON_PATH), fileName);
                categoryViewModel.ImageFile.SaveAs(path);
                Category category = new Category()
                {
                    Name   = categoryViewModel.Name,
                    Avatar = Constants.CATEGORY_ICON_PATH + fileName
                };
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("AllCategory", "Categories", new { area = "Admin" }));
            }
            return(View());
        }