public void Update(Event entity) { using (var ctx = new DALContext()) { using (var ctxTransaction = ctx.Database.BeginTransaction()) try { ctx.Events.Attach(entity); if (entity.Components != null) { foreach (var comp in entity.Components) { AttachComponent(ctx, comp); } } ctx.Entry(entity).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); ctxTransaction.Commit(); } catch (Exception ex) { ctxTransaction.Rollback(); Console.WriteLine(ex.StackTrace); throw ex; } } }
public async Task DeleteIceCream(int iceCreamID) { using (var db = new DALContext()) { IceCream a = await db.IceCreams.FindAsync(iceCreamID); db.Entry(a).State = EntityState.Deleted; await db.SaveChangesAsync(); } }
public async Task DeleteShop(int shopID) { using (var db = new DALContext()) { Shop shop = await db.Shops.FindAsync(shopID); db.Entry(shop).State = EntityState.Deleted; await db.SaveChangesAsync(); } }
public void Update(Registration entity) { using (var ctx = new DALContext()) { ctx.Registrations.Attach(entity); ctx.Entry(entity).State = EntityState.Modified; ctx.Users.Attach(entity.User); ctx.Events.Attach(entity.Event); foreach (var item in entity.Items) { ctx.Components.Attach(item); ctx.Entry(item).State = EntityState.Modified; } ctx.SaveChanges(); } }
private void AttachComponent(DALContext ctx, Component component) { if (component is Category) { var cats = ((Category)component); if (cats.Components != null) { foreach (var comp in cats.Components) { ctx.Components.Attach(comp); ctx.Entry(comp).State = System.Data.Entity.EntityState.Modified; ctx.Components.AddOrUpdate(comp); if (comp is Category) { AttachComponent(ctx, comp); } } } } ctx.Components.Attach(component); ctx.Entry(component).State = System.Data.Entity.EntityState.Modified; }
public async Task removeClient(Client client1) { if (client1 == null) { throw new Exception("the client that you want to remove doesn't exist "); } else { using (var db = new DALContext()) { Client a = db.ClientList.Find(client1.ID); db.Entry(a).State = EntityState.Deleted; await db.SaveChangesAsync(); } } }
public void Update(User entity) { using (var ctx = new DALContext()) { using (var ctxTransaction = ctx.Database.BeginTransaction()) try { ctx.Entry(entity).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); ctxTransaction.Commit(); } catch (Exception) { ctxTransaction.Rollback(); } } }
public async Task removeDistribution(Distribution Distribution1) { if (Distribution1.ClientList.Count != 0) { throw new Exception("this distribution is already assigned"); } if (Distribution1 == null) { throw new Exception("the distribution does'nt exist "); } else { using (var db = new DALContext()) { Distribution a = await db.DistributionList.FindAsync(Distribution1.ID); db.Entry(a).State = EntityState.Deleted; await db.SaveChangesAsync(); } } }
public async Task removeDeliveryMen(DeliveryMen delivery1) { if (GetDistributionList(delivery1).Count != 0) { throw new Exception("this delivery men is already assigned to a distribution,you can't remove it"); } if (delivery1 == null) { throw new Exception("the delivery men that you want to add doesn't exist "); } //else //{ using (var db = new DALContext()) { DeliveryMen a = await db.DeliveryMenList.FindAsync(delivery1.ID); db.Entry(a).State = EntityState.Deleted; await db.SaveChangesAsync(); } //} }