Beispiel #1
0
        public ActionResult Create([Bind(Include = "Id,Title,Text")] AboutShop aboutShop)
        {
            if (ModelState.IsValid)
            {
                db.AboutShops.Add(aboutShop);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(aboutShop));
        }
        public ActionResult Create([Bind(Include = "Id,Code,CreatedDate,ContactName,ContactAddress,ContactPhone,ContactEmail,ContactReceiverName,ContactReceiverAddress,ContactReceiverPhone,ContactReceiverEmail,Note,TotalPrice")] Order order)
        {
            if (ModelState.IsValid)
            {
                db.Orders.Add(order);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(order));
        }
        public ActionResult Create([Bind(Include = "Id,NameCompany,Address,Phone,Email,AddressWeb,AddressSocial")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.Add(contact);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(contact));
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "Id,ImageUrl,Name,Address,Comment")] UserComment userComment)
        {
            if (ModelState.IsValid)
            {
                db.UserComments.Add(userComment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userComment));
        }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "Id,Code,Title,ImageUrl,Source,Description,CreatedDate")] NewsService newsService)
        {
            if (ModelState.IsValid)
            {
                newsService.CreatedDate = DateTime.Now;
                db.NewsServices.Add(newsService);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(newsService));
        }
Beispiel #6
0
        public ActionResult Create([Bind(Include = "Id,CategoryId,CategoryName,Code,Name,Price,Unit,ImageUrl,Description,Size,Discount,DisplayPosition,Status,CreatedDate,SortOrder")] Product product)
        {
            if (ModelState.IsValid)
            {
                product.CreatedDate = DateTime.Now;
                //product.ImageUrl = "#";
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CategoryId   = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
            ViewBag.CategoryName = new SelectList(db.Categories, "Name", "Name", product.CategoryName);

            return(View(product));
        }
Beispiel #7
0
        public ActionResult DeleteProductImage(int deleteId)
        {
            using (var db = new ShopSellDb())
            {
                var item = db.ProductImages.Find(deleteId);

                if (item != null)
                {
                    // XÓA HÌNH
                    var pathToDetele = Server.MapPath(item.ImageUrl);
                    if (System.IO.File.Exists(pathToDetele))
                    {
                        System.IO.File.Delete(pathToDetele);
                    }

                    // XÓA TRONG DATABASE
                    var productId = item.ProductId;
                    db.ProductImages.Remove(item);
                    db.SaveChanges();

                    return(RedirectToAction("UploadDetailsImages", "ManageProducts", new { id = productId }));
                }

                return(HttpNotFound());
            }
        }
        public ActionResult Create([Bind(Include = "Id,ParentId,ParentLevel,Name,SortOrder,Status")] Category category)
        {
            if (ModelState.IsValid)
            {
                if (category.ParentId == 0)
                {
                    category.ParentLevel = 1;
                }
                else
                {
                    category.ParentLevel = 2;
                };
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            // BEGIN: Tạo ra dropdownlist cho trường Status
            var statusItems = new[]
            {
                new { Id = "ACTIVE", Name = "Active" },
                new { Id = "DEACTIVE", Name = "Deactive" },
            };

            ViewBag.Status = new SelectList(statusItems, "Id", "Name");
            // END: Tạo ra dropdownlist cho trường Status

            // BEGIN: Tạo ra dropdownlist cho trường ParentId
            var categories = db.Categories.Where(x => x.ParentId == 0).ToList();
            //var categories = db.Categories.ToList();

            var root = new Category();

            root.Id   = 0;
            root.Name = "Tạo mới";

            categories.Add(root);

            ViewBag.ParentId = new SelectList(categories, "Id", "Name");
            // END: Tạo ra dropdownlist cho trường ParentId

            return(View(category));
        }
Beispiel #9
0
        public IHttpActionResult PostOrder(Order order)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Orders.Add(order);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = order.Id }, order));
        }
Beispiel #10
0
        public ActionResult DeleteConfirmed(int id)
        {
            using (var db = new ShopSellDb())
            {
                var item = db.NewsServices.Find(id);
                if (item != null)
                {
                    // XÓA HÌNH
                    var pathToDetele = Server.MapPath(item.ImageUrl);
                    if (System.IO.File.Exists(pathToDetele))
                    {
                        System.IO.File.Delete(pathToDetele);
                    }
                }
            }

            NewsService newsService = db.NewsServices.Find(id);

            db.NewsServices.Remove(newsService);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }