Exemplo n.º 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;
            }
        }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 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;
            }
        }
Exemplo n.º 4
0
 public void CreateNew()
 {
     var newGroup = new Group();
     this.Group = new GroupViewModel(newGroup);
     UpdateTitle();
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        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);
            }
        }
Exemplo n.º 10
0
 public GroupViewModel(Group group)
 {
     this.Group = group;
 }