public ActionResult Create([Bind(Include = "DocumentypeID,Description")] DocumentType documentType)
        {
            if (ModelState.IsValid)
            {
                db.DocumentTypes.Add(documentType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(documentType));
        }
示例#2
0
        public ActionResult Create([Bind(Include = "ProductID,Descripcion,price,lastbuy,Stock,Remarks")] Products products)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(products);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(products));
        }
示例#3
0
        public ActionResult Create([Bind(Include = "SupplierID,Name,ContactFirtsName,ContactLastName,Phone,Address,Email")] Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                db.Suppliers.Add(supplier);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(supplier));
        }
示例#4
0
        public ActionResult Create([Bind(Include = "EmployeeID,FirtsName,LastName,Salary,BonusPercent,DateOfBirth,Startiem,Email,Url,DocumentypeID")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DocumentypeID = new SelectList(db.DocumentTypes, "DocumentypeID", "Description", employee.DocumentypeID);
            return(View(employee));
        }
        public ActionResult Create([Bind(Include = "CustomerID,Firtsname,ContactLastName,Phone,Address,Email,Document,DocumentypeID")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }


            ViewBag.DocumentypeID = new SelectList(db.DocumentTypes.OrderBy(x => x.Description), "DocumentypeID", "Description", customer.DocumentypeID);
            return(View(customer));
        }
示例#6
0
        public ActionResult NewOrder(OrderView orderview)
        {
            orderview = Session["orderview"] as OrderView;
            var customerid = int.Parse(Request["CustomerID"]);

            if (customerid == 0)
            {
                var lista = DATABASE.Customers.ToList();
                lista.Add(new Customer {
                    CustomerID = 0, Firtsname = "[Seleccione un cliente...]"
                });
                lista.OrderBy(x => x.Fullname).ToList();
                ViewBag.CustomerID = new SelectList(lista, "CustomerID", "Fullname");
                ViewBag.Error      = "Debe seleccionar un cliente";
                return(View(orderview));
            }

            var customer = DATABASE.Customers.Find(customerid);

            if (customer == null)
            {
                var list = DATABASE.Customers.ToList();
                list.Add(new Customer {
                    CustomerID = 0, Firtsname = "[Seleccione un cliente...]"
                });
                list.OrderBy(x => x.Fullname).ToList();
                ViewBag.CustomerID = new SelectList(list, "CustomerID", "Fullname");

                ViewBag.Error = "Cliente no existe";
                return(View(orderview));
            }

            if (orderview.Products.Count == 0)
            {
                var list = DATABASE.Customers.ToList();
                list.Add(new Customer {
                    CustomerID = 0, Firtsname = "[Seleccione un cliente...]"
                });
                list.OrderBy(x => x.Fullname).ToList();
                ViewBag.CustomerID = new SelectList(list, "CustomerID", "Fullname");

                ViewBag.Error = "Debe ingresar el detalle";

                return(View(orderview));
            }
            int orderid = 0;

            using (var transation = DATABASE.Database.BeginTransaction())
            {
                try
                {
                    var order = new Order
                    {
                        CustomerID  = customerid,
                        DateOrder   = DateTime.Now,
                        OrderStatus = OrderStatus.Created,
                    };

                    DATABASE.Orders.Add(order);
                    DATABASE.SaveChanges();
                    orderid = DATABASE.Orders.ToList().Select(x => x.OrderID).Max();
                    foreach (var item in orderview.Products)
                    {
                        var OrderDetails = new OrderDetail
                        {
                            Descripcion = item.Descripcion,

                            price    = item.price,
                            Quantity = item.Quantity,
                            OrderID  = orderid,

                            ProductID = item.ProductID
                        };

                        DATABASE.OrderDetails.Add(OrderDetails);
                        DATABASE.SaveChanges();
                    }
                    transation.Commit();
                }
                catch (Exception ex)
                {
                    transation.Rollback();
                    ViewBag.Error = "Error" + ex.ToString();
                    return(View(orderview));
                }
            }

            var cs = DATABASE.Customers.ToList();

            cs.Add(new Customer {
                CustomerID = 0, Firtsname = "[Seleccione un cliente...]"
            });
            cs.OrderBy(x => x.Fullname).ToList();
            ViewBag.CustomerID = new SelectList(cs, "CustomerID", "Fullname");

            ViewBag.Message      = String.Format("La ordern:{0}, grabada ok", orderid);
            orderview            = new OrderView();
            orderview.Customer   = new Customer();
            orderview.Products   = new List <ProductOrder>();
            Session["orderview"] = orderview;
            return(View(orderview));
        }