private PublicationProductViewModel ChangePage(Pagination pagination, int id, int CurrentPage, int TotalPages) { var exclude = _context.Pagination.Where(p => p.id != 0); _context.Pagination.RemoveRange(exclude); //limpar DB antes de começar um novo _context.SaveChanges(); pagination.ProductId = id; pagination.TotalPages = TotalPages; //precisa pegar o numero de paginas total do manual e comparar com a pagina atual, para saber se pode avançar mais ou nao pagination.CurrentPage = CurrentPage; // _context.Pagination.Add(pagination); _context.SaveChanges(); var page = BuildPage(id, pagination.CurrentPage); return(page); }
public IActionResult CreateUser(UserFormViewModel formUser, int id) { User user = new User(); var dealer = _dealerService.FindDealerById(id); user.Name = formUser.Name; user.Email = formUser.Email; user.Dealer = dealer; _userService.AddUser(user); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public void SaveThis(XmlProduct xmlproduct) { _context.Add(xmlproduct); _context.SaveChanges(); }
public void AddDealer(Dealer dealer) { _context.Dealer.Add(dealer); _context.SaveChanges(); }
public void AddUser(User user) { _context.User.Add(user); _context.SaveChanges(); }
public void Seed() { if (_context.User.Any() || _context.Product.Any() || _context.Dealer.Any() || _context.Company.Any()) { return; //DB has been seeded. } //Companies Company c1 = new Company { Name = "Stara" }; Company c2 = new Company { Name = "Jan" }; Company c3 = new Company { Name = "Kepler Weber" }; Company c4 = new Company { Name = "Pinhalense" }; Company c5 = new Company { Name = "QueroDiesel" }; //Dealers Dealer d1 = new Dealer("MaqLixo", c1); Dealer d2 = new Dealer("MaqMerda", c1); Dealer d3 = new Dealer("Podridão Máquinas LTDA.", c1); Dealer d4 = new Dealer("Máquinas Agrícolas Diversas", c1); Dealer d5 = new Dealer("MaqLixo", c2); Dealer d6 = new Dealer("MaqMerda", c2); Dealer d7 = new Dealer("Podridão Máquinas LTDA.", c2); Dealer d8 = new Dealer("Máquinas Agrícolas Diversas", c2); //Products Product p1 = new Product("RX-8000", "Pistola de Hádrons", "RMO-897500589", c1, "no_image.png"); Product p2 = new Product("TY-899", "Punheteira Pneumática", "R999-TY67KJ89", c1, "no_image.png"); Product p3 = new Product("JJK-009", "Estourador de Rabos Pneumático", "R-TY9999k", c1, "no_image.png"); Product p4 = new Product("JsssssJK-009", "Boqueteador Sismico", "R9k-1.0", c1, "no_image.png"); Product p6 = new Product("RX-8000", "Pistola de Hádrons", "RMO-897500589", c2, "no_image.png"); Product p7 = new Product("TY-899", "Punheteira Pneumática", "R999-TY67KJ89", c2, "no_image.png"); Product p8 = new Product("JJK-009", "Estourador de Rabos Pneumático", "R-TY9999k", c2, "no_image.png"); Product p9 = new Product("JsssssJK-009", "Boqueteador Sismico", "R9k-1.0", c2, "no_image.png"); //Users User u1 = new User("Joaquim", "*****@*****.**", d1); User u2 = new User("Jorge", "*****@*****.**", d1); User u3 = new User("Cuzão", "*****@*****.**", d1); User u4 = new User("Cuseiro", "*****@*****.**", d1); _context.Company.AddRange(c1, c2, c3, c4, c5); _context.Dealer.AddRange(d1, d2, d3, d4); _context.Product.AddRange(p1, p2, p3, p4, p6, p7, p8, p9); _context.User.AddRange(u1, u2, u3, u4); //_roleManager.CreateAsync(new IdentityRole("Admin")); _context.SaveChanges(); }
public void AddProduct(Product product) { _context.Add(product); _context.SaveChanges(); }