public IActionResult AdicionarProduto([FromBody] Produtos p)
        {
            try
            {
                var context = new postgresContext();
                context.Add <Produtos>(p);
                context.SaveChanges();
                context.Dispose();

                return(new ResultWithBody
                {
                    Code = System.Net.HttpStatusCode.OK,
                    Body = "Inserção de Produto - Produto Inserido",
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine("[error] ConfigController - GetFurnaces - {0} - {1}",
                                  ex.Message,
                                  ex.StackTrace.Replace(Environment.NewLine, " "));
                return(new ResultWithBody
                {
                    Code = System.Net.HttpStatusCode.InternalServerError,
                    Body = "GetFurnaces - Fatal error retrieving furnaces configuration",
                });
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Test test)
        {
            if (ModelState.IsValid)
            {
                _context.Add(test);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(test));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("Id,Filme,Genero")] TbFilme tbFilme)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tbFilme);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tbFilme));
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Endereco,Cpf")] TbCliente tbCliente)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tbCliente);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tbCliente));
        }
Beispiel #5
0
        public async Task <IActionResult> Create([Bind("TbClienteId,TbFilmeId,DataLocacao,DataDevolucao,Id")] TbLocacao tbLocacao)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tbLocacao);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TbClienteId"] = new SelectList(_context.TbCliente, "Id", "Cpf", tbLocacao.TbClienteId);
            ViewData["TbFilmeId"]   = new SelectList(_context.TbFilme, "Id", "Filme", tbLocacao.TbFilmeId);
            return(View(tbLocacao));
        }
Beispiel #6
0
        private static void Init()
        {
            using (var db = new woodmanContext())
            {
                var entities = db.EfCoreTest.Where(e => e.Name.Contains(nameof(BulkTransactionTests))).ToList();

                if (entities.Count > 0)
                {
                    db.RemoveRange(entities);
                }

                for (var i = 0; i < InitialCount; i++)
                {
                    db.Add(new EfCoreTest
                    {
                        Name         = nameof(BulkTransactionTests),
                        CreatedDate  = DateTime.Now,
                        ModifiedDate = DateTime.Now
                    });
                }

                db.SaveChanges();
            }

            using (var db = new postgresContext())
            {
                var entities = db.Efcoretest.Where(e => e.Name.Contains(nameof(BulkTransactionTests))).ToList();

                if (entities.Count > 0)
                {
                    db.RemoveRange(entities);
                }

                for (var i = 0; i < InitialCount; i++)
                {
                    db.Add(new Efcoretest
                    {
                        Name         = nameof(BulkTransactionTests),
                        Createddate  = DateTime.Now,
                        Modifieddate = DateTime.Now
                    });
                }

                db.SaveChanges();
            }
        }
Beispiel #7
0
        protected virtual void InitNpgSqlDb()
        {
            using (var db = new postgresContext())
            {
                for (var i = 1; i <= 10; i++)
                {
                    var name = $"{Name}_{i}";

                    var existing = db.Efcoretest
                                   .Where(e => e.Name == name)
                                   .FirstOrDefault();

                    var efCoreTestId = 0;

                    if (existing == null)
                    {
                        var inserted = db.Efcoretest.Add(new Efcoretest
                        {
                            Name         = name,
                            Createddate  = DateTime.Now,
                            Modifieddate = DateTime.Now
                        });

                        db.SaveChanges();

                        efCoreTestId = inserted.Entity.Id;
                        NpgSqlIds.Add(inserted.Entity.Id);
                    }
                    else
                    {
                        efCoreTestId = existing.Id;
                        NpgSqlIds.Add(existing.Id);
                    }

                    if (i > 5)
                    {
                        continue;
                    }

                    for (var j = 1; j <= 4; j++)
                    {
                        var childName = $"{Name}_{i}_{j}";

                        var existingChild = db.Efcoretestchild
                                            .Where(e => e.Name == childName)
                                            .FirstOrDefault();

                        if (existingChild == null)
                        {
                            var inserted = db.Add(new Efcoretestchild
                            {
                                Efcoretestid = efCoreTestId,
                                Name         = name,
                                Createddate  = DateTime.Now,
                                Modifieddate = DateTime.Now
                            });

                            db.SaveChanges();

                            NpgSqlCompositeIds.Add(new object[] { inserted.Entity.Id, efCoreTestId });
                        }
                        else
                        {
                            NpgSqlCompositeIds.Add(new object[] { existing.Id, efCoreTestId });
                        }
                    }
                }
            }
        }