コード例 #1
0
ファイル: IndexDao.cs プロジェクト: RodH257/RetrEave
        /// <summary>
        /// Craetes/updates an index
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public RetreaveIndex SaveOrUpdate(RetreaveIndex entity)
        {
            if (_database.IsNew(entity))
            {
                _database.Insert(entity);
            }
            else
            {
                _database.Update(entity);
            }

            //update the associated users
            _database.Execute("Delete from Users_Indexes where indexId=@0", entity.IndexId);

            foreach (RegisteredUser user in entity.AssociatedUsers)
            {
                if (_database.IsNew(user))
                {
                    throw new Exception("You must save the User entity first");
                }

                _database.Execute("Insert into Users_indexes (UserId, IndexId) values (@0, @1)", user.UserId,
                                  entity.IndexId);
            }
            return(entity);
        }
コード例 #2
0
ファイル: RegisteredUserDao.cs プロジェクト: RodH257/RetrEave
        /// <summary>
        /// UpSerts the user
        /// </summary>
        public RegisteredUser SaveOrUpdate(RegisteredUser entity)
        {
            if (_database.IsNew(entity))
            {
                _database.Insert(entity);
                //save the authentication details
                _database.Insert(entity.AuthDetails);
            }
            else
            {
                _database.Update(entity);
            }

            _database.Update <RegisteredUser>("SET AuthenticationDetails = @0 where UserId=@1",
                                              entity.AuthDetails.AuthenticationDetailsId, entity.UserId);
            return(entity);
        }