Exemplo n.º 1
0
 public ActionResult Create(News news)
 {
     if (ModelState.IsValid)
     {
         using (var scope = new TransactionScope())
         {
             if (Request.Files["ImageFile"] != null && Request.Files["ImageFile"].ContentLength < 2097152)
             {
                 string extension = Path.GetExtension(Request.Files["ImageFile"].FileName);
                 string fileName  = RandomString(5, true) + DateTime.Now.ToString("yymmssfff") + extension;
                 news.Image = "/Assets/Admin/img/news/" + fileName;
                 fileName   = Path.Combine(Server.MapPath("/Assets/Admin/img/news/"), fileName);
                 Request.Files["ImageFile"].SaveAs(fileName);
                 db.News.Add(news);
                 db.SaveChanges();
                 scope.Complete();
                 TempData["message"] = "Tạo Tin Tức thành công.";
                 return(RedirectToAction("Index"));
             }
             else
             {
                 ModelState.AddModelError("Image", "Chưa có hình tin tức hoặc hình ảnh lớn hơn 2MB!");
             }
         }
     }
     return(View(news));
 }
Exemplo n.º 2
0
 public ActionResult Create(Product product)
 {
     CheckValidationProduct(product);
     if (ModelState.IsValid)
     {
         using (var scope = new TransactionScope())
         {
             if (Request.Files["ImageFile"] != null && Request.Files["ImageFile"].ContentLength < 2097152)
             {
                 //string fileName = Path.GetFileNameWithoutExtension(product.ImageFile.FileName);
                 string extension = Path.GetExtension(Request.Files["ImageFile"].FileName);
                 string fileName  = RandomString(5, true) + DateTime.Now.ToString("yymmssfff") + extension;
                 product.Avatar = "/Assets/Admin/img/products/" + fileName;
                 fileName       = Path.Combine(Server.MapPath("/Assets/Admin/img/products/"), fileName);
                 Request.Files["ImageFile"].SaveAs(fileName);
                 db.Products.Add(product);
                 db.SaveChanges();
                 scope.Complete();
                 TempData["message"] = "Tạo sản phẩm thành công.";
                 return(RedirectToAction("Index"));
             }
             else
             {
                 ModelState.AddModelError("Avatar", "Chưa có hình sản phẩm hoặc hình ảnh lớn hơn 2MB!");
             }
         }
     }
     ViewBag.ProductTypeID = new SelectList(db.ProductTypes, "ID", "ProductTypeName", product.ProductTypeID);
     return(View(product));
 }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "ID,Fullname,Email,Phone,Title,Comment")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.Add(contact);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(contact));
        }
Exemplo n.º 4
0
 public ActionResult Edit(InstallmentBillDetail installmentBillDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(installmentBillDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BillID    = new SelectList(db.InstallmentBills, "ID", "BillCode", installmentBillDetail.BillID);
     ViewBag.ProductID = new SelectList(db.Products, "ID", "ProductCode", installmentBillDetail.ProductID);
     return(View(installmentBillDetail));
 }
Exemplo n.º 5
0
        public ActionResult Create(ProductType productType)
        {
            checkValidatorProductType(productType);
            if (ModelState.IsValid)
            {
                db.ProductTypes.Add(productType);
                db.SaveChanges();
                TempData["message"] = "Tạo loại sản phẩm thành công.";
                return(RedirectToAction("Index"));
            }

            return(View(productType));
        }
Exemplo n.º 6
0
        public void DeleteTest()
        {
            var db      = new DmQT03Entities();
            var contact = new Contact
            {
                Title    = "Title",
                Email    = "*****@*****.**",
                Fullname = "Nguyen Van A",
                Phone    = 013456789,
                Comment  = "Hello"
            };

            var controller = new ContactsController();
            var context    = new Mock <HttpContextBase>();
            var session    = new Mock <HttpSessionStateBase>();

            session.Setup(s => s["UserName"]).Returns("abc");
            context.Setup(c => c.Session).Returns(session.Object);
            controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);

            using (var scope = new TransactionScope())
            {
                db.Contacts.Add(contact);
                db.SaveChanges();
                var count   = db.Contacts.Count();
                var result2 = controller.DeleteConfirmed(contact.ID) as RedirectToRouteResult;
                Assert.IsNotNull(result2);
                Assert.AreEqual(count - 1, db.Contacts.Count());
            }
        }
Exemplo n.º 7
0
        public void DeleteTest()
        {
            var db          = new DmQT03Entities();
            var productType = new ProductType
            {
                ProductTypeName = "ProductName",
                ProductTypeCode = "123",
            };

            var controller = new ProductTypesController();
            var context    = new Mock <HttpContextBase>();
            var session    = new Mock <HttpSessionStateBase>();

            session.Setup(s => s["UserName"]).Returns("abc");
            context.Setup(c => c.Session).Returns(session.Object);
            controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);

            using (var scope = new TransactionScope())
            {
                db.ProductTypes.Add(productType);
                db.SaveChanges();
                var count   = db.ProductTypes.Count();
                var result2 = controller.DeleteConfirmed(productType.ID) as RedirectToRouteResult;
                Assert.IsNotNull(result2);
                Assert.AreEqual(count - 1, db.ProductTypes.Count());
            }
        }
Exemplo n.º 8
0
        public ActionResult LienHe(Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.Add(contact);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(contact));
        }
Exemplo n.º 9
0
 public ActionResult Index(Introduction introduction)
 {
     if (ModelState.IsValid)
     {
         introduction.ID = 1;
         db.Entry(introduction).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(introduction));
 }
Exemplo n.º 10
0
        public ActionResult Create2()
        {
            using (var scope = new TransactionScope())
                try
                {
                    var cashBill = Session["CashBill"] as CashBill;
                    var CTHoaDon = Session["CashBillDetail"] as List <CashBillDetail>;
                    cashBill.Date       = DateTime.Now;
                    cashBill.GrandTotal = (int)Session["total"];

                    db.CashBills.Add(cashBill);
                    db.SaveChanges();

                    foreach (var chiTiet in CTHoaDon)
                    {
                        chiTiet.BillID  = cashBill.ID;
                        chiTiet.Product = null;
                        db.CashBillDetails.Add(chiTiet);
                    }
                    db.SaveChanges();
                    scope.Complete();

                    Session["CashBill"]       = null;
                    Session["CashBillDetail"] = null;
                    Session["total"]          = null;
                    TempData["message"]       = "Tạo hóa đơn thành công.";
                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", e.Message);
                }
            return(View("Create"));
        }