public virtual bool Delete(TEntity entity) { //var remove = DbContext.Set<TEntity>().Remove(entity); entity.IsDeleted = true; entity.DeletionTime = DateTime.Now.ToUniversalTime(); DbContext.Entry(entity).State = EntityState.Modified; return(true); }
public bool Edit(T entity) { db.Entry(entity).State = EntityState.Modified; int i = db.SaveChanges(); return(i > 0); }
public Review UpdateReview(Review review) { Review currentReview = _context.Reviews.Where(r => r.ProductId == review.ProductId && r.UserId == review.UserId).FirstOrDefault(); _context.Entry(currentReview).CurrentValues.SetValues(review); _context.SaveChanges(); return(review); }
public OrderState UpdateOrderState(OrderState orderState) { var oldOrderState = _context.OrderStates.FirstOrDefault(os => os.Id == orderState.Id); _context.Entry(oldOrderState).CurrentValues.SetValues(orderState); _context.SaveChanges(); return(orderState); }
public Payment UpdatePayment(Payment payment) { var oldPayment = _context.Payments.FirstOrDefault(p => p.Id == payment.Id); _context.Entry(oldPayment).CurrentValues.SetValues(payment); _context.SaveChanges(); return(payment); }
public Order UpdateOrder(Order order) { var oldOrder = _context.Orders.FirstOrDefault(o => o.Id == order.Id); _context.Entry(oldOrder).CurrentValues.SetValues(order); _context.SaveChanges(); return(order); }
public Shipping UpdateShipping(Shipping shipping) { var oldShipping = _context.Shippings.FirstOrDefault(s => s.Id == shipping.Id); _context.Entry(oldShipping).CurrentValues.SetValues(shipping); _context.SaveChanges(); return(shipping); }
public OrderItem UpdateOrderItem(OrderItem orderItem) { var oldItem = _context.OrderItems .FirstOrDefault(oi => oi.OrderId == orderItem.OrderId && oi.ProductId == orderItem.ProductId); _context.Entry(oldItem).CurrentValues.SetValues(orderItem); _context.SaveChanges(); return(orderItem); }
public CartItem UpdateCartItem(CartItem cartItem) { var oldItem = _context.CartItems .FirstOrDefault(ci => ci.VisitorId == cartItem.VisitorId && ci.ProductId == cartItem.ProductId); _context.Entry(oldItem).CurrentValues.SetValues(cartItem); _context.SaveChanges(); return(cartItem); }
public FrontPageItem UpdateFrontPageItem(FrontPageItem item) { var oldItem = _context.FrontPageItems .FirstOrDefault(fi => fi.Id == item.Id); _context.Entry(oldItem).CurrentValues.SetValues(item); _context.SaveChanges(); return(item); }
public bool UpdateCustomer(Customer customer) { int isExecuted = 0; db.Entry(customer).State = EntityState.Modified; isExecuted = db.SaveChanges(); if (isExecuted > 0) { return(true); } return(false); }
public bool UpdateSupplier(Supplier supplier) { int isExecuted = 0; db.Entry(supplier).State = EntityState.Modified; isExecuted = db.SaveChanges(); if (isExecuted > 0) { return(true); } return(false); }
public bool Update(Product product) { int isExecuted = 0; db.Entry(product).State = EntityState.Modified; isExecuted = db.SaveChanges(); if (isExecuted > 0) { return(true); } return(false); }
public bool UpdateCategory(Category category) { int isExecuted = 0; db.Entry(category).State = EntityState.Modified; isExecuted = db.SaveChanges(); if (isExecuted > 0) { return(true); } return(false); }
public void Site_should_save_new_record() { var entityRepository = new DomainRepository <Site>(dbContext); var site = new Site(new TenantId("abc"), "def", "def", true); entityRepository.Add(site); dbContext.Entry(site).State = EntityState.Added; entityRepository.SaveChanges(); var result = entityRepository.Find(site.Id); Assert.NotNull(result); Assert.Equal("def", result.Name); }
public bool Update(Catalog catalog) { int isExecuted = 0; //Method 1 //Student aStudent = db.Students.FirstOrDefault(c => c.ID == student.ID); //if (aStudent != null) //{ // aStudent.Name = student.Name; // isExecuted = db.SaveChanges(); //} //Method 2 db.Entry(catalog).State = EntityState.Modified; isExecuted = db.SaveChanges(); if (isExecuted > 0) { return(true); } return(false); }
public static void FillTenantSubscription() { using (var db = new BusinessDbContext()) { var tenants = db.Tenants.ToList(); var subscriptions = db.Subscriptions.AsNoTracking().ToList(); foreach (var tenant in tenants) { var subscription = subscriptions.Where(x => x.TenantId == tenant.Id).OrderByDescending(x => x.ExpireOn).FirstOrDefault(); if (subscription != null) { tenant.SubscriptionId = subscription.Id; db.Entry(tenant).State = EntityState.Modified; } } db.SaveChanges(); } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); //BusinessDbContext dbContext; var optionsBuilder = new DbContextOptionsBuilder <BusinessDbContext>(); optionsBuilder.UseMySql("Server=localhost;database=test;uid=root;pwd=P@ssword;charset=utf8;port=3306;SslMode=None"); TenantId tenantId = new TenantId(); tenantId.Id = "abc"; Guid siteId = Guid.NewGuid(); var site = new Site(); site.Id = siteId; site.TenantId = tenantId; //Branding branding = new Branding(); //branding.Id = Guid.NewGuid(); //branding.TenantId = tenantId; //branding.SiteId = siteId; //branding.Site = site; using (var dbContext = new BusinessDbContext(optionsBuilder.Options)) { //dbContext.Entry(site).State = EntityState.Added; //dbContext.Entry(site.Branding).State = EntityState.Added; /* not worked * site.CreateBranding(); * dbContext.Add(site); * dbContext.Entry(site.Branding).State = EntityState.Added; */ /* worked * dbContext.Add(site); * site.CreateBranding(); * */ //dbContext.Entry(site).State = EntityState.Detached; site.CreateBranding(); dbContext.Add(site); dbContext.Entry(site).State = EntityState.Added; dbContext.Entry(site.Branding).State = EntityState.Added; //dbContext.Entry(site.Branding.TenantId).State = EntityState.Added; //dbContext.Entry(site.TenantId).State = EntityState.Added; //site.CreateBranding(); //dbContext //dbContext.Entry(site.TenantId).State = EntityState.Added; //site.Branding = branding; // error //dbContext.Entry(site).State = EntityState.Unchanged; //dbContext.Entry(branding).State = EntityState.Added; dbContext.SaveChanges(); //var site2 = dbContext.Set<Site>().Find(siteId); //site2.Branding = new Branding(); //site2.Branding.Id = Guid.NewGuid(); //site2.Branding.TenantId = site2.TenantId; //site2.Branding.SiteId = site2.Id; //dbContext.Set<Site>().Update(site2); //dbContext.SaveChanges(); } }
public virtual bool Edit(TEntity entity) { Db.Entry(entity).State = EntityState.Modified; return(true); }
public void Update(TEntity entity) { _context.Entry(entity).State = EntityState.Modified; _context.SaveChanges(); }