public Item Create(Item entity) { using (var ctx = new DALContext()) { ctx.Database.Log = (s) => { Console.WriteLine(entity); System.Diagnostics.Debug.WriteLine(s); };//Console.Write; using (var ctxTransaction = ctx.Database.BeginTransaction()) { if (entity.Parent != null) { ctx.Components.Attach(entity.Parent); } if (entity.Event != null) { ctx.Events.Attach(entity.Event); } try { Item item = (Item)ctx.Components.Add(entity); ctx.SaveChanges(); ctxTransaction.Commit(); return(item); } catch (Exception err) { ctxTransaction.Rollback(); throw err; } } } }
public User Create(User user) { User u = null; using (var ctx = new DALContext()) { using (var ctxTransaction = ctx.Database.BeginTransaction()) { try { u = ctx.Users.Add(user); ctx.SaveChanges(); ctxTransaction.Commit(); return(u); } catch (System.Data.Entity.Infrastructure.DbUpdateException) { ctxTransaction.Rollback(); return(null); } catch (Exception err) { ctxTransaction.Rollback(); throw err; } } } }
public Category Create(Category entity) { using (var ctx = new DALContext()) { using (var ctxTransaction = ctx.Database.BeginTransaction()) { try { if (entity.Parent != null) { entity.Parent = ctx.Components.Single(x => x.Id == entity.Parent.Id); //ctx.Components.Attach(entity.Parent); } Category cat = (Category)ctx.Components.Add(entity); ctx.SaveChanges(); ctxTransaction.Commit(); return(cat); } catch (Exception err) { ctxTransaction.Rollback(); throw err; } } } }
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 Event Create(Event entity) { Event e = null; using (var ctx = new DALContext()) { if (entity.Admin != null) { entity.Admin = ctx.Users.Single(x => x.Id == entity.Admin.Id); //ctx.Users.Attach(entity.Admin); } using (var ctxTransaction = ctx.Database.BeginTransaction()) { try { e = ctx.Events.Add(entity); ctx.SaveChanges(); ctxTransaction.Commit(); return(e); } catch (Exception err) { ctxTransaction.Rollback(); throw err; } } } }
public void Update(Category entity) { using (var ctx = new DALContext()) { ctx.Components.AddOrUpdate(entity); ctx.SaveChanges(); } }
public static int AddSkin(skins skn) { using (DALContext cnx = new DALContext()) { cnx.skins.AddObject(skn); return cnx.SaveChanges(); } }
public static void CreateOwner(user_owner no) { using (DALContext cnx = new DALContext()) { cnx.user_owner.AddObject(no); cnx.SaveChanges(); } }
public static void CreateFranchize(user_franchaser uf) { using (DALContext cnx = new DALContext()) { cnx.user_franchaser.AddObject(uf); cnx.SaveChanges(); } }
public static int AddSkin(skins skn) { using (DALContext cnx = new DALContext()) { cnx.skins.AddObject(skn); return(cnx.SaveChanges()); } }
public static void CreateFranchize(user_franchaser uf) { using (DALContext cnx = new DALContext()) { cnx.user_franchaser.AddObject(uf); cnx.SaveChanges(); } }
public static void CreateOwner(user_owner no) { using (DALContext cnx = new DALContext()) { cnx.user_owner.AddObject(no); cnx.SaveChanges(); } }
public static int DeleteApp(int appId, int ownerId) { using (DALContext cnx = new DALContext()) { application app = cnx.application.Where(x => x.id == appId && x.owner_id == ownerId).FirstOrDefault(); cnx.application.DeleteObject(app); return(cnx.SaveChanges()); } }
public static int DeleteApp(int appId,int ownerId) { using (DALContext cnx = new DALContext()) { application app = cnx.application.Where(x => x.id == appId && x.owner_id == ownerId).FirstOrDefault(); cnx.application.DeleteObject(app); return cnx.SaveChanges(); } }
public void AddEmployee(EmployeeBLLModel model) { var efModel = new Employee() { Name = model.Name, Salary = model.Salary, IsRetired = model.IsRetired }; context.Employees.Add(efModel); context.SaveChanges(); }
public static int CreateApp(application app) { int modificationCount = 0; using (DALContext cnx = new DALContext()) { cnx.application.AddObject(app); modificationCount += cnx.SaveChanges(); cnx.skins.AddObject(new skins { app_id = app.id }); cnx.themes.AddObject(new themes { app_id = app.id }); modificationCount += cnx.SaveChanges(); } return modificationCount; }
public static int CreateApp(application app) { int modificationCount = 0; using (DALContext cnx = new DALContext()) { cnx.application.AddObject(app); modificationCount += cnx.SaveChanges(); cnx.skins.AddObject(new skins { app_id = app.id }); cnx.themes.AddObject(new themes { app_id = app.id }); modificationCount += cnx.SaveChanges(); } return(modificationCount); }
public void distdone() { using (var db = new DALContext()) { foreach (var item in db.DistributionList) { if (item.date < DateTime.Now) { if (item.isDone == false) { item.isDone = true; } } } db.SaveChanges(); } }
public static int UpdateApp(application app) { using (DALContext cnx = new DALContext()) { application realApp = cnx.application.Where(x => x.id == app.id && x.owner_id == app.owner_id).FirstOrDefault(); if (realApp != null) { realApp.is_active = app.is_active; realApp.app_name = app.app_name; return(cnx.SaveChanges()); } else { return(0); } } }
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 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(); } }
public void Assignation2(Client mycl, Distribution mydist) { using (var db = new DALContext()) { Client client = db.ClientList.FirstOrDefault(clien => clien.ID == mycl.ID); if (client == null) { throw new ArgumentNullException("Doesn't exist"); } Distribution del = db.DistributionList.FirstOrDefault(dist => dist.ID == mydist.ID); if (del == null) { throw new ArgumentNullException("Doesn't exist"); } del.ClientList.Add(client); db.SaveChanges(); } }
public Registration Create(Registration entity) { using (DALContext ctx = new DALContext()) { // User and Event objets was created by another ctx so we need to reattach them to this ctx entity.User = ctx.Users.Single(u => u.Id == entity.User.Id); entity.Event = ctx.Events.Single(e => e.Id == entity.Event.Id); //ctx.Events.Attach(entity.Event); //ctx.Entry(entity.Event).State = EntityState.Unchanged; using (var ctxTransaction = ctx.Database.BeginTransaction()) { try { ctx.Registrations.AddOrUpdate(entity); ctx.SaveChanges(); ctxTransaction.Commit(); return(entity); } catch (Exception err) { ctxTransaction.Rollback(); while (err.InnerException != null) { err = err.InnerException; if (err.Message.Contains("IX_UniqueUserReg")) { throw new DuplicateRegistrationException(); } } throw err; } } } }
public void Save() { _context.SaveChanges(); }
public static int UpdateApp(application app) { using (DALContext cnx = new DALContext()) { application realApp = cnx.application.Where(x => x.id == app.id && x.owner_id == app.owner_id).FirstOrDefault(); if (realApp != null) { realApp.is_active = app.is_active; realApp.app_name = app.app_name; return cnx.SaveChanges(); } else return 0; } }