Пример #1
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;
                    }
                }
            }
        }
Пример #2
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;
                    }
                }
            }
        }
Пример #3
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;
                    }
                }
            }
        }
Пример #4
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;
                    }
            }
        }
Пример #5
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;
                    }
                }
            }
        }
Пример #6
0
 public void Update(Category entity)
 {
     using (var ctx = new DALContext())
     {
         ctx.Components.AddOrUpdate(entity);
         ctx.SaveChanges();
     }
 }
Пример #7
0
 public static int AddSkin(skins skn)
 {
     using (DALContext cnx = new DALContext())
     {
         cnx.skins.AddObject(skn);
         return cnx.SaveChanges();
     }
 }
Пример #8
0
 public static void CreateOwner(user_owner no)
 {
     using (DALContext cnx = new DALContext())
     {
         cnx.user_owner.AddObject(no);
         cnx.SaveChanges();
     }
 }
Пример #9
0
 public static void CreateFranchize(user_franchaser uf)
 {
     using (DALContext cnx = new DALContext())
     {
         cnx.user_franchaser.AddObject(uf);
         cnx.SaveChanges();
     }
 }
Пример #10
0
 public static int AddSkin(skins skn)
 {
     using (DALContext cnx = new DALContext())
     {
         cnx.skins.AddObject(skn);
         return(cnx.SaveChanges());
     }
 }
Пример #11
0
 public static void CreateFranchize(user_franchaser uf)
 {
     using (DALContext cnx = new DALContext())
     {
         cnx.user_franchaser.AddObject(uf);
         cnx.SaveChanges();
     }
 }
Пример #12
0
 public static void CreateOwner(user_owner no)
 {
     using (DALContext cnx = new DALContext())
     {
         cnx.user_owner.AddObject(no);
         cnx.SaveChanges();
     }
 }
Пример #13
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());
     }
 }
Пример #14
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();
     }
 }
Пример #15
0
        public void AddEmployee(EmployeeBLLModel model)
        {
            var efModel = new Employee()
            {
                Name      = model.Name,
                Salary    = model.Salary,
                IsRetired = model.IsRetired
            };

            context.Employees.Add(efModel);
            context.SaveChanges();
        }
Пример #16
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;
        }
Пример #17
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);
        }
Пример #18
0
 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(); }
 }
Пример #19
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);
         }
     }
 }
Пример #20
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();
                    }
            }
        }
Пример #21
0
        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();
            }
        }
Пример #22
0
        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();
            }
        }
Пример #23
0
        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;
                    }
                }
            }
        }
Пример #24
0
 public void Save()
 {
     _context.SaveChanges();
 }
Пример #25
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;
     }
 }