예제 #1
0
        public ActionResult Create([Bind(Include = "id,description,price,discount,category_id,image,sort_id,status")] Product product, ImageProduct imageproduct, IEnumerable <HttpPostedFileBase> files)
        {
            string images = "";

            if (ModelState.IsValid)
            {
                foreach (var file in files)
                {
                    if (file.ContentLength >= 0)
                    {
                        images += file.FileName + ",";
                    }
                }
                product.date            = DateTime.Now;
                product.image           = images.Split(',')[0];
                imageproduct.product_id = product.id;
                imageproduct.image      = images.Substring(0, images.Length - 1);
                db.ImageProducts.Add(imageproduct);
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.category_id = new SelectList(db.Categories, "id", "name", product.category_id);
            return(View(product));
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "id,name,address,phone,email,department_id")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
예제 #3
0
        [ValidateAntiForgeryToken]//tranh hacker xam nhap
        public async Task <ActionResult> Register(CustomerRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //Luu thong tin dang ky vao table customer
                    Customer cus = new Customer
                    {
                        name    = model.Name,
                        address = model.Address,
                        phone   = model.Phone,
                        email   = model.Email,
                        user_id = user.Id
                    };
                    db.Customers.Add(cus);
                    db.SaveChanges();
                    //gan vai tro customer cho user vua dang ky
                    await UserManager.AddToRoleAsync(user.Id, "customer");

                    //Login
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    //Redict về Homepage
                    return(RedirectToAction("Index", "Store"));
                }
                AddErrors(result);
            }
            return(View(model));
        }
예제 #4
0
        public ActionResult Create([Bind(Include = "id,name,image,parent_id,sort_id,status")] Category category, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                //Luu hinh vao csdl
                if (file != null)
                {
                    category.image = file.FileName;
                    db.Categories.Add(category);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
예제 #5
0
        public ActionResult Update(int id, string status, string filter)
        {
            Order order = db.Orders.Find(id);

            order.status = status;
            db.SaveChanges();
            return(RedirectToAction("Index", new { filter }));
        }
예제 #6
0
        public ActionResult CheckOut()
        {
            Order         order = null;
            SHOESEntities db    = new SHOESEntities();

            using (var tran = db.Database.BeginTransaction())
            {
                try
                {
                    string   user_id  = User.Identity.GetUserId();
                    Customer customer = db.Customers.Where(c => c.user_id == user_id).First();
                    Employee employee = db.Employees.Find(1);
                    order = new Order
                    {
                        date     = DateTime.Now,
                        status   = "New",
                        Customer = customer,
                        Employee = employee
                    };
                    db.Orders.Add(order);
                    IList <Item> items = Cart.Items;
                    foreach (var item in items)
                    {
                        Product     product     = db.Products.Find(item.ID);
                        OrderDetail orderdetail = new OrderDetail
                        {
                            order_id = order.id,
                            Product  = product,
                            quantity = item.Quantity,
                            price    = item.Price,
                            discount = item.Discount
                        };
                        db.OrderDetails.Add(orderdetail);
                    }
                    db.SaveChanges();
                    Cart.Empty();
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw ex;
                }
            }
            return(View(order));
        }