Example #1
0
        public ActionResult Create([Bind(Include = "ID,Username,Password,Fullname,Birthday,Sex,PhoneNumber,Email,Address,Permission,Active")] Account account)
        {
            if (ModelState.IsValid)
            {
                db.Account.Add(account);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(account));
        }
Example #2
0
        public ActionResult Create([Bind(Include = "ID,Name,Active")] NewsType newsType)
        {
            if (ModelState.IsValid)
            {
                db.NewType.Add(newsType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(newsType));
        }
        public ActionResult Create([Bind(Include = "ID,Name,Images")] Producer producer)
        {
            if (ModelState.IsValid)
            {
                db.Producer.Add(producer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(producer));
        }
Example #4
0
        public ActionResult Create([Bind(Include = "ID,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Category.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Example #5
0
        public ActionResult Create([Bind(Include = "ID,Title,IsPublic,Content,Author,CreatedDate,NewsTypeID")] New @new)
        {
            if (ModelState.IsValid)
            {
                db.New.Add(@new);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.NewsTypeID = new SelectList(db.NewType, "ID", "Name", @new.NewsTypeID);
            return(View(@new));
        }
        public ActionResult Create([Bind(Include = "ID,Discount,Begin,End,ProductID")] Sale sale)
        {
            if (ModelState.IsValid)
            {
                db.Sale.Add(sale);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductID = new SelectList(db.Product, "ID", "Name", sale.ProductID);
            return(View(sale));
        }
Example #7
0
        //[CaptchaValidation("CaptchaCode", "registerCaptcha", "Mã xác nhập không đúng!")]
        public ActionResult ChangePassword(UserModel userModel)
        {
            Account acc = new Account();

            if (ModelState.IsValid)
            {
                var user = db.Account.SingleOrDefault(a => a.Username == userModel.Username);
                if (user != null)
                {
                    if (user.Password == userModel.Password)   //nếu đúng pass của tài khoản mới cập nhập
                    {
                        user.Password = userModel.NewPassword; //Hàm cập nhập mật khẩu
                        db.SaveChanges();
                        TempData["Success"] = "Đổi mật khẩu thành công";
                        return(RedirectToAction("Index", "Product"));
                    }
                    else
                    {
                        TempData["Error"] = "Mật khẩu cũ không đúng";
                        return(View());
                    }
                }
            }
            TempData["Error2"] = "Đổi mật khẩu thất bại";
            return(View());
        }
 //[ValidateAntiForgeryToken]
 public ActionResult Edit(FormCollection formcollection)
 {
     if (ModelState.IsValid)
     {
         var lstID = formcollection["ID"].ToString().Split(new char[] { ',' });
         foreach (var id in lstID)
         {
             var bill = db.Bill.Find(int.Parse(id));
             if (bill.Status == "Đã hủy")
             {
                 ViewBag.Errorstatus = "Không thể chuyển từ đã hủy sang trạng thái khác";
                 return(RedirectToAction("Index"));
             }
             bill.Status          = formcollection["Status"];
             db.Entry(bill).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     //ViewBag.AccountID = new SelectList(db.Account, "ID", "Username", bill.AccountID);
     return(RedirectToAction("Index"));
 }
Example #9
0
        //Insert order
        public bool Create(BillDetails billDetail)
        {
            try
            {
                //giảm số lượng khi đặt sản phẩm
                var product = dt.Product.Find(billDetail.ProductID);
                product.Quantity = product.Quantity - billDetail.Amount;
                dt.BillDetail.Add(billDetail);
                dt.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
Example #10
0
        public long Create(Account acc)
        {
            var check = user.Account.SingleOrDefault(x => x.Username == acc.Username);

            if (check == null)
            {
                acc.Permission = "Khách hàng";
                acc.Active     = "Kích hoạt";
                //  code kierm tra loi EntityValidate lỗi ràng buỗjc
                try
                {
                    user.Account.Add(acc);
                    user.SaveChanges();
                    // code của bạn
                }
                catch (DbEntityValidationException ex)
                {
                    // Retrieve the error messages as a list of strings.
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage);

                    // Join the list to a single string.
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }


                return(1);
            }

            else
            {
                return(-1);
            }
        }
        public ActionResult Create([Bind(Include = "ID,Name,ProducerID,CategoryID,Price,IMG,Quantity,Description,TopHot,NewProduct,Active")] Product product, int?sale, DateTime?beginDate, DateTime?endDate)
        {
            if (ModelState.IsValid)
            {
                if (sale != null)
                {
                    var sales = new Sale();
                    sales.Discount  = sale;
                    sales.ProductID = product.ID;
                    if (beginDate == null || endDate == null)
                    {
                        ViewBag.DateSale   = "Nếu bạn đã nhập khuyến mại thì bạn phải nhập cả ngày bắt đầu và kết thúc!";
                        ViewBag.CategoryID = new SelectList(db.Category, "ID", "Name", product.CategoryID);
                        ViewBag.ProducerID = new SelectList(db.Producer, "ID", "Name", product.ProducerID);
                        return(View(product));
                    }
                    else
                    {
                        db.Product.Add(product);
                        db.SaveChanges();
                        sales.Begin = (DateTime)beginDate;
                        sales.End   = (DateTime)endDate;
                        db.Sale.Add(sales);
                        db.SaveChanges();
                    }
                }
                else
                {
                    db.Product.Add(product);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryID = new SelectList(db.Category, "ID", "Name", product.CategoryID);
            ViewBag.ProducerID = new SelectList(db.Producer, "ID", "Name", product.ProducerID);
            return(View(product));
        }
Example #12
0
 public long Create(Bill order)
 {
     bill.Bill.Add(order);
     bill.SaveChanges();
     return(order.ID);
 }
Example #13
0
 public ActionResult CustomerDetailsForm(CustomerDetails Customer)
 {
     _context.Add(Customer);
     _context.SaveChanges();
     return(View());
 }