Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Nombre,Descripcion")] Categoria categoria)
        {
            if (ModelState.IsValid)
            {
                categoria.Id = Guid.NewGuid();
                _context.Add(categoria);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(categoria));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Nombre,Telefono,Direccion,Email")] Sucursal sucursal)
        {
            if (ModelState.IsValid)
            {
                sucursal.Id = Guid.NewGuid();
                _context.Add(sucursal);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sucursal));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Nombre,Apellido,Telefono,Direccion,Email,Username,FechaAlta")] Empleado empleado)
        {
            if (ModelState.IsValid)
            {
                empleado.Id = Guid.NewGuid();
                _context.Add(empleado);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(empleado));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,Nombre,Descripcion,PrecioVigente,Activo,CategoriaId")] Producto producto)
        {
            if (ModelState.IsValid)
            {
                producto.Id = Guid.NewGuid();
                _context.Add(producto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoriaId"] = new SelectList(_context.Categorias, "Id", "Descripcion", producto.CategoriaId);
            return(View(producto));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,Activo,ClienteId,Subtotal")] Carrito carrito)
        {
            if (ModelState.IsValid)
            {
                carrito.Id = Guid.NewGuid();
                _context.Add(carrito);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClienteId"] = new SelectList(_context.Clientes, "Id", "Apellido", carrito.ClienteId);
            return(View(carrito));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Id,SucursalId,ProductoId,Cantidad")] StockItem stockItem)
        {
            if (ModelState.IsValid)
            {
                stockItem.Id = Guid.NewGuid();
                _context.Add(stockItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductoId"] = new SelectList(_context.Productos, "Id", "Descripcion", stockItem.ProductoId);
            ViewData["SucursalId"] = new SelectList(_context.Sucursal, "Id", "Direccion", stockItem.SucursalId);
            return(View(stockItem));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("Id,CarritoId,ProductoId,ValorUnitario,Cantidad,Subtotal")] CarritoItem carritoItem)
        {
            if (ModelState.IsValid)
            {
                carritoItem.Id = Guid.NewGuid();
                _context.Add(carritoItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarritoId"]  = new SelectList(_context.Carritos, "Id", "Id", carritoItem.CarritoId);
            ViewData["ProductoId"] = new SelectList(_context.Productos, "Id", "Descripcion", carritoItem.ProductoId);
            return(View(carritoItem));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("Id,Total,ClienteId,CarritoId")] Compra compra)
        {
            if (ModelState.IsValid)
            {
                compra.Id = Guid.NewGuid();
                _context.Add(compra);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarritoId"] = new SelectList(_context.Carritos, "Id", "Id", compra.CarritoId);
            ViewData["ClienteId"] = new SelectList(_context.Clientes, "Id", "Apellido", compra.ClienteId);
            return(View(compra));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Create(Cliente cliente)
        {
            if (_context.Clientes.Any(c => c.Username == cliente.Username))
            {
                ModelState.AddModelError(nameof(cliente.Username), "El Nombre de Usuario ya existe");
            }

            if (_context.Clientes.Any(c => c.Email == cliente.Email))
            {
                ModelState.AddModelError(nameof(cliente.Email), "El Email ya existe");
            }


            // SI LOS ATRIBUTOS REQUERIDOS SON CORRECTOS Y SI NO TIENEN NINGUN MODEL ERROR AGREGADO =TRUE
            if (ModelState.IsValid)
            {
                cliente.Id        = Guid.NewGuid();
                cliente.FechaAlta = DateTime.Now;
                _context.Add(cliente);


                //El carrito se crea automáticamente en estado activo con la creación de un cliente
                //(todo cliente tendrá un carrito en estado activo cuando éste sea creado).

                Carrito carrito = new Carrito()// id - activo - clienteId - subtotal
                {
                    Id        = Guid.NewGuid(),
                    Activo    = true,
                    ClienteId = cliente.Id,
                    Subtotal  = 0
                };
                _context.Add(carrito);

                await _context.SaveChangesAsync(); // guardames los cambios

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cliente));
        }