예제 #1
0
 public static List <application> GetApps()
 {
     using (DALContext cnx = new DALContext())
     {
         return(cnx.application.ToList());
     }
 }
예제 #2
0
 public static List <user_franchaser> GetFranchizers()
 {
     using (DALContext cnx = new DALContext())
     {
         return(cnx.user_franchaser.ToList());
     }
 }
예제 #3
0
        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();



                //}
            }
        }
예제 #4
0
        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;
                    }
                }
            }
        }
예제 #5
0
 public static List<application> GetApps()
 {
     using (DALContext cnx = new DALContext())
     {
         return cnx.application.ToList();
     }
 }
예제 #6
0
        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;
                    }
            }
        }
예제 #7
0
        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;
                    }
                }
            }
        }
예제 #8
0
 public static application GetAppById(int id)
 {
     using (DALContext cnx = new DALContext())
     {
         return cnx.application.Where(x => x.id == id).FirstOrDefault();
     }
 }
예제 #9
0
        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;
                    }
                }
            }
        }
예제 #10
0
        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;
                    }
                }
            }
        }
예제 #11
0
        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();
            }
        }
예제 #12
0
        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);
            }
        }
예제 #13
0
 public static application GetAppById(int id)
 {
     using (DALContext cnx = new DALContext())
     {
         return(cnx.application.Where(x => x.id == id).FirstOrDefault());
     }
 }
예제 #14
0
 public static List <Users> GetUsers()
 {
     using (DALContext cnx = new DALContext())
     {
         return(cnx.Users.ToList());
     }
 }
예제 #15
0
 public static bool IsFrinchizerExist(int id)
 {
     using (DALContext cnx = new DALContext())
     {
         return(cnx.user_franchaser.Where(c => c.id == id).Count() > 0);
     }
 }
예제 #16
0
 public void Update(Category entity)
 {
     using (var ctx = new DALContext())
     {
         ctx.Components.AddOrUpdate(entity);
         ctx.SaveChanges();
     }
 }
예제 #17
0
 public static void CreateFranchize(user_franchaser uf)
 {
     using (DALContext cnx = new DALContext())
     {
         cnx.user_franchaser.AddObject(uf);
         cnx.SaveChanges();
     }
 }
예제 #18
0
 public async Task AddIceCream(IceCream iceCream)
 {
     using (var db = new DALContext())
     {
         db.IceCreams.Add(iceCream);
         await db.SaveChangesAsync();
     }
 }
예제 #19
0
 public static void CreateOwner(user_owner no)
 {
     using (DALContext cnx = new DALContext())
     {
         cnx.user_owner.AddObject(no);
         cnx.SaveChanges();
     }
 }
예제 #20
0
 public static void CreateFranchize(user_franchaser uf)
 {
     using (DALContext cnx = new DALContext())
     {
         cnx.user_franchaser.AddObject(uf);
         cnx.SaveChanges();
     }
 }
예제 #21
0
 public static int AddSkin(skins skn)
 {
     using (DALContext cnx = new DALContext())
     {
         cnx.skins.AddObject(skn);
         return(cnx.SaveChanges());
     }
 }
예제 #22
0
 public static int AddSkin(skins skn)
 {
     using (DALContext cnx = new DALContext())
     {
         cnx.skins.AddObject(skn);
         return cnx.SaveChanges();
     }
 }
예제 #23
0
 public async Task AddShop(Shop shop)
 {
     using (var db = new DALContext())
     {
         db.Shops.Add(shop);
         await db.SaveChangesAsync();
     }
 }
예제 #24
0
 public static void CreateOwner(user_owner no)
 {
     using (DALContext cnx = new DALContext())
     {
         cnx.user_owner.AddObject(no);
         cnx.SaveChanges();
     }
 }
예제 #25
0
 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());
     }
 }
예제 #26
0
 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();
     }
 }
예제 #27
0
 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));
     }
 }
예제 #28
0
 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);
     }
 }
예제 #29
0
 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());
     }
 }
예제 #30
0
        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();
            }
        }
예제 #31
0
        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();
            }
        }
예제 #32
0
 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));
     }
 }
예제 #33
0
 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());
     }
 }
예제 #34
0
        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);
        }
예제 #35
0
        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));
            }
        }
예제 #36
0
 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);
     }
 }
예제 #37
0
        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;
        }
예제 #38
0
 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;
     }
 }
예제 #39
0
 public static List<user_franchaser> GetFranchizers()
 {
     using (DALContext cnx = new DALContext())
     {
         return cnx.user_franchaser.ToList();
     }
 }
예제 #40
0
 public static List<Users> GetUsers()
 {
     using (DALContext cnx = new DALContext())
     {
         return cnx.Users.ToList();
     }
 }
예제 #41
0
 public static bool IsFrinchizerExist(int id)
 {
     using (DALContext cnx = new DALContext())
     {
         return cnx.user_franchaser.Where(c => c.id == id).Count() > 0;
     }
 }
예제 #42
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;
     }
 }