Beispiel #1
0
        /// <summary>
        /// Inserts a group in the database
        /// </summary>
        /// <param name="group"></param>
        public void InsertGroup(Group group)
        {
            var currentDatabase = db;

            if (group == null)
            {
                throw new ArgumentNullException("group must not be null");
            }

            if (currentDatabase == null)
            {
                return;
            }
            try
            {
                DateTime start = DateTime.Now;
                currentDatabase.BeginTransaction();
                SQLiteCommand cmd = currentDatabase.CreateCommand(SQL_GROUP_INSERT,
                                                     group.Name, group.Description);
                int numberOfRowsAffected = cmd.ExecuteNonQuery();
                currentDatabase.CommitTransaction();
            }
            catch (SQLiteException ex)
            {
                if (currentDatabase.TransactionOpened)
                    currentDatabase.RollbackTransaction();
                throw ex;
            }
        }
 public void GetGroupById(Action<OperationResult<Model.Group>> callBack, int groupId)
 {
     Group group = new Group("Test group", "Test projects group.");
     group.GroupId = groupId;
     var result = new OperationResult<Model.Group>(group);
     callBack(result);
 }
Beispiel #3
0
        /// <summary>
        /// Inserts a group in the database
        /// </summary>
        /// <param name="group"></param>
        public void InsertGroupAndSync(Group group)
        {
            var currentDatabase = db;

            if (group == null)
            {
                throw new ArgumentNullException("group must not be null");
            }

            if (currentDatabase == null)
            {
                return;
            }
            try
            {
                DateTime start = DateTime.Now;
                currentDatabase.BeginTransaction();
                //save new group
                SQLiteCommand cmd = currentDatabase.CreateCommand(SQL_GROUP_INSERT,
                                                     group.Name, group.Description);
                int numberOfRowsAffected = cmd.ExecuteNonQuery();
                
                //load new inserted group
                SQLiteCommand cmdLoad = currentDatabase.CreateCommand(SQL_SELECT_LAST_INSERT_ID);
                var lastRowIdResult = cmdLoad.ExecuteQuery<ScalarIdColumn>();
                var lastRowId = lastRowIdResult.FirstOrDefault();

                int lastId = lastRowId.Id;

                //set new values
                group.GroupId = lastId;
                currentDatabase.CommitTransaction();
            }
            catch (SQLiteException ex)
            {
                if (currentDatabase.TransactionOpened)
                    currentDatabase.RollbackTransaction();
                throw ex;
            }
        }
Beispiel #4
0
 public void CreateNew()
 {
     var newGroup = new Group();
     this.Group = new GroupViewModel(newGroup);
     UpdateTitle();
 }
Beispiel #5
0
        /// <summary>
        /// Delete group from the database
        /// </summary>
        /// <param name="group"></param>
        public void DeleteGroup(Group group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group must not be null");
            }

            int groupId = group.GroupId;

            this.DeleteGroupById(groupId);
        }
Beispiel #6
0
        public void InsertOrUpdateGroup(Group group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group must not be null");
            }

            int groupId = group.GroupId;
            if (groupId == 0)
            {
                this.InsertGroupAndSync(group);
            }
            else
            {
                this.UpdateGroup(group);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Update group in the database
        /// </summary>
        /// <param name="group"></param>
        public void UpdateGroup(Group group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group must not be null");
            }

            if (db == null)
            {
                return;
            }
            try
            {
                db.BeginTransaction();
                SQLiteCommand cmd = db.CreateCommand(SQL_GROUP_UPDATE,
                                                      group.Name,
                                                      group.Description,
                                                      group.GroupId);
                int numberOfRowsAffected = cmd.ExecuteNonQuery();
                db.CommitTransaction();
            }
            catch (SQLiteException ex)
            {
                if (db.TransactionOpened)
                    db.RollbackTransaction();
                throw ex;
            }
        }
        public void AddSampleGroupsToDb()
        {
            int groupsCount = 10;
            var groups = new List<Group>();
            for (int i = 0; i < groupsCount; i++)
            {
                var group = new Group()
                {
                    GroupId = 0,
                    Name = string.Format("Name {0}", i),
                    Description = string.Format("Description of group {0}", i)
                };

                groups.Add(group);
            }

            foreach (Group gr in groups)
            {
                _groupsDataService.Save(OnGroupSaved, gr);
            }
        }
        public void LoadDesignGroups()
        {
            var groups = new List<GroupViewModel>();
            for (int i = 0; i < 10; i++)
            {
                var group = new Group()
                {
                    GroupId = i,
                    Name = string.Format("Name {0}", i),
                    Description = string.Format("Description of group {0}", i)
                };

                var groupViewModel = new GroupViewModel(group);
                groups.Add(groupViewModel);
            }

            Groups = new ObservableCollection<GroupViewModel>();
            foreach (var group in groups)
            {
                Groups.Add(group);
            }
        }
Beispiel #10
0
 public GroupViewModel(Group group)
 {
     this.Group = group;
 }