public IActionResult CreateComplaint(Complaints complaints) { complaints.Id = db.Complaintses.Count() + 1; db.Complaintses.Add(complaints); db.SaveChanges(); return(View("Start")); }
public static void Initialize(AplicationContext context) { if (!context.Users.Any()) { context.Users.AddRange( new User { Id = 1, Login = "******", Email = "*****@*****.**", Password = "******" }, new User { Id = 2, Login = "******", Email = "*****@*****.**", Password = "******" }, new User { Id = 3, Login = "******", Email = "*****@*****.**", Password = "******" } ); context.SaveChanges(); } }
private static void CadastrarPedido() { using var db = new AplicationContext(); var cliente = db.Clientes.FirstOrDefault(); var produto = db.Produtos.FirstOrDefault(); var pedido = new Pedido { ClienteId = cliente.Id, IniciadoEm = DateTime.Now, FinalizadoEm = DateTime.Now, Observacao = "Pedido Teste", Status = StatusPedido.Analise, TipoFrete = TipoFrete.SemFrete, Items = new List <PedidoItem> { new PedidoItem { ProdutoId = produto.Id, Desconto = 0, Quantidade = 1, Valor = 10 } } }; db.Pedidos.Add(pedido); db.SaveChanges(); }
private static void InserirDadosEmMassa() { var produto = new Produto { Descricao = "Produto Teste", CodigoBarras = "1234567891231", Valor = 10m, TipoProduto = TipoProduto.MercadoriaParaVenda, Ativo = true }; var Cliente = new Cliente { Nome = "Rafael Almeida", CEP = "99999000", Cidade = "Itabaiana", Estado = "SE", Telefone = "99000001111" }; using var db = new AplicationContext(); db.AddRange(produto, Cliente); var registros = db.SaveChanges(); Console.WriteLine($"Total de registros(s): {registros}"); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, AplicationContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } if (!context.Countries.Any()) { context.Countries.AddRange( new List <Country>() { new Country() { Name = "c", CountryID = 1 }, new Country() { Name = "b", CountryID = 2 }, } ); context.SaveChanges(); } app.UseHttpsRedirection(); app.UseMvc(); }
public IActionResult Privacy(Complaints complaints) { complaints.Id = db.Complaintses.Count() + 1; db.Complaintses.Add(complaints); db.SaveChanges(); return(View()); }
private static void RemoverRegistro() { using var db = new AplicationContext(); var cliente = db.Clientes.Find(2); //db.Clientes.Remove(cliente); //db.Remove(cliente); db.Entry(cliente).State = EntityState.Deleted; db.SaveChanges(); }
public IActionResult Registration(User user, int districtId) { if (!ModelState.IsValid) { return(View()); } user.Id = db.Users.Count() + 1; db.Users.Add(user); db.UserToRoles.Add(new UserToRole { Id = db.UserToRoles.Count() + 1, UserId = user.Id, RoleId = 1 }); //db.StatusToUsers.Add(new StatusToUser { Id = db.StatusToUsers.Count() + 1, UserId = user.Id, UserStatusId = 1 }); db.UsetToVirtualDistricts.Add(new UsetToVirtualDistrict { Id = db.UsetToVirtualDistricts.Count() + 1, UserId = user.Id, VirtualDistrictId = districtId }); db.SaveChanges(); var user1 = db.Users.Where(u => u.Id == user.Id); currentUserId = user.Id; return(RedirectToAction("Index")); }
private static void AtualizarDados() { using var db = new AplicationContext(); var cliente = db.Clientes.Find(1); //cliente.Nome = "Cliente Alterado Passo1"; var clienteDesconectado = new Cliente { Nome = "Cliente Desconectado", Telefone = "7966669999" }; db.Entry(cliente).CurrentValues.SetValues(clienteDesconectado); //db.Clientes.Update(cliente); db.SaveChanges(); }
private static void InserirDados() { var produto = new Produto { Descricao = "Produto Teste", CodigoBarras = "1234567891231", Valor = 10m, TipoProduto = TipoProduto.MercadoriaParaVenda, Ativo = true }; using var db = new AplicationContext(); //db.Produtos.Add(produto); //db.Set<Produto>().Add(produto); //db.Entry(produto).State = EntityState.Added; db.Add(produto); var registros = db.SaveChanges(); Console.WriteLine($"Total de registros(s): {registros}"); }
public static void Initialize(AplicationContext context) { User user1 = new User { Id = 1, FirstName = "Anton", LastName = "Totbin", PIN = 1234567890123, // BirthDate = new DateTime(1976, 8, 11), Login = "******", Email = "*****@*****.**", Password = "******" }; User user2 = new User { Id = 2, FirstName = "Alex", LastName = "Toto", PIN = 1111111111111, // BirthDate = new DateTime(1996, 6, 10), Login = "******", Email = "*****@*****.**", Password = "******" }; User user3 = new User { Id = 3, FirstName = "Ivan", LastName = "Lopert", PIN = 1111111111112, // BirthDate = new DateTime(1996, 6, 10), Login = "******", Email = "*****@*****.**", Password = "******" }; User user4 = new User { Id = 4, FirstName = "Olena", LastName = "Varneva", PIN = 1111111111113, // BirthDate = new DateTime(1983, 5, 07), Login = "******", Email = "*****@*****.**", Password = "******" }; User user5 = new User { Id = 5, FirstName = "Vika", LastName = "Petrenko", PIN = 1111111111114, // BirthDate = new DateTime(1973, 1, 12), Login = "******", Email = "*****@*****.**", Password = "******" }; User user6 = new User { Id = 6, FirstName = "Yulia", LastName = "Stahiv", PIN = 1111111111115, // BirthDate = new DateTime(2000, 13, 03), Login = "******", Email = "*****@*****.**", Password = "******" }; User user7 = new User { Id = 7, FirstName = "Oleg", LastName = "Lesiv", PIN = 1111111111116, // BirthDate = new DateTime(1968, 15, 03), Login = "******", Email = "*****@*****.**", Password = "******" }; User user8 = new User { Id = 8, FirstName = "Vadim", LastName = "Pushka", PIN = 1111111111117, // BirthDate = new DateTime(1989, 19, 02), Login = "******", Email = "*****@*****.**", Password = "******" }; User user9 = new User { Id = 9, FirstName = "Andrii", LastName = "Virt", PIN = 1111111111118, // BirthDate = new DateTime(1959, 10, 09), Login = "******", Email = "*****@*****.**", Password = "******" }; User user10 = new User { Id = 10, FirstName = "Oksana", LastName = "Virtlaeva", PIN = 1111111111119, // BirthDate = new DateTime(1980, 12, 05), Login = "******", Email = "*****@*****.**", Password = "******" }; context.Users.AddRange( user1, user2, user3, user4, user5, user6, user7, user8, user9, user10 ); context.SaveChanges(); }
static void Main(string[] args) { AplicationContext app = new AplicationContext(); //inserting data to db. for (int i = 0; i < 10; i++) { Person person = new Person(); person.name = "Ankit" + i; person.email = "Ankit" + i + "@gmail.com"; person.isActive = (i % 5 == 0 || i % 3 == 0) ? 1 : 0; app.persons.Add(person); app.SaveChanges(); } //extracting persion detail by id Console.WriteLine("Enter the id to search"); int userId = Convert.ToInt32(Console.ReadLine()); var getPerson = app.persons.Where(a => a.id == userId).FirstOrDefault(); if (getPerson != null) { Console.WriteLine(getPerson.id + "\t" + getPerson.name + "\t" + getPerson.email + "\t" + getPerson.isActive); } else { Console.WriteLine("Not found"); } //get active users Console.WriteLine("Enter any key to see active users"); Console.ReadLine(); var activeUsers = app.persons.Where(a => a.isActive == 1).ToList(); if (activeUsers.Any()) { foreach (Person item in activeUsers) { Console.WriteLine(item.id + "\t" + item.name + "\t" + item.isActive); } } else { Console.WriteLine("No active users."); } //delete based on id Console.WriteLine("Enter the id to delete"); int newId = Convert.ToInt32(Console.ReadLine()); var resultantList = app.persons.Where(a => a.id == newId).FirstOrDefault(); if (resultantList != null) { app.persons.Remove(resultantList); app.SaveChanges(); } else { Console.WriteLine("no such id is found"); } }
public void Seed(AplicationContext context) { if (context.User.Any()) { return; } string password = "******"; byte[] passwordHash, passwordSalt; HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); context.User.Add(new User { Name = "yazilim", Surname = "Aplication", Email = "*****@*****.**", Username = "******", PasswordHash = passwordHash, PasswordSalt = passwordSalt, Avatar = "/assets/images/avatar/avatarset01/avatarset01_01.png", }); var store = new Store { Id = 37814, Name = "Stock Mount", Description = "Stock Mount", }; context.Store.Add(store); var store2 = new Store { Id = 37815, Name = "Stock Mount", Description = "Stock Mount", }; context.Store.Add(store2); var store3 = new Store { Id = 37816, Name = "Stock Mount", Description = "Stock Mount", }; context.Store.Add(store3); if (context.Database.ProviderName != "Microsoft.EntityFrameworkCore.InMemory") { context.Database.OpenConnection(); try { context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT dbo.Store ON;"); context.SaveChanges(); context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT dbo.Store OFF;"); } finally { context.Database.CloseConnection(); } } for (int i = 1; i < 101; i++) { var order = new Order { Name = "Aplication", PersonalIdentification = "11111111111", Nickname = "Aplication", OrderDate = DateTime.Parse("2020-07-06T11:30:48.403Z"), IntegrationOrderCode = "202847319367", OrderStatus = "Completed", Fullname = "Aplication", Address = "Üniversiteler Mh. Odtü Teknokent Silikon Blok Aplication Çankaya Ankara", Telephone = "5320000000", TaxNumber = "11111111111", City = "Ankara", District = "Çankaya", CompanyTitle = null, Store = store, Email = "Aplication", }; order.OrderDetails.Add(new OrderDetail { StoreId = store.Id, IntegrationProductCode = "112576403", IntegrationOrderDetailId = "37726242", ProductName = "FIRAT Thermo Kauçuk Bezli Sulama Hortumu 1\" - 50 Metre", ProductCode = "7401000254", Price = 219, Quantity = 1, RawQuantity = 1, Invoiced = true, Unread = false, DeliveryTitle = "Aplication", Address = "Üniversiteler Mh. Odtü Teknokent Silikon Blok Aplication Çankaya Ankara", Telephone = "5320000000", CargoCompany = "Yurtiçi", CargoLabelCode = "600974982644", CargoPayment = "Mağaza Öder", CargoDate = DateTime.Parse("2016-08-12T21:00:00Z"), District = "Çankaya", City = "Ankara", ShipmentCampaignCode = "601508011309577", MerchantSku = "7401000254", DetailType = 1, OrderStatus = "Completed", LastModificationTime = DateTime.Parse("2020-02-27T14:57:40.793"), ProductUnit = "0", }); order.OrderDetails.Add(new OrderDetail { StoreId = store.Id, IntegrationProductCode = "119072276", IntegrationOrderDetailId = "37726244", ProductName = "WERT 2251 Saatçi Tornavida Seti 6 Parça", ProductCode = "WERT.2251", Price = 9, Quantity = 1, RawQuantity = 1, TaxRate = 0, Invoiced = true, Unread = false, DeliveryTitle = "Aplication", Address = "Üniversiteler Mh. Odtü Teknokent Silikon Blok Aplication Çankaya Ankara", Telephone = "5320000000", CargoCompany = "Yurtiçi", CargoLabelCode = "600974982644", CargoPayment = "Mağaza Öder", CargoDate = DateTime.Parse("2016-08-12T21:00:00Z"), District = "Çankaya", City = "Ankara", ShipmentCampaignCode = "601508011309577", MerchantSku = "WERT.2251", DetailType = 1, OrderStatus = "Completed", LastModificationTime = DateTime.Parse("2020-02-27T14:57:40.793"), ProductUnit = "0", }); order.OrderDetails.Add(new OrderDetail { StoreId = store.Id, IntegrationProductCode = "94191960", IntegrationOrderDetailId = "37726243", ProductName = "CETA FORM 4000M/7ST1 7 Parça Tornavida Takımı - Tornavida Seti", ProductCode = "CETA.4000M/7ST1", Price = 27, Quantity = 1, RawQuantity = 1, Invoiced = true, Unread = false, DeliveryTitle = "Aplication", Address = "Üniversiteler Mh. Odtü Teknokent Silikon Blok Aplication Çankaya Ankara", Telephone = "5320000000", CargoCompany = "Yurtiçi", CargoLabelCode = "600974982644", CargoPayment = "Mağaza Öder", CargoDate = DateTime.Parse("2016-08-12T21:00:00Z"), District = "Çankaya", City = "Ankara", ShipmentCampaignCode = "601508011309577", MerchantSku = "CETA.4000M/7ST1", DetailType = 1, OrderStatus = "Completed", LastModificationTime = DateTime.Parse("2020-02-27T14:57:40.793"), ProductUnit = "0", }); context.Orders.AddRange(order); } context.SaveChanges(); }
public void Save() => db.SaveChanges();
public void Commit() { _aplicationContext.SaveChanges(); }