public static List <application> GetApps() { using (DALContext cnx = new DALContext()) { return(cnx.application.ToList()); } }
public static List <user_franchaser> GetFranchizers() { using (DALContext cnx = new DALContext()) { return(cnx.user_franchaser.ToList()); } }
public async Task UpdateDeliveryMen2(DeliveryMen DeliveryMen1) { using (var db = new DALContext()) { DeliveryMen del = db.DeliveryMenList.FirstOrDefault(deliverym => deliverym.ID == DeliveryMen1.ID); Distribution[] newlist = new Distribution[del.DistributionList.Count]; del.DistributionList.CopyTo(newlist, 0); foreach (var item in newlist) { del.DistributionList.Remove(item); } db.DeliveryMenList.AddOrUpdate(DeliveryMen1); await db.SaveChangesAsync(); for (int i = 0; i < newlist.Length; i++) { Assignation(newlist[i], DeliveryMen1); } await db.SaveChangesAsync(); //} } }
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 static List<application> GetApps() { using (DALContext cnx = new DALContext()) { return cnx.application.ToList(); } }
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 static application GetAppById(int id) { using (DALContext cnx = new DALContext()) { return cnx.application.Where(x => x.id == id).FirstOrDefault(); } }
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 async Task AddDeliveryMen(DeliveryMen DeliveryMen1) { using (var db = new DALContext()) { bool isexisting = false; foreach (var item in db.DeliveryMenList) { if (item.ID == DeliveryMen1.ID) { isexisting = true; } } if (DeliveryMen1 == null || isexisting == true) { throw new Exception("the DeliveryMen that you want to add is empty or already existing"); } bool problem = true; if (!(DeliveryMen1.telephone == "") && (DeliveryMen1.telephone.Substring(0, 1) == "0" || DeliveryMen1.telephone.Substring(0, 1) == "+" || DeliveryMen1.telephone.Substring(0, 1) == "*") && (DeliveryMen1.telephone.Length == 10 || DeliveryMen1.telephone.Length == 13 || DeliveryMen1.telephone.Length == 5)) { problem = false; } if (problem) { throw new Exception("You can't add a DeliveryMen without an valid phone number"); } if (DeliveryMen1.mail.Contains("@") == false) { throw new Exception("You can't add a DeliveryMen without an valid email address"); } db.DeliveryMenList.Add(DeliveryMen1); await db.SaveChangesAsync(); } }
public Category FindByID(int id) { using (var ctx = new DALContext()) { var query = ctx.Components.OfType <Category>() .Where(x => x.Id == id) .Include(x => x.Components);; var cat = query .FirstOrDefault(); cat.Components .AddRange(ctx.Components.OfType <Item>() .Where(item => item.Parent.Id == cat.Id)); // note: Only resolves one level for the found Category foreach (var subcomp in cat.Components) { if (subcomp is Category) { var sub = (Category)subcomp; var items = ctx.Components.OfType <Item>() .Where(x => x.Parent.Id == sub.Id).ToList(); sub.Components.AddRange(items); } } return(cat); } }
public static application GetAppById(int id) { using (DALContext cnx = new DALContext()) { return(cnx.application.Where(x => x.id == id).FirstOrDefault()); } }
public static List <Users> GetUsers() { using (DALContext cnx = new DALContext()) { return(cnx.Users.ToList()); } }
public static bool IsFrinchizerExist(int id) { using (DALContext cnx = new DALContext()) { return(cnx.user_franchaser.Where(c => c.id == id).Count() > 0); } }
public void Update(Category entity) { using (var ctx = new DALContext()) { ctx.Components.AddOrUpdate(entity); ctx.SaveChanges(); } }
public static void CreateFranchize(user_franchaser uf) { using (DALContext cnx = new DALContext()) { cnx.user_franchaser.AddObject(uf); cnx.SaveChanges(); } }
public async Task AddIceCream(IceCream iceCream) { using (var db = new DALContext()) { db.IceCreams.Add(iceCream); await db.SaveChangesAsync(); } }
public static void CreateOwner(user_owner no) { using (DALContext cnx = new DALContext()) { cnx.user_owner.AddObject(no); cnx.SaveChanges(); } }
public static int AddSkin(skins skn) { using (DALContext cnx = new DALContext()) { cnx.skins.AddObject(skn); return(cnx.SaveChanges()); } }
public static int AddSkin(skins skn) { using (DALContext cnx = new DALContext()) { cnx.skins.AddObject(skn); return cnx.SaveChanges(); } }
public async Task AddShop(Shop shop) { using (var db = new DALContext()) { db.Shops.Add(shop); await db.SaveChangesAsync(); } }
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 ObservableCollection <Distribution> GetAllDistribution(Func <Distribution, bool> filter = null) { using (var db = new DALContext()) { var list = new ObservableCollection <Distribution>(db.DistributionList .Distinct() .AsNoTracking()); return(new ObservableCollection <Distribution>(list)); } }
public bool IsRegisteredToEvent(User user, Event evnt) { using (var ctx = new DALContext()) { var userRegs = ctx.Users.Include(x => x.Registrations.Select(reg => reg.Event)).Single(x => x.Id == user.Id).Registrations; var eventRegs = ctx.Events.Include(x => x.Registrations.Select(reg => reg.User)).Single(x => x.Id == evnt.Id).Registrations; var userEventReg = userRegs.Intersect(eventRegs) /*.Where(reg => reg.Event.Id == evnt.Id && reg.User.Id == user.Id).ToList();*/.SingleOrDefault(reg => reg.Event.Id == evnt.Id && reg.User.Id == user.Id); return(userEventReg /*.Single()*/ != null); } }
public User FindByEmail(string email) { using (var ctx = new DALContext()) { return(ctx.Users .Include(x => x.Registrations.Select(y => y.Event)) .Where(x => x.Email == email) .FirstOrDefault()); } }
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 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 Event FindFromInviteString(string inviteString) { using (var ctx = new DALContext()) { return(ctx.Events .Include(x => x.Registrations.Select(reg => reg.User)) .Include(x => x.Components) .Include(x => x.Admin) .SingleOrDefault(x => x.InviteString == inviteString)); } }
public Item FindItemByID(int itemId) { using (DALContext ctx = new DALContext()) { return(ctx.Components .OfType <Item>() .Where(i => i.Id == itemId) .Include(x => x.Parent) .SingleOrDefault()); } }
public List <Component> FindComponentByParentId(int id) { List <Component> components = null; using (var ctx = new DALContext()) { components = ctx.Components.Where(c => c.Parent.Id == id).ToList(); } return(components); }
public ObservableCollection <Client> GetAllClients(Func <Client, bool> filter = null) { using (var db = new DALContext()) { var list = new ObservableCollection <Client>(db.ClientList .Distinct() .AsNoTracking()); return(new ObservableCollection <Client>(list)); } }
public DeliveryMen GetDEL(int id) { using (var db = new DALContext()) { var list = new ObservableCollection <DeliveryMen>(db.DeliveryMenList .Distinct() .Where(m => m.ID == id) .AsNoTracking()); DeliveryMen mymen = list.FirstOrDefault(); return(mymen); } }
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 GetOwnerId(string userId) { using (DALContext cnx = new DALContext()) { user_owner o = cnx.user_owner.Where(c => c.user_id.Equals(userId)).FirstOrDefault(); if (o != null) return o.id; else return 0; } }
public static List<user_franchaser> GetFranchizers() { using (DALContext cnx = new DALContext()) { return cnx.user_franchaser.ToList(); } }
public static List<Users> GetUsers() { using (DALContext cnx = new DALContext()) { return cnx.Users.ToList(); } }
public static bool IsFrinchizerExist(int id) { using (DALContext cnx = new DALContext()) { return cnx.user_franchaser.Where(c => c.id == id).Count() > 0; } }
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; } }