//Create public User Add(User user) { _context.Users.Add(user); _context.Addresses.Add(user.Address); _context.SaveChanges(); return(user); }
//Create public ShoppingCart AddArticle(ShoppingCart shoppingCart, Article article) { shoppingCart.Articles.Add(article); _context.ShoppingCarts.Update(shoppingCart); _context.SaveChanges(); return(shoppingCart); }
public void Delete_WithValidEntityID_ShouldRemoveRecordFromDatabase() { var options = ConnectionOptionHelper.Sqlite(); //Arrange var supplier = new Supplier { Name = "Shirt Supplier", Description = "This is a Shirt Supplier", IsActive = true }; using (var context = new ECommerceDbContext(options)) { context.Database.OpenConnection(); context.Database.EnsureCreated(); var sut = new SupplierRepository(context); context.Suppliers.Add(supplier); context.SaveChanges(); //Act sut.Delete(supplier.ID); context.SaveChanges(); var actual = context.Suppliers.Find(supplier.ID); //Assert Assert.Null(actual); } }
public ShoppingCart CreateCart(ShoppingCart shoppingCart, User user) { shoppingCart.Buyer = user; _context.ShoppingCarts.Add(shoppingCart); _context.SaveChanges(); return(shoppingCart); }
public void Delete_WithValidEntityID_ShouldRemoveRecordFromDatabase() { var options = ConnectionOptionHelper.Sqlite(); //Arrange var category = new Category { Name = "Bag", Description = "Bag Department" }; using (var context = new ECommerceDbContext(options)) { context.Database.OpenConnection(); context.Database.EnsureCreated(); var sut = new CategoryRepository(context); context.Categories.Add(category); context.SaveChanges(); //Act sut.Delete(category.ID); context.SaveChanges(); var actual = context.Categories.Find(category.ID); //Assert Assert.Null(actual); } }
public bool Update(Product product) { _dbContext.Product.Update(product); _dbContext.SaveChanges(); return(true); }
public void Atualizar(Produto produto) { if (ProdutoExists(produto.Id)) { _context.Entry(produto).State = EntityState.Modified; _context.SaveChanges(); } }
public ActionResult Create(Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Create([Bind(Include = "CategoryId,Name")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "SupplierId,Name")] Supplier supplier) { if (ModelState.IsValid) { db.Suppliers.Add(supplier); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(supplier)); }
public ActionResult Create([Bind(Include = "SellId,SellNumver,Date,BuyerName,BuyerDoc,PhoneNumber,TotalPrice")] Sell sell) { if (ModelState.IsValid) { sell.Date = DateTime.Now; db.Sells.Add(sell); db.SaveChanges(); return(RedirectToAction("Edit", new { id = sell.SellId })); } return(View(sell)); }
public ActionResult Create([Bind(Include = "Id,OrderDate,CustomerId")] Order order) { if (ModelState.IsValid) { db.Orders.Add(order); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Firstname", order.CustomerId); return(View(order)); }
public bool Atualizar(Estoque estoque) { if (Exists(estoque)) { _context.Entry(estoque).State = EntityState.Modified; _context.SaveChanges(); return(true); } else { return(false); } }
public ActionResult Create([Bind(Include = "ProductId,Name,Price,CategoryId,SupplierId")] Product product) { if (ModelState.IsValid) { product.Deleted = false; db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", product.CategoryId); ViewBag.SupplierId = new SelectList(db.Suppliers, "SupplierId", "Name", product.SupplierId); return(View(product)); }
private void CreateEditions() { var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName); if (defaultEdition == null) { defaultEdition = new Edition { Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName }; _context.Editions.Add(defaultEdition); _context.SaveChanges(); /* Add desired features to the standard edition, if wanted... */ } }
public void SaveCategory(Category category) { using (var context = new ECommerceDbContext()) { context.Categories.Add(category); try { context.SaveChanges(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } } }
public void Retrieve_WithVAlidEntityID_ReturnsAValidEntity() { var options = ConnectionOptionHelper.Sqlite(); //Arrange var category = new Category { Name = "Shoes", Description = "Shoes Department" }; using (var context = new ECommerceDbContext(options)) { context.Database.OpenConnection(); context.Database.EnsureCreated(); context.Categories.Add(category); context.SaveChanges(); } using (var context = new ECommerceDbContext(options)) { var sut = new CategoryRepository(context); // Act var actual = sut.Retrieve(category.ID); //Assert Assert.NotNull(actual); Assert.Equal(category.Name, actual.Name); Assert.Equal(category.Description, actual.Description); } }
public ActionResult Create([Bind(Include = "SellItemId,Quantity,UnitPrice,ProductId,SellId")] SellItem sellItem) { if (ModelState.IsValid) { db.SellItems.Add(sellItem); var sell = db.Sells.Find(sellItem.SellId); sell.TotalPrice += sellItem.Quantity * sellItem.UnitPrice; db.Entry(sell).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Edit", "Sells", new { id = sellItem.SellId })); } //ViewBag.ProductId = new SelectList(db.Products, "ProductId", "Name", sellItem.ProductId); //ViewBag.SellId = new SelectList(db.Sells, "SellId", "SellNumver", sellItem.SellId); return(RedirectToAction("Edit", "Sells", new { id = sellItem.SellId })); }
public void Update_WithValidEntity_ShouldUpdateDatabaseRecord() { var options = ConnectionOptionHelper.Sqlite(); var oldCategory = new Category { Name = "shoes", Description = "Shoes Department" }; using (var context = new ECommerceDbContext(options)) { context.Database.OpenConnection(); context.Database.EnsureCreated(); //Arrange context.Categories.Add(oldCategory); context.SaveChanges(); } var newName = "Bag"; var newDescription = "Bag Department"; using (var context = new ECommerceDbContext(options)) { var sut = new CategoryRepository(context); //Act var record = context.Categories.Find(oldCategory.ID); record.Name = newName; record.Description = newDescription; sut.Update(record.ID, record); var newCategory = context.Categories.Find(record.ID); //Assert Assert.Equal(newCategory.Name, newName); Assert.Equal(newCategory.Description, newDescription); } }
public void Retrieve_WithVAlidEntityID_ReturnsAValidEntity() { var options = ConnectionOptionHelper.Sqlite(); // Arrange var supplier = new Supplier { Name = "Bag Supplier", Description = "This is a Bag Supplier" }; using (var context = new ECommerceDbContext(options)) { context.Database.OpenConnection(); context.Database.EnsureCreated(); context.Suppliers.Add(supplier); context.SaveChanges(); } using (var context = new ECommerceDbContext(options)) { var sut = new SupplierRepository(context); // Act var actual = sut.Retrieve(supplier.ID); //Assert Assert.NotNull(actual); Assert.Equal(supplier.Name, actual.Name); Assert.Equal(supplier.Description, actual.Description); } }
public void Gravar(Usuario usuario) { if (!Exists(usuario)) { _context.Usuarios.Add(usuario); _context.SaveChanges(); } }
public void UpdateProduct(Product product) { using (var context = new ECommerceDbContext()) { context.Entry(product).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public void UpdateCategory(Category category) { using (var context = new ECommerceDbContext()) { context.Entry(category).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public void Gravar(Perfil perfil) { if (!Exists(perfil)) { _context.Perfis.Add(perfil); _context.SaveChanges(); } }
public void DeleteProduct(int ID) { using (var context = new ECommerceDbContext()) { var product = context.Products.Find(ID); context.Products.Remove(product); context.SaveChanges(); } }
public void Create() { new DefaultEditionCreator(_context).Create(); new DefaultLanguagesCreator(_context).Create(); new HostRoleAndUserCreator(_context).Create(); new DefaultSettingsCreator(_context).Create(); _context.SaveChanges(); }
private void AddSettingIfNotExists(string name, string value, int?tenantId = null) { if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null)) { return; } _context.Settings.Add(new Setting(tenantId, null, name, value)); _context.SaveChanges(); }
private void AddLanguageIfNotExists(ApplicationLanguage language) { if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name)) { return; } _context.Languages.Add(language); _context.SaveChanges(); }
public void DeleteCategory(int ID) { using (var context = new ECommerceDbContext()) { var category = context.Categories.Find(ID); context.Categories.Remove(category); context.SaveChanges(); } }
public IActionResult Create(Registration regDetails) { if (ModelState.IsValid) { context.RegistrationTable.Add(regDetails); context.SaveChanges(); return(RedirectToAction("Login")); } return(View("Registration", regDetails)); }