public ActionResult OrdenarEnLinea(int id)
        {
            var producto = repository.Productos.Where(p => p.ProductoId == id).FirstOrDefault();
            ViewData["selectedProduct"] = producto;

            var newOrder = new Orden();
            newOrder.Ordenado = DateTime.Today;
            //newOrder.Cliente = new Cliente();  { Nombre = "", Apellido = "", Direccion = "", Email = "", Telefono = "" };
            newOrder.Producto = producto;

            return View(newOrder);
        }
        public ActionResult OrdenarEnLinea(FormCollection collection)
        {
            var email = collection["Cliente.Email"].ToString();
            ViewData["finished"] = true;
            Cliente clienteModel = new Cliente();

            if (repository.Clientes.Where(p => p.Email == email).Any())
            {
                clienteModel = repository.Clientes.Where(p => p.Email == email).First();
            }

            var createdOrder = new Orden();

            if (clienteModel.ClienteId != 0)
            {
                try
                {
                    createdOrder.ClienteClienteId = clienteModel.ClienteId;
                    createdOrder.ProductoProductoId = Convert.ToInt32(collection["Producto.ProductoId"].ToString());

                    //TryUpdateModel(createdOrder, new string[] { "Cantidad", "Ordenado" }, collection.ToValueProvider());

                    createdOrder.Cantidad = Convert.ToInt32(collection["Cantidad"].ToString());
                    createdOrder.Ordenado = DateTime.Parse(collection["Ordenado"].ToString());

                    // Validate

                    if (String.IsNullOrEmpty(clienteModel.Nombre.ToString()))
                        ModelState.AddModelError("Nombre", "El Nombre es Requerido");

                    repository.GuardarOrden(createdOrder);

                    if (ModelState.IsValid)
                    {
                        repository.SaveDB();
                        return RedirectToAction("Index");
                    }

                }
                catch
                {
                    return View();
                }
            }
            else
            {
                try
                {
                    clienteModel.Nombre = collection["Cliente.Nombre"].ToString();
                    clienteModel.Apellido = collection["Cliente.Apellido"].ToString();
                    clienteModel.Direccion = collection["Cliente.Direccion"].ToString();
                    clienteModel.Email = collection["Cliente.Email"].ToString();
                    clienteModel.Telefono = collection["Cliente.Telefono"].ToString();

                    repository.SaveClient(clienteModel);

                    createdOrder.ClienteClienteId = repository.Clientes.Where(c => c.Email == clienteModel.Email).First().ClienteId;
                    createdOrder.ProductoProductoId = Convert.ToInt32(collection["Producto.ProductoId"].ToString());

                    //TryUpdateModel(createdOrder, new string[] { "Cantidad", "Ordenado" }, collection.ToValueProvider());

                    createdOrder.Cantidad = Convert.ToInt32(collection["Cantidad"].ToString());
                    createdOrder.Ordenado = DateTime.Parse(collection["Ordenado"].ToString());

                    repository.GuardarOrden(createdOrder);
                }
                catch
                {

                }
            }

            return View("OrdenFinalizada");
        }
 /// <summary>
 /// Create a new Orden object.
 /// </summary>
 /// <param name="ordenId">Initial value of the OrdenId property.</param>
 /// <param name="cantidad">Initial value of the Cantidad property.</param>
 /// <param name="ordenado">Initial value of the Ordenado property.</param>
 /// <param name="clienteClienteId">Initial value of the ClienteClienteId property.</param>
 /// <param name="productoProductoId">Initial value of the ProductoProductoId property.</param>
 public static Orden CreateOrden(global::System.Int32 ordenId, global::System.Int32 cantidad, global::System.DateTime ordenado, global::System.Int32 clienteClienteId, global::System.Int32 productoProductoId)
 {
     Orden orden = new Orden();
     orden.OrdenId = ordenId;
     orden.Cantidad = cantidad;
     orden.Ordenado = ordenado;
     orden.ClienteClienteId = clienteClienteId;
     orden.ProductoProductoId = productoProductoId;
     return orden;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Ordenes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrdenes(Orden orden)
 {
     base.AddObject("Ordenes", orden);
 }
Esempio n. 5
0
        public void GuardarOrden(Orden orden)
        {
            var product = Productos.Where(p => p.ProductoId == orden.ProductoProductoId).FirstOrDefault();
            var ingredientes = product.Ingredientes;
            var docenas = orden.Cantidad;

            foreach(var ingredient in ingredientes)
            {
                var totalInventario = ingredient.Cantidad*docenas;
                ingredient.Inventario.CantidadTotal -= totalInventario;
            }

            entity.AddToOrdenes(orden);
            entity.SaveChanges();
        }