public async Task <IActionResult> Create([Bind("NroCancha,NombreCancha,Habilitada,Importe")] Cancha cancha)
        {
            if (ModelState.IsValid)
            {
                if (!_context.Cancha.Any(a => a.NombreCancha == cancha.NombreCancha))
                {
                    if (cancha.Importe > 0)
                    {
                        _context.Add(cancha);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        ModelState.AddModelError("", "El importe debe ser positivo");
                        return(View());
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Ya existe una cancha con ese nombre");
                    return(View());
                }
            }
            return(View(cancha));
        }
        public async Task <IActionResult> Edit(string id, [Bind("Email,Contraseña,Nombre,Puntos")] Cliente cliente)
        {
            if (id != cliente.Email)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(cliente);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClienteExists(cliente.Email))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Details), "Perfiles1", new { id }));
            }
            return(View(cliente));
        }
Exemple #3
0
        public async Task <IActionResult> PutProductos([FromRoute] int id, [FromBody] Productos productos)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != productos.Id)
            {
                return(BadRequest());
            }

            _context.Entry(productos).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutDepartamento([FromRoute] int id, [FromBody] DepartamentoDTO departamento)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != departamento.Id)
            {
                return(BadRequest());
            }

            _context.Entry(Mapper.Map <Departamento>(departamento)).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepartamentoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("Id,SaleDate,PaidFull")] Sale sale)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sale);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sale));
        }
Exemple #6
0
        public async Task <IActionResult> Create([Bind("ClienteId,Nome,TipoCliente,Documento,DataCadastro,Telefone")] Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cliente);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cliente));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Lastname,DateSet,Phone")] Client client)
        {
            if (ModelState.IsValid)
            {
                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
Exemple #8
0
        public async Task <IActionResult> Create([Bind("Id,Make,FuelType,Aspiration,NumDoors,BodyStyle,DriveWheels,EngineLocation,WheelBase,Length,Width,Height,CurbWeight,EngineType,NumCylinders,EngineSize,FuelSystem,Bore,Stroke,CompressionRatio,Horsepower,PeakRpm,CityMpg,HighwayMpg,Price")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicle);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicle));
        }
Exemple #9
0
        public async Task <IActionResult> Agregar(Usuario usuario)
        {
            var addUsuario = context.Add(usuario);
            await context.SaveChangesAsync();

            return(Ok(addUsuario));
        }
        public async Task <IActionResult> Edit(string id, [Bind("Email,Contraseña,Nombre,Puntos")] Cliente cliente)
        {
            if (id != cliente.Email)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                using (var db = new EmpresaContext())
                {
                    try
                    {
                        Cliente aux = db.Cliente.Find(id);
                        aux.Contraseña = cliente.Contraseña;
                        aux.Nombre     = cliente.Nombre;

                        //db.Update(cliente);
                        await db.SaveChangesAsync();
                    }
                    catch (Exception)
                    {
                    }
                }
                return(RedirectToAction("Acceder", "Home"));
            }
            return(View(cliente));
        }
Exemple #11
0
        public async Task <IActionResult> Create([Bind("NroTurno,EmailCliente,NroCancha,FechaHora")] Turno turno)
        {
            //turno.EmailCliente = (string)ViewData["EmailUsuario"];
            if (ModelState.IsValid)
            {
                try
                {
                    Cancha c = _context.Cancha.Find(turno.NroCancha);
                    if (c.Habilitada)
                    {
                        if (TurnoDisponible(turno))
                        {
                            _context.Add(turno);
                            Cliente cli = _context.Cliente.Find(turno.EmailCliente);
                            cli.Puntos += 100;
                            await _context.SaveChangesAsync();

                            /* return RedirectToAction(nameof(Index), "Usuarios1", new { turno.EmailCliente }, "")*/;
                            //return RedirectToAction(nameof(Index), "Usuarios1", ViewData["EmailUsuario"]);

                            ModelState.AddModelError("", "Reserva realizada con éxito");
                        }
                        else
                        {
                            ModelState.AddModelError("", "El turno no está disponible");
                            ViewData["EmailCliente"] = new SelectList(_context.Cliente, "Email", "Email", turno.EmailCliente);
                            ViewData["NroCancha"]    = new SelectList(_context.Cancha, "NroCancha", "NombreCancha", turno.NroCancha);
                            return(View());
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Cancha Inhabilitada");
                        ViewData["EmailCliente"] = new SelectList(_context.Cliente, "Email", "Email", turno.EmailCliente);
                        ViewData["NroCancha"]    = new SelectList(_context.Cancha, "NroCancha", "NombreCancha", turno.NroCancha);
                        return(View());
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            ViewData["EmailCliente"] = new SelectList(_context.Cliente, "Email", "Email", turno.EmailCliente);
            ViewData["NroCancha"]    = new SelectList(_context.Cancha, "NroCancha", "NombreCancha", turno.NroCancha);
            return(View(turno));
        }
 public async Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt)
 {
     //Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction():
     //See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
     await ResilientTransaction.New(_empresaContext)
     .ExecuteAsync(async() => {
         // Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction
         await _empresaContext.SaveChangesAsync();
         await _eventLogService.SaveEventAsync(evt, _empresaContext.Database.CurrentTransaction.GetDbTransaction());
     });
 }
        public async Task <IActionResult> Edit([Bind("Id,nome,CNPJ,telefone,email,endereco,numero,cidade,bairro,senha")] Empresa empresa)
        {
            int id       = Ok;
            var empresas = await _context.Empresas.FirstOrDefaultAsync(e => (e.email == empresa.email || e.CNPJ == empresa.CNPJ) && e.Id != id);

            if (empresas != null)
            {
                ViewBag.Erro = "Email ou CNPJ já cadastrado!";
            }
            else
            {
                if (id != empresa.Id)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(empresa);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!EmpresaExists(empresa.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(UserPage)));
                }
            }
            return(View(empresa));
        }
Exemple #14
0
 public async Task <int> SaveChanges()
 {
     return(await Db.SaveChangesAsync());
 }