Example #1
0
        public static string Delete <T>(T[] items) where T : EntityObject, IUserRecord
        {
            var db      = new x360ceModelContainer();
            var table   = db.CreateObjectSet <T>();
            var deleted = 0;

            for (int i = 0; i < items.Length; i++)
            {
                var item = items[i];
                // Fix nulls.
                FixData(item);
                var computerId = item.ComputerId;
                var profileId  = item.ProfileId;
                var dbItem     = GetExistingItem(table, item);
                if (dbItem == null)
                {
                    continue;
                }
                table.DeleteObject(dbItem);
                deleted++;
            }
            db.SaveChanges();
            db.Dispose();
            return(string.Format("{0}s: {1} deleted.", items.GetType().GetElementType().Name, deleted));
        }
Example #2
0
        public static string Upsert <T>(T[] items) where T : EntityObject, IUserRecord
        {
            var db      = new x360ceModelContainer();
            var table   = db.CreateObjectSet <T>();
            var created = 0;
            var updated = 0;

            for (int i = 0; i < items.Length; i++)
            {
                var         item       = items[i];
                var         computerId = item.ComputerId;
                var         profileId  = item.ProfileId;
                IUserRecord dbItem     = GetExistingItem(table, item, true);
                // If database item was not found then...
                if (dbItem == null)
                {
                    // Use supplied item as new item.
                    created++;
                    item.DateCreated = DateTime.Now;
                    item.DateUpdated = item.DateCreated;
                    table.AddObject(item);
                }
                else
                {
                    updated++;
                    // Use created date from db.
                    item.DateCreated = dbItem.DateCreated;
                    item.DateUpdated = DateTime.Now;
                    RuntimeHelper.CopyDataMembers(item, dbItem, true);
                }
            }
            db.SaveChanges();
            db.Dispose();
            return(string.Format("{0}s: {1} created, {2} updated.", items.GetType().GetElementType().Name, created, updated));
        }
Example #3
0
        public static string Select <T>(Guid computerId, Guid profileId, T[] filter, out T[] items) where T : EntityObject, IUserRecord
        {
            var db    = new x360ceModelContainer();
            var table = db.CreateObjectSet <T>();

            items = table.Where(x => x.ComputerId == computerId && x.ProfileId == profileId).ToArray();
            db.Dispose();
            return(string.Format("{0}s: {1} selected.", items.GetType().GetElementType().Name, items.Length));
        }