Ejemplo n.º 1
0
        public ActionResult AddOder(Order order)
        {
            Customer customer = db.Customers.Find(1);
            Customer cus      = new Customer();

            cus.username        = customer.username;
            cus.password        = customer.password;
            cus.customerName    = order.customerName;
            cus.customerEmail   = customer.customerEmail;
            cus.customerAddress = order.customerAddress;
            cus.customerPhone   = order.customerPhone;
            cus.createAt        = DateTime.Now;
            db.Customers.Add(cus);
            db.SaveChanges();

            Product product = db.Products.Find(Session["pro"]);

            order.createAt   = DateTime.Now;
            order.customerId = cus.customerId;
            order.employeeId = 1;
            order.totalPrice = product.productPrice;
            db.Orders.Add(order);
            db.SaveChanges();

            OrderDetail orderDetail = new OrderDetail();

            orderDetail.productId = product.productId;
            orderDetail.quantity  = 1;
            orderDetail.price     = product.productPrice;
            orderDetail.orderId   = order.orderId;
            db.OrderDetails.Add(orderDetail);
            db.SaveChanges();
            Session["pro"] = 0;
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
 public ActionResult CreateProduct(Product product)
 {
     if (ModelState.IsValid)
     {
         product.createAt = DateTime.Now;
         db.Products.Add(product);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
        public ActionResult Create([Bind(Include = "id,typeId,name,image,detail,price")] Cake cake)
        {
            if (ModelState.IsValid)
            {
                db.Cakes.Add(cake);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.typeId = new SelectList(db.Types, "id", "name", cake.typeId);
            return(View(cake));
        }
Ejemplo n.º 4
0
        public static void Seed(CakeContext context)
        {
            context.Database.Migrate();

            if (!context.Cakes.Any())
            {
                context.Cakes.AddRange(GetPreConfigureCakes());

                context.SaveChanges();
            }
        }